From 7d7da3ca1b57e9d8f1ce671eb6869620f6f9e28d Mon Sep 17 00:00:00 2001 From: remsky Date: Thu, 2 Jan 2025 01:32:53 -0700 Subject: [PATCH] test: Add GitHub Actions workflow for Docker build and publish --- .github/workflows/docker-publish.yml | 105 +++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..bcb8bdd --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,105 @@ +name: Docker Build and Publish + +on: + push: + branches: [ "master" ] + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "master" ] + # Allow manual trigger from GitHub UI + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata for GPU image + - name: Extract metadata (tags, labels) for GPU Docker + id: meta-gpu + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + + # Extract metadata for CPU image + - name: Extract metadata (tags, labels) for CPU Docker + id: meta-cpu + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + suffix=-cpu + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + + # Build and push GPU version + - name: Build and push GPU Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta-gpu.outputs.tags }} + labels: ${{ steps.meta-gpu.outputs.labels }} + platforms: linux/amd64 + target: runtime + + # Build and push CPU version + - name: Build and push CPU Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile.cpu + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta-cpu.outputs.tags }} + labels: ${{ steps.meta-cpu.outputs.labels }} + platforms: linux/amd64 + target: runtime + + create-release: + needs: build + runs-on: ubuntu-latest + # Only run this job if we're pushing a tag + if: startsWith(github.ref, 'refs/tags/') + permissions: + contents: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Create Release + uses: softprops/action-gh-release@v1 + with: + generate_release_notes: true + draft: false + prerelease: false