Skip to content

Use docker metadata to generate tags and labels #19

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,24 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Docker image tags
run: |
echo 'DOCKER_IMAGE_TAGS<<EOF' >> $GITHUB_ENV

# Add release tag if it matches pattern (e.g. 0.0.1)
if [[ ${{ github.ref_name }} =~ .+\..+\..+ ]]; then
echo ",ghcr.io/${{ github.repository }}:${{ github.ref_name }}" >> $GITHUB_ENV
fi

# Only add latest tag if master branch
if [[ ${{ github.ref_name }} == 'master' ]]; then
echo ",ghcr.io/${{ github.repository }}:latest" >> $GITHUB_ENV
fi

echo 'EOF' >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest
type=semver,pattern={{version}}

# Only build and push Docker images for releases
- name: Build and push Docker image to GitHub Container Registry
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ env.DOCKER_IMAGE_TAGS }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
git_commit_id=${{ github.sha }}
cache-from: type=local,src=/tmp/.buildx-cache
Expand Down