Modify docker ENV

I’m building a docker image and would like the hash to be added to the docker file each time its build. How do I do this? Im using workflows ECR and ECS to build and deploy.

Do you mean as a comment? What form would this hash take in the Dockerfile?


Which hash would you like added? You would not be able to add the hash of the dockerfile to itself if that is the objective. You could take the hash of the file, and then generate a new dockerfile with the hash of the un-modified version if you wish.

How would the hash live in the dockerfile? Is it meant to be echoed out?

I would like the hash from circle to be used as a environmental variable within the dockerfile. I plan to use this ENV to dynamically display on the logs which build this is. Hopefully that makes sense.

I would like to add the circle-sha1 hash if possible. I have a line in the dockerfile ENV key $CIRCLE_SHA1. I was hoping that each build could replace this variable. The dockerfile is a node api and was hoping to use a route to display the hash to verify which build is running. Hopefully this make sense.

Currently I am using aws-ecr/build-and-push-image workflow which is building the dockerfile and pushing it to AWS. If its possible to echo the hash to the dockerfile or copy the dockerfile, append a line and output it. Whatever way I have to do this to get the hash running is what i want.

Hello @kielfriedt,

You could certainly do this but you may not be able to use the aws-ecr directly as you will need an extra step. You could however fork this Orb and create your own with the . extra step you need.

The extra step being you will need to append the line you want to your dockerfile.

- run: echo "ENV HASH_KEY ${CIRCLE_SHA1}" >> dockerfile

You would need something like the above to inject the string into the dockerfile before building and pushing the image.

OK, right. I would write this hash to a spare file, and when you build, cat that file to standard out.