I’m building my docker image in a generic way so that might be used by multiple services, however not all the --build-arg
will be present because it depends on the service that is being called on the GitHub Actions. My question is; is it possible to use only one or more --build-arg
without using every --build-arg
?
Command:
docker build
-f ${{ inputs.docker-location }}
-t $IMAGE_NAME:$TAG
--build-arg value1=${{secrets.value1}}
--build-arg value2=${{ secrets.value2}}
--build-arg value3=${{secrets.value3}}
--build-arg value4=${{ secrets.value4 }} .
So in this case I would only pass the value1 and value2, however, it fails because the rest of the values will be empty.
I know it works if all args are present, as I’m already using it, but wanted to expand it in a more generic way.
Thanks in advance! 🙂
3
Answers
I've tried a couple of things and this one work.
Also figure it out that if you don't want to pass any value as if it empty, then you can just leave it without the default value, like below and the pipeline will ignore the empty args.
--build-arg value2=${{ secrets.value2}}
Yes, you can do this by defining a default
ARG
in the Dockerfile, e.g:For more information: https://docs.docker.com/engine/reference/builder/#default-values
In your pipeline check if those secrets are empty or not. If empty then give it a default value that you would handle in the Dockerfile appropriatly.