Race condition when pushing manifest lists with the same digest
Reported
We have a Maven project using jib to build and push a Docker image with two tags (current version and "latest") to GitLab Container Registry.
This fails frequently with
Failed to execute goal com.google.cloud.tools:jib-maven-plugin:3.3.2:build (docker-push) on project management-console:
500 Internal Server Error
PUT https://registry.gitlab.com/v2/chromaway/core-tools/management-console/pmc/manifests/3.15.0
{"errors":[{"code":"UNKNOWN","message":"unknown error","detail":{}}]}
It usually works if rerunning the job.
The project is here: https://gitlab.com/chromaway/core-tools/management-console
Seems to be similar to fix(datastore): race condition pushing two or m... (#640 - closed)
Context
The container registry on GitLab.com is backed by a metadata database. The manifests
table keeps track of these manifests.
Only one manifest per digest and repository can exist as defined by the constraint top_level_namespace_id_repository_id_digest_key
.
Problem
A race condition happens when pushing a manifest list with the same digest but different tags at the same time, as seen in the report. This is how jib
builds the lists and pushes them to the registry. The problem is similar to #640 (closed).
Solution
In fix(datastore): race condition pushing two or m... (#640 - closed), we fixed this by exposing and using a CreateOrFind
method to the manifests store, and then updated the handler to use this new method.
For this problem, we can do the same but the handler for manifests lists is a bit different so we did not catch that in the first solution.