chore: add Docker deployment support #1
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docker | |
| on: | |
| push: | |
| branches: [main] | |
| tags: ["v*"] | |
| pull_request: | |
| paths: | |
| - "Dockerfile" | |
| - ".dockerignore" | |
| - ".github/workflows/docker.yml" | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| packages: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| # Build binaries first (needed for Docker image) | |
| build-binaries: | |
| name: Build Linux Binaries | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| strategy: | |
| matrix: | |
| include: | |
| - platform: linux-amd64 | |
| goos: linux | |
| goarch: amd64 | |
| - platform: linux-arm64 | |
| goos: linux | |
| goarch: arm64 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| with: | |
| persist-credentials: false | |
| - name: Set up Go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| check-latest: false | |
| - name: Build CLI | |
| run: | | |
| BINARY="github-actions-utils-cli-${{ matrix.platform }}" | |
| # Build static binary (no CGO, static linking) | |
| CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build \ | |
| -ldflags "-s -w -extldflags '-static'" \ | |
| -a -installsuffix cgo \ | |
| -o "dist/${BINARY}" \ | |
| ./cmd/cli | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: cli-${{ matrix.platform }} | |
| path: dist/github-actions-utils-cli-* | |
| retention-days: 1 | |
| # Build and push Docker images | |
| docker: | |
| name: Build and Push Docker Image | |
| needs: build-binaries | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| with: | |
| persist-credentials: false | |
| - name: Download Linux binaries | |
| uses: actions/download-artifact@v6 | |
| with: | |
| path: dist | |
| pattern: cli-linux-* | |
| merge-multiple: true | |
| - 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 Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| # Tag as 'latest' on main branch | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| # Tag with version on tags (e.g., v1.0.0 -> 1.0.0) | |
| type=semver,pattern={{version}} | |
| # Tag with major.minor on tags (e.g., v1.0.0 -> 1.0) | |
| type=semver,pattern={{major}}.{{minor}} | |
| # Tag with major on tags (e.g., v1.0.0 -> 1) | |
| type=semver,pattern={{major}} | |
| # Tag with short commit SHA | |
| type=sha,prefix={{branch}}- | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |