Skip to content

Build docker container with labels and tags

Benjamin Bock requested to merge improve-container-builds into master

Instead of building the container with just tag latest as we did in the last weeks, this changes creates two version tags: the short git commit id and the branch name. On the default branch, it continues to add latest In addition, it adds some labels which include the author, the time, the commit, ci pipeline, ci job etc.

It's also prepared that if we use version labels, those can be added as well. There are two approaches for that: one adds the version label to those builds made from exactly the tagged commit (OnlyIfThisCommitHasVersion). Alternatively, this could be switched to LastVersionTagInGit so patches based on that last version will also get the version tag.

I noticed that CI_MERGE_REQUEST_ID might be empty, so builds which started before a MR was created will have an invalid URL here. This seems to be the case for all examples as well.

As we now add useful version tags in every branch, now the images are build in every branch, not only in master. This might allow us to move testing inside the container which would save us from building assets twice.

In addition, we could consider if/how we could make the deployed version a bit more explicit, e.g. by not running "latest" in the environments but a specific tag. However this may need further investigation and discussion.

The container registry will become a bit more filled now. AFAIK, there's currently no limit in gitlab. But if we hit a limit, we'd need to clean up there.

Full example:

Kaniko arguments to run: 
--context /builds/dietech/workOS 
--dockerfile /builds/dietech/workOS/Dockerfile 
--cache=true 
--cache-copy-layers=true 
--cache-ttl=24h  
--destination registry.gitlab.com/dietech/workos:improve-container-builds  
--destination registry.gitlab.com/dietech/workos:a420b329  
--label org.opencontainers.image.vendor=https://gitlab.com/bnjmnbck 
--label org.opencontainers.image.authors=https://gitlab.com/bnjmnbck 
--label org.opencontainers.image.revision=a420b32989c2560901e39ed95d1fef3e272607b8 
--label org.opencontainers.image.source=https://gitlab.com/dietech/workOS 
--label org.opencontainers.image.documentation=https://gitlab.com/dietech/workOS 
--label org.opencontainers.image.licenses=https://gitlab.com/dietech/workOS 
--label org.opencontainers.image.url=https://gitlab.com/dietech/workOS 
--label vcs-url=https://gitlab.com/dietech/workOS 
--label com.gitlab.ci.user=https://gitlab.com/bnjmnbck 
--label com.gitlab.ci.email=bb-gitlab@bock.be 
--label com.gitlab.ci.tagorbranch=improve-container-builds 
--label com.gitlab.ci.pipelineurl=https://gitlab.com/dietech/workOS/-/pipelines/343190827 
--label com.gitlab.ci.commiturl=https://gitlab.com/dietech/workOS/commit/a420b32989c2560901e39ed95d1fef3e272607b8 
--label com.gitlab.ci.cijoburl=https://gitlab.com/dietech/workOS/-/jobs/1453649386 
--label com.gitlab.ci.mrurl=https://gitlab.com/dietech/workOS/-/merge_requests/
 
--label org.opencontainers.image.created='2021-07-26T21:03:46+00:00' 
--label build-date='2021-07-26T21:03:46+00:00' 
--label org.opencontainers.image.title=workOS 
--label org.opencontainers.image.description=workOS 
--label org.opencontainers.image.ref.name=registry.gitlab.com/dietech/workos:improve-container-builds
Edited by Benjamin Bock

Merge request reports