tag docker image with branch name and git tags #34
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and push Docker image | |
on: | |
push: | |
branches: [current, test] | |
env: | |
image_base: ghcr.io/agicommies/subspace | |
jobs: | |
build-n-push: | |
permissions: write-all | |
runs-on: ubuntu-22.04-32core-karl | |
steps: | |
- uses: actions/checkout@v3 | |
- id: commit | |
uses: prompt/actions-commit-hash@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker Login | |
uses: docker/[email protected] | |
with: | |
registry: ghcr.io | |
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: | | |
${{ env.image_base }}:${{ steps.commit.outputs.short }} | |
${{ env.image_base }}:${{ github.head_ref || github.ref_name }} | |
${{ env.tags_image_names }} |