concourse / registry-image-resource

a resource for images in a Docker registry
Apache License 2.0
89 stars 107 forks source link

Semver mode can wrongfully report tag `latest` as the newest version in race scenario #316

Open odormond opened 2 years ago

odormond commented 2 years ago

We recently encountered an issue where the version of a resource type used by concourse was not the most recent one despite the fact that check correctly reported the most recent version available.

Here is the definition of the resource:

resource_types:
  - name: cogito
    type: registry-image
    check_every: 1h
    source:
      repository: pix4d/cogito

As you can see, source.tag is not set and we expect semver versioning of the resource type.

Looking at the resource_config_versions table in the DB, here is what I saw:

 check_order |                                                version                                                 
-------------+--------------------------------------------------------------------------------------------------------
          13 | {"tag": "latest", "digest": "sha256:9ef19fc7b58192be3de6dd9c400f72d9f6bc4d8f2bab5ff642366c25812789f8"}
          12 | {"tag": "0.6.2", "digest": "sha256:e59670b6b6bf4b7e6dd2c92d7af771719cd63b898329569a6d0a93119dd45543"}
          10 | {"tag": "0.6.1", "digest": "sha256:9ef19fc7b58192be3de6dd9c400f72d9f6bc4d8f2bab5ff642366c25812789f8"}
           8 | {"tag": "0.6.0", "digest": "sha256:cef4adfe17e9ee5f7c16a4094e435d88857f663f080507dcb6b61e7390b52852"}
...

As you can see:

Forcing a check prints out 0.6.2 as expected.

After looking at the code, the problem can be explained as a race condition between tagging the repository images and checking them. Here is the scenario:

mymasse commented 2 years ago

I'm running into something similar just using a simple resource not a resource-type. I'm not specifying a source.tag in my resource and was surprised when my job ran with tag latest. Since the documentation mentions:

With tag omitted, check will instead detect tags based on semver versions (e.g. 1.2.3) and return them in semver order

Note that this was a brand new pipeline so all the current images tags were all existing.

marco-m commented 2 years ago

@odormond I have the impression that https://github.com/concourse/concourse/pull/8196 could be a manual workaround (until this issue is fixed).

odormond commented 2 years ago

@odormond I have the impression that concourse/concourse#8196 could be a manual workaround (until this issue is fixed).

Yes. That would be better than having to issue sql queries directly in the DB. :laughing: