Closed dkebler closed 3 months ago
Hi @dkebler ,
Just to confirm, the .INCLUDE
directive is a 'compile-time' feature, but the %
directive is a runtime feature. i.e the commands in %
lines are not executed until you run the script generated by the bash-tpl command. But, by that time, the .INCLUDE
has already happened (and failed in your case)
I could see a possible new feature to make the include file optional, maybe something like:
.INCLUDE? "include.tpl"
I'll grind on that some more, but in the meantime:
Q: Does your "$BUILD_SRC/Dockerfile"
file include bash-tpl template commands?
If YES, then what you might do is modify your build script to compile it separately and then turn the .INCLUDE
into a source
to be executed at runtime:
If NO, i.e. your Dockerfile is just a pure text file (not templated), then you can turn your .INCLUDE
into a cat
to be executed at runtime.
Let me know if either of those could work for you for now, and I'll think about how to make the include accept an optional flag for times when the included file may not exist.
-TW
PS: See the discussions here (issue #16) as it contains some overlap with this discussion. It also contains a starter makefile which could be useful for setting up a multi-file setup.
@dkebler pls lemme know if you get a chance to read my msg - I'd like to continue the discussion.
-TW
finally gettting back to this.
My workaround was simply to make temporary file with a comment therein if it doesn't exist.
Not ideal but it works.
#!/bin/bash
echo "------------ creating Dockfile from template in Dockerfile.d -------------"
[[ ! -f $BDIR/.src/Dockerfile ]] && echo "#dummy file" > $BDIR/.src/Dockerfile
[[ -f $APPEND_BUILD_ENV ]] && source "$APPEND_BUILD_ENV" && echo using $APPEND_BUILD_ENV when building Dockerfile && cat $APPEND_BUILD_ENV && echo -e "\n-----"
pushd $(dirname "$(realpath "$BASH_SOURCE")") > /dev/null || return 1
source <(../lib/bash-tpl Dockerfile.tpl ) | grep -v '^# ' > ../Dockerfile
echo "done ------- creating Dockfile from template in Dockerfile.d -------------"
popd > /dev/null || return 2
This also means I can remove the conditional in my template, so now just
# appends any additional custom Dockerfile code, currently causes error
.INCLUDE "$BDIR/.src/Dockerfile"
In this case bash-tpl is not generating a bash script to be run later but a Dockerfile which is more a less a "static" file (i.e. can't do a "cat" later) . To include this file was simply a way to give the user a way to inject some additional custom lines into the Dockerfile so NO it doesn't have any templating code but NO I can not use cat as you suggest.
if the file
"$BUILD_SRC/Dockerfile"
does not exist then the .INCLUDE statement is ignored BUT bash-tpl STILL seems to want to check that the .INCLUDE file exists thus throwing an error. This is unexpected.if
"$BUILD_SRC/Dockerfile"
exists it all works as expected.