I'm using a dockerfile to build go code, and I'm trying to pass 3 options in -ldflags option. Two of these flags comes from ENV variables, and I have to inject them in -ldflags content, thru string interpolation or concatenation, but I don't know how.
The objective is to inject git revision hash and current timestamp in two variables in main.go
It can be done by creating a file from dockerfile with "echo" command, but I want to be sure it's not possible with simple variables interpolation/concatenating
ENV GIT_REVISION $( git rev-parse --short HEAD )
ENV COMPILATION_TIMESTAMP $( date +%Y%m%dT%H:%M:%S )
RUN go get -d -v
// This one works:
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o myprogram .
// This one, with those variables, fails:
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags "-extldflags '-static' -X main.compiledOn=${COMPILATION_TIMESTAMP} -X main.gitRevisionHash=${GIT_REVISION}" -o myprogram .