name: Build and Push Docker Image on: workflow_dispatch: inputs: version: description: "Version to build (e.g., 1.8.0)" required: true production: description: "Is this a production build?" required: true default: false type: boolean registry: description: "Docker registry to push to" required: true default: "both" type: choice options: - "ghcr" - "dockerhub" - "both" jobs: build: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v5 with: fetch-depth: 1 - name: Set up QEMU uses: docker/setup-qemu-action@v3 with: platforms: linux/amd64,linux/arm64,linux/arm/v7 - name: Setup Docker Buildx uses: docker/setup-buildx-action@v3 - name: Determine tags id: tags run: | VERSION=${{ github.event.inputs.version }} PROD=${{ github.event.inputs.production }} REGISTRY=${{ github.event.inputs.registry }} TAGS=() if [ "$PROD" = "true" ]; then TAGS+=("release-$VERSION") TAGS+=("latest") else TAGS+=("dev-$VERSION") fi ALL_TAGS=() for tag in "${TAGS[@]}"; do if [ "$REGISTRY" = "ghcr" ] || [ "$REGISTRY" = "both" ]; then ALL_TAGS+=("ghcr.io/lukegus/termix:$tag") fi if [ "$REGISTRY" = "dockerhub" ] || [ "$REGISTRY" = "both" ]; then if [ "$PROD" = "true" ]; then ALL_TAGS+=("docker.io/bugattiguy527/termix:$tag") fi fi done echo "ALL_TAGS=${ALL_TAGS[*]}" >> $GITHUB_ENV echo "All tags to build:" printf '%s\n' "${ALL_TAGS[@]}" - name: Login to GHCR if: ${{ github.event.inputs.registry == 'ghcr' || github.event.inputs.registry == 'both' }} uses: docker/login-action@v3 with: registry: ghcr.io username: lukegus password: ${{ secrets.GHCR_TOKEN }} - name: Login to Docker Hub if: ${{ github.event.inputs.registry == 'dockerhub' || github.event.inputs.registry == 'both' }} uses: docker/login-action@v3 with: username: bugattiguy527 password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push multi-arch image uses: docker/build-push-action@v5 with: context: . file: ./docker/Dockerfile push: true platforms: linux/amd64,linux/arm64,linux/arm/v7 tags: ${{ env.ALL_TAGS }} build-args: | BUILDKIT_INLINE_CACHE=1 BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 labels: | org.opencontainers.image.source=https://github.com/${{ github.repository }} org.opencontainers.image.revision=${{ github.sha }} outputs: type=registry,compression=zstd,compression-level=19 - name: Cleanup Docker if: always() run: | docker image prune -af docker system prune -af --volumes