mirror of
https://github.com/lissy93/networking-toolbox.git
synced 2026-11-22 14:01:44 +03:00
100 lines
3.2 KiB
YAML
100 lines
3.2 KiB
YAML
name: 🐳 Build & Push Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
tags: ['v*']
|
|
workflow_dispatch:
|
|
inputs:
|
|
tag:
|
|
description: 'Custom tag to publish'
|
|
required: false
|
|
type: string
|
|
dry_run:
|
|
description: 'Build without pushing'
|
|
required: false
|
|
default: false
|
|
type: boolean
|
|
|
|
env:
|
|
REPO_NAME: 'lissy93/networking-toolbox'
|
|
# REPO_NAME: ${{ vars.REPO_NAME || github.repository }}
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
attestations: write
|
|
id-token: write
|
|
|
|
steps:
|
|
- name: 🛎️ Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: 🔌 Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: 🔌 Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: 🏷️ Determine tags
|
|
id: tags
|
|
run: |
|
|
TAGS=""
|
|
|
|
if [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ inputs.tag }}" ]]; then
|
|
# Manual dispatch with custom tag
|
|
TAG="${{ inputs.tag }}"
|
|
TAGS="docker.io/${{ env.REPO_NAME }}:${TAG},ghcr.io/${{ env.REPO_NAME }}:${TAG}"
|
|
elif [[ "${{ github.ref_type }}" == "tag" ]]; then
|
|
# Git tag push
|
|
TAG="${{ github.ref_name }}"
|
|
TAG="${TAG#v}" # Remove v prefix
|
|
TAGS="docker.io/${{ env.REPO_NAME }}:${TAG},ghcr.io/${{ env.REPO_NAME }}:${TAG}"
|
|
elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
|
|
# Main branch push
|
|
TAGS="docker.io/${{ env.REPO_NAME }}:latest,ghcr.io/${{ env.REPO_NAME }}:latest"
|
|
fi
|
|
|
|
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
|
|
echo "Publishing tags: ${TAGS}"
|
|
|
|
- name: 🔑 Login to Docker Hub
|
|
if: steps.tags.outputs.tags != '' && vars.DOCKER_USERNAME != ''
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ vars.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_TOKEN }}
|
|
continue-on-error: true
|
|
|
|
- name: 🔑 Login to GitHub Container Registry
|
|
if: steps.tags.outputs.tags != ''
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: 🔨 Build and push
|
|
if: steps.tags.outputs.tags != ''
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64
|
|
push: ${{ !inputs.dry_run }}
|
|
tags: ${{ steps.tags.outputs.tags }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
labels: |
|
|
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
|
|
org.opencontainers.image.revision=${{ github.sha }}
|
|
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
|
|
|
|
- name: ⚠️ Warning if skipped
|
|
if: steps.tags.outputs.tags == ''
|
|
run: |
|
|
echo "::warning::No tags determined - skipping Docker build"
|
|
echo "This happens when the trigger doesn't match main branch, git tag, or manual dispatch with tag"
|