Repository navigation
Enable SHA pinning with incremental container images numbers #12110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #! /bin/bash | ||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
|
|
||
| image=$1 | ||
| tag=${2:-$(cd $SCRIPT_DIR/../../ && mvn help:evaluate -Dexpression=project.version -q -DforceStdout)} | ||
| original_tag=$tag | ||
| c=1 | ||
|
|
||
| while : | ||
| do | ||
| tag="${original_tag}-${c}" | ||
| if DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect $image:$tag >/dev/null 2>/dev/null; then | ||
| c=$((c+1)) | ||
| else | ||
| echo "-${c}" | ||
| break | ||
| fi | ||
| done | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,10 @@ | |
| - '[0-9]+.[0-9]+.[0-9]+' | ||
| concurrency: keycloak-container-release | ||
|
|
||
| env: | ||
| QUAY_IMAGE: quay.io/keycloak/keycloak | ||
| DOCKER_IMAGE: keycloak/keycloak | ||
|
|
||
| jobs: | ||
| publish: | ||
| if: github.repository == 'keycloak/keycloak' | ||
|
|
@@ -19,6 +23,9 @@ | |
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v2 | ||
|
|
||
| - name: Set incremental number | ||
| run: echo "INCREMENTAL=$(.github/scripts/incremental-tag.sh ${{ env.QUAY_IMAGE }})" >> $GITHUB_ENV | ||
|
|
||
| - name: Login to Quay | ||
| uses: docker/login-action@v2 | ||
|
|
@@ -38,12 +45,13 @@ | |
| uses: docker/metadata-action@v4 | ||
| with: | ||
| images: | | ||
| keycloak/keycloak | ||
| quay.io/keycloak/keycloak | ||
| ${{ env.DOCKER_IMAGE }} | ||
| ${{ env.QUAY_IMAGE }} | ||
| tags: | | ||
| type=ref,event=branch | ||
| type=semver,pattern={{version}} | ||
| type=semver,pattern={{major}}.{{minor}} | ||
| type=semver,pattern={{version}},suffix=${{ env.INCREMENTAL }} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suffix may require you to add the separator (e.g. https://github.com/docker/metadata-action#typesemver doesn't really say much
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup, is not well documented, we are adding the |
||
|
|
||
| - name: Build and push the image | ||
| uses: docker/build-push-action@v3 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop doesn't seem necessary.
With anonymous access to the quay API, we can list all the current tags, and determine what the next value for
cshould be from that:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I read correctly the documentation:
https://docs.quay.io/api/swagger/#!/tag/listRepoTags
the endpoint you are suggesting will return a paged result and the order is not specified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that's true. The order does seem to be the time of modification, but that's not specified. Here's a more complete solution:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update @ASzc !
This is again a similar tradeoff as the other PR 🙂 , I do believe that plain docker commands are preferable for this task since they work with any Docker registry.
Also, the overall complexity of your proposed solution (although shows great
bashskills 🙂 ) seems to be a little higher than my proposal.It would be nice to have a third opinion to break the tie, cc. @abstractj @stianst