|
| 1 | +name: Docker Release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + tag_name: |
| 10 | + description: "Release tag name (e.g., '1.0.1')" |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: docker-${{ github.workflow }}-${{ github.ref }} |
| 16 | + cancel-in-progress: false |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + |
| 21 | +env: |
| 22 | + VERSION_NUMBER: ${{ github.event.inputs.tag_name || github.event.release.tag_name }} |
| 23 | + REGISTRY: docker.io |
| 24 | + IMAGE_NAME: ${{ github.repository }} |
| 25 | + |
| 26 | +jobs: |
| 27 | + build-and-push: |
| 28 | + name: Build and Push Docker Images |
| 29 | + runs-on: ubuntu-latest |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Checkout code |
| 33 | + uses: actions/checkout@v4 |
| 34 | + |
| 35 | + - name: Set up QEMU |
| 36 | + uses: docker/setup-qemu-action@v3 |
| 37 | + with: |
| 38 | + platforms: linux/amd64,linux/arm64 |
| 39 | + |
| 40 | + - name: Set up Docker Buildx |
| 41 | + uses: docker/setup-buildx-action@v3 |
| 42 | + |
| 43 | + - name: Login to Docker Hub |
| 44 | + uses: docker/login-action@v3 |
| 45 | + with: |
| 46 | + registry: ${{ env.REGISTRY }} |
| 47 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 48 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 49 | + |
| 50 | + - name: Extract metadata for Docker |
| 51 | + id: meta |
| 52 | + uses: docker/metadata-action@v5 |
| 53 | + with: |
| 54 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 55 | + tags: | |
| 56 | + type=semver,pattern={{version}},value=${{ env.VERSION_NUMBER }} |
| 57 | + type=semver,pattern={{major}}.{{minor}},value=${{ env.VERSION_NUMBER }} |
| 58 | + type=semver,pattern={{major}},value=${{ env.VERSION_NUMBER }} |
| 59 | + type=raw,value=latest,enable=${{ !contains(env.VERSION_NUMBER, '-') }} |
| 60 | +
|
| 61 | + - name: Build and push Docker images |
| 62 | + id: build |
| 63 | + uses: docker/build-push-action@v6 |
| 64 | + with: |
| 65 | + context: . |
| 66 | + file: ./Dockerfile |
| 67 | + platforms: linux/amd64,linux/arm64 |
| 68 | + push: true |
| 69 | + tags: ${{ steps.meta.outputs.tags }} |
| 70 | + labels: ${{ steps.meta.outputs.labels }} |
| 71 | + cache-from: type=gha |
| 72 | + cache-to: type=gha,mode=max |
| 73 | + provenance: true |
| 74 | + sbom: true |
| 75 | + |
| 76 | + - name: Generate artifact attestation |
| 77 | + uses: actions/attest-build-provenance@v2 |
| 78 | + with: |
| 79 | + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 80 | + subject-digest: ${{ steps.build.outputs.digest }} |
| 81 | + push-to-registry: true |
0 commit comments