Coder Social home page Coder Social logo

dkr2sh's Introduction

dkr2sh - convert Dockerfile to shell script

This script naively translates some Dockerfile instructions into corresponding shell commands.

Conversion Rules

Instructions commented out

  • FROM
  • CMD
  • LABEL
  • MAINTAINER
  • EXPOSE
  • ENTRYPOINT
  • VOLUME
  • ARG
  • ONBUILD
  • STOPSIGNAL
  • HEALTHCHECK

Translate these instructions manually:

  • USER - execute the next block(s) with su or equivalent
  • SHELL - unwrap JSON-formatted arguments, run it for subsequent block(s)

ENV

Before:

ENV FOO bar

After:

export FOO=bar

RUN

Before:

RUN /usr/bin/foo \
    && /sbin/bar --quux

After:

/usr/bin/foo \
    && /sbin/bar --quux

COPY

COPY behaves differently on files and directories, so we use rsync to emulate recursive content copying on directories.

If --from argument is given, it becomes just a comment, because unlike Docker images (and ogres), shell scripts don't have layers.

Before:

COPY --from=composer foo.sh /usr/local/bin/

After:

for i in foo.sh; do
        test -d "$i" && i="$i/"
        rsync -a "$i" /usr/local/bin/ # --from=composer
done

WORKDIR

Before:

WORKDIR /var/lib/pgsql/10.1

After:

mkdir -p /var/lib/pgsql/10.1 && cd /var/lib/pgsql/10.1

ADD

ADD has many rules, and transforms into a fairly large snippet.

Before:

ADD https://example.org/foo.bin /opt

After:

if echo "/opt" | grep -q '/$'; then
        mkdir -p "/opt";
else
        mkdir -p "$(dirname "/opt")";
fi

for i in https://example.org/foo.bin; do
        if echo "$i" | grep -q '^\(https\?\|ftp\)://'; then
                if echo "/opt" | grep -q '/$'; then
                        (cd "/opt" && wget -q "$i");
                else
                        wget -q -O "/opt" "$i";
                fi
        elif test -d "$i"; then
                rsync -a "$i/" "/opt";
        elif tar -tf "$i" >/dev/null 2>&1; then
                mkdir -p "/opt" && tar -C "/opt" -xf "$i";
        else
                rsync -a "$i" "/opt";
        fi
done

Copyright

Copyright 2018, Development Gateway

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

dkr2sh's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dkr2sh's Issues

How to use this?

Yep, that's the issue ;-). Looks nice, and found this and another one here:

https://github.com/thatkevin/dockerfile-to-shell-script

Kevin's not proud of his (he says), but it's simple one shell script. What you have here puzzles me:

  1. the README fails to offer any tips on how to actually use it.
  2. To confound that, an examination reveals two oddly identical files copy.sh and `copy-from.sh
  3. a sed script with not tips on how to use it
  4. a sh2sed.sh script with no internal docs on use

The desire of a naive conversion is strong, and you've put a little more work into it than Kevin, certainly with ADD handling. But it's just a tiny bit of documentation and maybe housekeeping, short of being useful to others. Can I motivate you to add a little more documentation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.