name: Build and Push Multi-Registry Docker Image on: workflow_dispatch: inputs: tag_name: description: "Custom tag name for the Docker image (comma-separated for multiple tags, e.g. latest,release-1.8.0)" required: false default: "" push_to_ghcr: description: "Push to GitHub Container Registry" type: boolean required: true default: true push_to_dockerhub: description: "Push to Docker Hub" type: boolean required: true default: true jobs: build: runs-on: blacksmith-4vcpu-ubuntu-2404 steps: - name: Checkout repository uses: actions/checkout@v5 with: fetch-depth: 1 - name: Set up QEMU uses: docker/setup-qemu-action@v3 with: platforms: arm64,arm/v7,arm/v6 - name: Setup Blacksmith Builder uses: useblacksmith/setup-docker-builder@v1 - name: Cache npm dependencies uses: actions/cache@v4 with: path: | ~/.npm node_modules */*/node_modules key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-node- - name: Cache Docker layers uses: actions/cache@v4 with: path: /tmp/.buildx-cache key: ${{ runner.os }}-buildx-${{ github.ref_name }}-${{ hashFiles('docker/Dockerfile') }} restore-keys: | ${{ runner.os }}-buildx-${{ github.ref_name }}- ${{ runner.os }}-buildx- - name: Login to GitHub Container Registry if: ${{ inputs.push_to_ghcr }} uses: docker/login-action@v3 with: registry: ghcr.io username: lukegus password: ${{ secrets.GHCR_TOKEN }} - name: Login to Docker Hub if: ${{ inputs.push_to_dockerhub }} uses: docker/login-action@v3 with: username: bugattiguy527 password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Determine Docker image tags id: vars run: | REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]') echo "REPO_OWNER=$REPO_OWNER" >> $GITHUB_ENV if [ "${{ github.event.inputs.tag_name }}" != "" ]; then IFS=',' read -ra TAGS <<< "${{ github.event.inputs.tag_name }}" elif [ "${{ github.ref }}" == "refs/heads/main" ]; then TAGS=("latest") elif [ "${{ github.ref }}" == "refs/heads/development" ]; then TAGS=("development-latest") else TAGS=("${{ github.ref_name }}") fi echo "TAGS=${TAGS[*]}" >> $GITHUB_ENV - name: Build and Push Multi-Arch Docker Image uses: useblacksmith/build-push-action@v2 with: context: . file: ./docker/Dockerfile push: true platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 tags: | ${{ inputs.push_to_ghcr && format('ghcr.io/lukegus/termix:{0}', join(fromJson('["' + replace(env.TAGS, " ", '","') + '"]'), '\nghcr.io/lukegus/termix:')) }} ${{ inputs.push_to_dockerhub && format('docker.io/bugattiguy527/termix:{0}', join(fromJson('["' + replace(env.TAGS, " ", '","') + '"]'), '\ndocker.io/bugattiguy527/termix:')) }} labels: | org.opencontainers.image.source=https://github.com/${{ github.repository }} org.opencontainers.image.revision=${{ github.sha }} build-args: | BUILDKIT_INLINE_CACHE=1 BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 outputs: type=registry,compression=zstd,compression-level=19 - name: Cleanup Docker Images Locally if: always() run: | docker image prune -af docker system prune -af --volumes