Buildspec file, pass env var to Dockerfile?

0

Hi, I have a buildspec file. In prebuild I got: pre_build: commands: IMAGE_TAG=$(cd src && git rev-parse HEAD | cut -c 1-7)

Then I have a build phase and in Dockerfile I have command go build, how to pass it rev-parse HEAD from pre_build to Dockerfile?

Dockefile is building in a separate container which is not seeing git rev-parse HEAD from pre_build phase.

RUN go build -v -ldflags=" -X 'main.BuildSha=$(git rev-parse HEAD)'"

profile picture
asked 2 years ago244 views
1 Answer
1
Accepted Answer

Hi,

You should use the the ARG option in Dockerfile along with --build-arg when building the image. You might find this blog helpful - https://blog.bitsrc.io/how-to-pass-environment-info-during-docker-builds-1f7c5566dd0e

--Syd

profile picture
Syd
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions