diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..333cab8 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,90 @@ +name: Multi-Arch Docker Build & Push + +on: + workflow_dispatch: + inputs: + image_name: + description: "Base image name (without registry). Example: myuser/myimage" + required: true + tags: + description: "Image tags (comma or space separated). Example: v1.01 latest beta" + required: true + dockerhub_user: + description: "Docker Hub username (leave empty if not pushing to Docker Hub)" + required: false + push_to_dockerhub: + description: "Push to Docker Hub? (true/false)" + required: false + default: "false" + push_to_ghcr: + description: "Push to GHCR? (true/false)" + required: false + default: "false" + push_to_quay: + description: "Push to Quay.io? (true/false)" + required: false + default: "false" + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + 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: Parse tags + id: tags + run: | + TAGS_INPUT="${{ github.event.inputs.tags }}" + TAGS_INPUT=$(echo "$TAGS_INPUT" | tr ',' ' ') + TAG_ARGS="" + for TAG in $TAGS_INPUT; do + if [ "${{ github.event.inputs.push_to_dockerhub }}" == "true" ]; then + TAG_ARGS="$TAG_ARGS --tag docker.io/${{ github.event.inputs.dockerhub_user }}/${{ github.event.inputs.image_name }}:$TAG" + fi + if [ "${{ github.event.inputs.push_to_ghcr }}" == "true" ]; then + TAG_ARGS="$TAG_ARGS --tag ghcr.io/${{ github.repository_owner }}/${{ github.event.inputs.image_name }}:$TAG" + fi + if [ "${{ github.event.inputs.push_to_quay }}" == "true" ]; then + TAG_ARGS="$TAG_ARGS --tag quay.io/${{ github.event.inputs.image_name }}:$TAG" + fi + done + echo "tags=$TAG_ARGS" >> $GITHUB_OUTPUT + + - name: Log in to Docker Hub + if: github.event.inputs.push_to_dockerhub == 'true' + uses: docker/login-action@v3 + with: + username: ${{ github.event.inputs.dockerhub_user }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Log in to GHCR + if: github.event.inputs.push_to_ghcr == 'true' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GHCR_TOKEN }} + + - name: Log in to Quay.io + if: github.event.inputs.push_to_quay == 'true' + uses: docker/login-action@v3 + with: + registry: quay.io + username: ${{ secrets.QUAY_USERNAME }} + password: ${{ secrets.QUAY_PASSWORD }} + + - name: Build and Push Multi-Arch Image + run: | + docker buildx build \ + --platform linux/amd64,linux/arm64 \ + ${{ steps.tags.outputs.tags }} \ + --push \ + -f Dockerfile \ + .