From d9a75c7c1a52166e636d0831456f2a57c9e76740 Mon Sep 17 00:00:00 2001 From: krakenhavoc Date: Tue, 24 Mar 2026 14:48:36 +0000 Subject: [PATCH] feat: container release pipeline --- .github/workflows/docker-publish.yaml | 110 ++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 .github/workflows/docker-publish.yaml diff --git a/.github/workflows/docker-publish.yaml b/.github/workflows/docker-publish.yaml new file mode 100644 index 0000000..82c936a --- /dev/null +++ b/.github/workflows/docker-publish.yaml @@ -0,0 +1,110 @@ +name: CI/CD — Build and Publish Probe Image + +on: + push: + branches: [main] + paths: + - '**.go' + - go.mod + - go.sum + - Dockerfile + - .github/workflows/docker-publish.yaml + pull_request: + branches: [main] + paths: + - '**.go' + - go.mod + - go.sum + - Dockerfile + - .github/workflows/docker-publish.yaml + workflow_dispatch: {} + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + ci: + name: Lint and test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: "1.24" + - uses: golangci/golangci-lint-action@v6 + with: + version: latest + - run: go test ./... -race + + build-and-push: + name: Build and push Probe Docker image + needs: ci + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + 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: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=sha + type=raw,value=dev + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + VERSION=${{ github.sha }} + cache-from: type=gha + cache-to: type=gha,mode=max + + deploy: + name: Deploy to ${{ matrix.environment }} + needs: build-and-push + if: github.event_name == 'push' + runs-on: ubuntu-latest + strategy: + matrix: + environment: >- + ${{ + github.ref == 'refs/heads/main' + && fromJSON('["dev","prd"]') + || fromJSON('["dev"]') + }} + steps: + - name: Trigger infra deployment + uses: peter-evans/repository-dispatch@v4 + with: + token: ${{ secrets.INFRA_DEPLOY_PAT }} + repository: KrakenKey/infra-int + event-type: image-published + client-payload: >- + {"image": "${{ env.IMAGE_NAME }}", "sha": "${{ github.sha }}", "ref": "${{ github.ref_name }}", "environment": "${{ matrix.environment }}"}