Skip to content

Commit

Permalink
Add workflow to use versioned images
Browse files Browse the repository at this point in the history
  • Loading branch information
smola committed Sep 29, 2023
1 parent c12c420 commit c365220
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/docker-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Tag new images version
on:
push:
branches:
- smola/simple-image-tagging
workflow_dispatch:

jobs:
tag-images:
name: Tag new images version
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # 3.3.0
- name: Login to ghcr.io
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # 2.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Tag images
run: ./build --tag
- name: Create Pull Request
if: steps.changes-check.outputs.changed == 'true'
run: |
git commit -am 'Update base images'
git push origin HEAD:github-actions/docker-lock-update
gh pr create --title "Update base images" --base smola/staging --head github-actions/docker-lock-update
25 changes: 25 additions & 0 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,29 @@ function do_push() {
done
}

function do_tag() {
local tag token
TAG_PREFIX=
echo "Pulling latest images"
for tag in base latest "${BASE_VARIANTS[@]}" "${VARIANTS[@]}"; do
tag="${tag,,}"
tag="$(image_name "${tag}")"
docker pull "$tag"
done
token="$(curl "https://ghcr.io/token?scope=repository:datadog/dd-trace-java-docker-build:pull" | jq -r .token)"
latest_version="$(curl -s -k -X GET -H "Authorization: Bearer $token" -H "Accept: application/json" "https://ghcr.io/v2/datadog/dd-trace-java-docker-build/tags/list" | jq -r '.tags[]' | grep ^v | sed -e 's~^v~~g' -e 's~-.*~~g' | sort -rn | head -n 1)"
latest_version="${latest_version:-0}"
next_version="$((latest_version+1))"
echo "Latest version is v$latest_version, will tag v$next_version"
for tag in base latest "${BASE_VARIANTS[@]}" "${VARIANTS[@]}"; do
tag="${tag,,}"
tag="$(image_name "${tag}")"
new_tag="${tag/:/:v$next_version-}"
docker tag "$tag" "$new_tag"
docker push "$new_tag"
done
}

if [[ -z ${1:-} ]]; then
do_build
elif [[ ${1} = "--test" ]]; then
Expand All @@ -216,4 +239,6 @@ elif [[ ${1} = "--inner-describe" ]]; then
do_inner_describe
elif [[ ${1} = "--push" ]]; then
do_push
elif [[ ${1} = "--tag" ]]; then
do_tag
fi

0 comments on commit c365220

Please sign in to comment.