Skip to content

Commit

Permalink
tag docker image with branch name and git tags
Browse files Browse the repository at this point in the history
  • Loading branch information
steinerkelvin committed Feb 15, 2024
1 parent 58e318e commit beea080
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/docker-build-n-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ name: Build and push Docker image

on:
push:
branches: [current, feb12]
branches: [current, test]

env:
image_base: ghcr.io/agicommies/subspace

jobs:
build-n-push:
Expand All @@ -25,10 +27,18 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Compute image names for commit tags
run: |
tags=$(git tag --contains ${{ steps.commit.outputs.short }})
image_names=$(<<< $tags xargs -I {_} printf "$image_base:{_}\n")
echo tags_image_names=$image_names | tee -a $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ghcr.io/agicommies/subspace:${{ steps.commit.outputs.short }}
# , ghcr.io/agicommies/subspace:latest
tags: |
${{ env.image_base }}:${{ steps.commit.outputs.short }}
${{ env.image_base }}:${{ github.head_ref || github.ref_name }}
${{ env.tags_image_names }}
35 changes: 35 additions & 0 deletions .github/workflows/docker-retag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Tag docker image with git tags

on:
push:
tags: ["*"]

env:
image_base: ghcr.io/agicommies/subspace

jobs:
tag-docker-image:
permissions: write-all
runs-on: ubuntu-latest

steps:
- id: commit
uses: prompt/actions-commit-hash@v3

- 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
env:
image_of_commit: $image_base:${{ steps.commit.outputs.short }}
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 beea080

Please sign in to comment.