Publish release to DockerHub #21
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: Publish release to DockerHub | |
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
on: | |
release: | |
types: | |
- published | |
workflow_dispatch: | |
env: | |
# Use docker.io for Docker Hub if empty | |
REGISTRY: docker.io | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
outputs: | |
is_dev: ${{ steps.check_version.outputs.is_dev }} | |
steps: | |
- name: Extract branch or tag name and determine if it's a dev release | |
id: check_version | |
run: | | |
# Extract branch or tag name | |
if [[ "$GITHUB_REF" == refs/heads/* ]]; then | |
TAG_NAME="${GITHUB_REF#refs/heads/}" # Extract branch name | |
elif [[ "$GITHUB_REF" == refs/tags/* ]]; then | |
TAG_NAME="${GITHUB_REF#refs/tags/}" # Extract tag name | |
else | |
TAG_NAME="$GITHUB_REF" # Fallback (shouldn't happen) | |
fi | |
echo "Extracted TAG_NAME: $TAG_NAME" | |
# Check if TAG_NAME starts with "dev" | |
if [[ "$TAG_NAME" == dev* ]]; then | |
echo "is_dev=true" >> $GITHUB_ENV | |
echo "is_dev=true" >> $GITHUB_OUTPUT | |
echo "Detected a development release: $TAG_NAME" | |
else | |
echo "is_dev=false" >> $GITHUB_ENV | |
echo "is_dev=false" >> $GITHUB_OUTPUT | |
echo "Detected a production release: $TAG_NAME" | |
fi | |
shell: bash | |
build-prod: | |
needs: setup | |
if: needs.setup.outputs.is_dev == 'false' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
id-token: write | |
attestations: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@4574d27a4764455b42196d70a065bc6853246a25 | |
- name: Setup Docker buildx | |
uses: docker/setup-buildx-action@f7ce87c1d6bead3e36075b2ce75da1f6cc28aaca | |
- name: Log into registry ${{ env.REGISTRY }} | |
uses: docker/login-action@327cd5a69de6c009b9ce71bce8395f28e651bf99 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@8e1d5461f02b7886d3c1a774bfbd873650445aa2 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}} | |
- name: Build and push Docker image (Production Release) | |
id: build-and-push | |
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
provenance: true | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
build-dev: | |
needs: setup | |
if: needs.setup.outputs.is_dev == 'true' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
id-token: write | |
attestations: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@4574d27a4764455b42196d70a065bc6853246a25 | |
- name: Setup Docker buildx | |
uses: docker/setup-buildx-action@f7ce87c1d6bead3e36075b2ce75da1f6cc28aaca | |
- name: Log into registry ${{ env.REGISTRY }} | |
uses: docker/login-action@327cd5a69de6c009b9ce71bce8395f28e651bf99 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@8e1d5461f02b7886d3c1a774bfbd873650445aa2 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name == 'develop' && 'develop' || format('dev-{0}', github.ref_name) }} | |
- name: Build and push Docker image (Production Release) | |
id: build-and-push | |
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
provenance: true | |
push: true | |
tags: | | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name == 'develop' && 'develop' || format('dev-{0}', github.ref_name) }} | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:dev-latest | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |