Skip to content

Commit

Permalink
docker image tagger
Browse files Browse the repository at this point in the history
  • Loading branch information
steinerkelvin committed Feb 15, 2024
1 parent 100c76d commit c3328d2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/docker-build-n-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
branches: [current, test]

env:
image_base: ghcr.io/agicommies/subspace

jobs:
build-n-push:
permissions: write-all
Expand All @@ -27,7 +30,7 @@ jobs:
- name: Compute image names for commit tags
run: |
tags=$(git tag --contains ${{ steps.commit.outputs.short }})
image_names=$(<<< $tags xargs -I {} printf "ghcr.io/agicommies/subspace:{}\n")
image_names=$(<<< $tags xargs -I {_} printf "$image_base:{_}\n")
echo $image_names | tee -a $GITHUB_ENV
- name: Build and push
Expand All @@ -36,5 +39,5 @@ jobs:
context: .
push: true
tags: |
ghcr.io/agicommies/subspace:${{ steps.commit.outputs.short }}
ghcr.io/agicommies/subspace:${{ github.head_ref || github.ref_name }}
$image_base:${{ steps.commit.outputs.short }}
$image_base:${{ github.head_ref || github.ref_name }}
29 changes: 29 additions & 0 deletions .github/workflows/docker-retag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
on:
push:
tags: ["*"]

env:
image_base: ghcr.io/agicommies/subspace

jobs:
tag-docker-image:
permissions: write-all
runs-on: ubuntu-latest
env:
image_of_commit: $image_base:${{ steps.commit.outputs.short }}
steps:
- name: Docker Login
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Checks if docker image is on registry
run: |
image_exists_check=$(docker manifest inspect "$image_of_commit" > /dev/null 2>&1; echo $?)
if [ $image_exists_check -eq 0 ]; then
echo "Image exists. Tagging with `${{ github.ref_name }}`"
docker buildx imagetools create "$image_of_commit" --tag "$image_base:${{ github.ref_name }}"
fi

0 comments on commit c3328d2

Please sign in to comment.