dkr2sh icon indicating copy to clipboard operation
dkr2sh copied to clipboard

How to use this?

Open bernd-wechner opened this issue 3 years ago • 2 comments

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?

bernd-wechner avatar Feb 05 '22 06:02 bernd-wechner

The file to use is dkr2sh.sed, which is a sed script, note how it starts:

#!/bin/sed -f
# Convert Dockerfile to shell script.

To use it, normal sed usage implies it takes stdin and outputs stdout. So:

./dkr2sh.sed < Dockerfile > mydockerscript.sh

Contributing: The explanation of the tranform rules in the documentation matches the .sh files, copy-from.sh, copy.sh and add.sh

In the dkr2sh.sed file, the transform rules have been translated to sed patterns. The sh2sed.sh is the helper script that can do this as part of manual labour. You can change any of the patterns and run, eg. ./sh2sed.sh < copy-from.sh and you will get this:

for i in ARGS; do\n\ttest -d "$i" \&\& i="$i\/"\n\trsync -a "$i" DEST # FROM\ndone

It matches the replacement string in the dkr2sh.sed file, here, but with match groups inserted inplace of ARGS, DEST, FROM

s/^[[:space:]]*COPY\([[:space:]]\+--from=[^[:space:]]\+\)\(\([[:space:]]\+[^[:space:]]\+\)\+\)\([[:space:]]\+[^[:space:]]\+\)[[:space:]]*/for i in\2; do\n\ttest -d "$i" \&\& i="$i\/"\n\trsync -a "$i"\4 #\1\ndone/i

dsschneidermann avatar Feb 23 '22 10:02 dsschneidermann

I don't really expect that this will get merged, so for any newcomers, take a look at the branched version here

https://github.com/dsschneidermann/dkr2sh

dsschneidermann avatar Feb 23 '22 11:02 dsschneidermann