Mandatory arg
I have something that works for your question, but it will not work for all cases at all.
In your docker file after ONBUILD WORKDIR /app/src you will have:
COPY build_copy.sh /config ONBUILD COPY target_app.txt /config ONBUILD RUN sh /config/build_copy.sh
The build_copy.sh file will contain the following lines:
TARGET_APP=`cat /config/target_app.txt` ONBUILD RUN ./build $TARGET_APP ONBUILD RUN cp $TARGET_APP/build/bin /app/bin
The target_app.txt file should contain the text that you want to put in TARGET_APP. This will require the target_app.txt file in your child image.
Optional arg argument
You can mitigate this a bit by adding the “optional” text files in the / config folder to your child’s root directory and changing your ONBUILD to:
ONBUILD COPY /config /config
You will need only a folder, all files there will be optional. The shell script can then use:
TARGET_APP_2=`cat /config/target_app.txt` if [ -n "$TARGET_APP_2" ] then TARGET_APP=$TARGET_APP_2 else TARGET_APP='default_app' fi
source share