I need to determine, within one of my Dockerfiles, which tag triggered the build in Docker Cloud since I use the same Dockerfile for a couple different Docker Cloud build rules and have a bit of conditional logic in that Dockerfile to handle building the image for each tag slightly differently.
I’ve been trying to use a custom build hook to do this, but we have a number of build rules configured for this repo and each one could have a different value for the following fields in the Docker Cloud automated builds UI:
- source (branch or tag)
- Docker tag
- Dockerfile location
- Build context
I know there are env vars provided by Docker Cloud that give us the first 2 of these 4 values: SOURCE_BRANCH and CACHE_TAG. But I’m wondering how I would be able to choose the correct Dockerfile and Build context to pass onto my custom “docker build” command?
For example, right now I have this in my hooks/build file (leaving “source” out of this example):
docker build --build-arg CACHE_TAG=$CACHE_TAG -t $IMAGE_NAME .
But the problem is that this is always going to use the
Dockerfile filename and
. as the build context which differs from most of the build rules we have for this repo. I could add extra logic to the build file to determine the Dockerfile and build context from the cache tag but then I’m basically duplicating half of the data from the Docker Cloud automated builds UI and hardcoding it into the build file which is not desired.