name: 🐳 Build & Push Docker Image on: push: branches: [main] tags: ['v*'] paths: - package.json - Dockerfile - 'src/**' 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: ${{ 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="" REPO_LOWER=$(echo "${{ env.REPO_NAME }}" | tr '[:upper:]' '[:lower:]') if [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ inputs.tag }}" ]]; then # Manual dispatch with custom tag TAG="${{ inputs.tag }}" TAGS="docker.io/${REPO_LOWER}:${TAG},ghcr.io/${REPO_LOWER}:${TAG}" elif [[ "${{ github.ref_type }}" == "tag" ]]; then # Git tag push TAG="${{ github.ref_name }}" TAG="${TAG#v}" # Remove v prefix TAGS="docker.io/${REPO_LOWER}:${TAG},ghcr.io/${REPO_LOWER}:${TAG}" elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then # Main branch push TAGS="docker.io/${REPO_LOWER}:latest,ghcr.io/${REPO_LOWER}:latest" fi echo "tags=${TAGS}" >> $GITHUB_OUTPUT echo "repo_lower=${REPO_LOWER}" >> $GITHUB_OUTPUT echo "Publishing tags: ${TAGS}" - name: 🔑 Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.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.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - name: 📋 Extract metadata id: meta uses: docker/metadata-action@v5 with: images: ghcr.io/${{ steps.tags.outputs.repo_lower }} tags: | type=raw,value=${{ steps.tags.outputs.tags }} labels: | org.opencontainers.image.title=Networking Toolbox org.opencontainers.image.description=All-in-one Swiss Army knife for sysadmins and network engineers - a collection of 100+ offline-first essential networking tools in a single, easy-to-use Docker image. org.opencontainers.image.url=https://github.com/${{ github.repository }} org.opencontainers.image.source=https://github.com/${{ github.repository }} org.opencontainers.image.vendor=${{ github.repository_owner }} - 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 && github.event_name != 'pull_request' }} tags: ${{ steps.tags.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max build-args: | BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} REVISION=${{ github.sha }} - 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"