diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml new file mode 100644 index 0000000..1b18d0f --- /dev/null +++ b/.github/workflows/publish-image.yml @@ -0,0 +1,74 @@ +name: publish-image + +on: + push: + tags: + - "*" + +jobs: + tests: + uses: ./.github/workflows/reusable-test.yml + + build-and-push: + needs: tests + runs-on: ubuntu-latest + + permissions: + contents: read + packages: 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: Extract tag + id: meta + run: | + echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT" + + - name: Check semver tag + id: semver + run: | + if [[ "${GITHUB_REF_NAME}" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "is_semver=true" >> "$GITHUB_OUTPUT" + else + echo "is_semver=false" >> "$GITHUB_OUTPUT" + fi + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push (tag) + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: true + platforms: linux/amd64,linux/arm64 + tags: | + ghcr.io/${{ github.repository }}:${{ steps.meta.outputs.tag }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Build and push (latest) + if: steps.semver.outputs.is_semver == 'true' + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: true + platforms: linux/amd64,linux/arm64 + tags: | + ghcr.io/${{ github.repository }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max