Labeling Docker Images With Commit SHA (Interpolate Environmental Variables In codeship-services.yml)

docker

#1

As part of our workflow, we will like to label our Docker images with the HEAD commit SHA so that our user can trace our Docker images to specific commit in our GH account. Here’s an example of what it looks like on microbadger.com. I’m unsure how to achieve this with Codeship Pro. AFAICT, the codeship-services.yml file doesn’t interpolate environment variables.

What I’m hoping to achieve is this:

# codeship-services.yml
myapp:
  build:
    image: myimage
    dockerfile: Dockerfile
    args:
      VCS_REF: ${HEAD_COMMIT_SHA} # specify this in .env file like docker-compose, but it's currently not working
# Dockerfile
...
ARG VCS_REF
LABEL org.label-schema.vcs-ref=$VCS_REF \
            org.label-schema.vcs-url="e.g. https://github.com/microscaling/microscaling"

Any thoughts on how I can achieve this? This a blocker to our workflow.

Thanks.

PS FWIW AFAIK, the CI_* environmental variables are only available at runtime, right?


#2

EDIT: I solved a similar problem, check my thread: How to write a build environment variable value into a image

:wink:


#3

I think we are talking about different things. I don’t want the CI_* environmental variable to be written to a file for runtime usage. Rather, I want the commit SHA to be baked into the image as labels so that when I do docker inspect <image>, the commit SHA will appear as a label.


#4

The reason you can’t see the error is a bug on our end, we’re got it in our queue to fix. What’s happening is that your encrypted env is failing to parse - it either contains invalid characters or is encrypted with the wrong key.

Sorry for the trouble, there should be a very clear error message around this.