|
| 1 | +# Copyright The Linux Foundation and each contributor to LFX. |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +name: Docker Build - Release |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + tags: |
| 9 | + - v* |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + |
| 14 | +env: |
| 15 | + REGISTRY: ghcr.io |
| 16 | + IMAGE_NAME: ${{ github.repository }} |
| 17 | + COSIGN_VERSION: v2.5.3 |
| 18 | + HELM_VERSION: v3.18.4 |
| 19 | + |
| 20 | +jobs: |
| 21 | + build-and-push: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + permissions: |
| 24 | + contents: read |
| 25 | + packages: write |
| 26 | + id-token: write |
| 27 | + outputs: |
| 28 | + app_version: ${{ steps.prepare.outputs.app_version }} |
| 29 | + chart_name: ${{ steps.prepare.outputs.chart_name }} |
| 30 | + chart_version: ${{ steps.prepare.outputs.chart_version }} |
| 31 | + |
| 32 | + steps: |
| 33 | + - name: Checkout repository |
| 34 | + uses: actions/checkout@v4 |
| 35 | + |
| 36 | + - name: Prepare versions and chart name |
| 37 | + id: prepare |
| 38 | + run: | |
| 39 | + set -euo pipefail |
| 40 | + APP_VERSION=$(echo ${{ github.ref_name }} | sed 's/v//g') |
| 41 | + CHART_NAME="$(yq '.name' charts/*/Chart.yaml)" |
| 42 | + CHART_VERSION="$(yq '.version' charts/*/Chart.yaml)" |
| 43 | + { |
| 44 | + echo "app_version=$APP_VERSION" |
| 45 | + echo "chart_name=$CHART_NAME" |
| 46 | + echo "chart_version=$CHART_VERSION" |
| 47 | + } >> "$GITHUB_OUTPUT" |
| 48 | +
|
| 49 | + - name: Set up Docker Buildx |
| 50 | + uses: docker/setup-buildx-action@v3 |
| 51 | + |
| 52 | + - name: Log in to Container Registry |
| 53 | + uses: docker/login-action@v3 |
| 54 | + with: |
| 55 | + registry: ${{ env.REGISTRY }} |
| 56 | + username: ${{ github.actor }} |
| 57 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + |
| 59 | + - name: Extract metadata |
| 60 | + id: meta |
| 61 | + uses: docker/metadata-action@v5 |
| 62 | + with: |
| 63 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 64 | + tags: | |
| 65 | + type=semver,pattern={{version}} |
| 66 | + type=semver,pattern={{major}}.{{minor}} |
| 67 | +
|
| 68 | + - name: Build and push Docker image |
| 69 | + uses: docker/build-push-action@v5 |
| 70 | + with: |
| 71 | + context: . |
| 72 | + push: true |
| 73 | + tags: ${{ steps.meta.outputs.tags }} |
| 74 | + labels: ${{ steps.meta.outputs.labels }} |
| 75 | + platforms: linux/amd64,linux/arm64 |
| 76 | + cache-from: type=gha |
| 77 | + cache-to: type=gha,mode=max |
| 78 | + build-args: | |
| 79 | + BUILD_ENV=production |
| 80 | +
|
| 81 | + release-helm-chart: |
| 82 | + needs: build-and-push |
| 83 | + runs-on: ubuntu-latest |
| 84 | + permissions: |
| 85 | + contents: write |
| 86 | + packages: write |
| 87 | + id-token: write |
| 88 | + outputs: |
| 89 | + digest: ${{ steps.publish-ghcr.outputs.digest }} |
| 90 | + image_name: ${{ steps.publish-ghcr.outputs.image_name }} |
| 91 | + steps: |
| 92 | + - name: Checkout repository |
| 93 | + uses: actions/checkout@v4 |
| 94 | + |
| 95 | + - name: Publish Chart to GHCR |
| 96 | + id: publish-ghcr |
| 97 | + uses: linuxfoundation/lfx-public-workflows/.github/actions/helm-chart-oci-publisher@c465d6571fa0b8be9d551d902955164ea04a00af # main |
| 98 | + with: |
| 99 | + name: ${{ needs.build-and-push.outputs.chart_name }} |
| 100 | + repository: ${{ github.repository }}/chart |
| 101 | + chart_version: ${{ needs.build-and-push.outputs.chart_version }} |
| 102 | + app_version: ${{ needs.build-and-push.outputs.app_version }} |
| 103 | + registry: ghcr.io |
| 104 | + registry_username: ${{ github.actor }} |
| 105 | + registry_password: ${{ secrets.GITHUB_TOKEN }} |
| 106 | + |
| 107 | + - name: Install Cosign |
| 108 | + uses: sigstore/cosign-installer@d58896d6a1865668819e1d91763c7751a165e159 # v3.9.2 |
| 109 | + with: |
| 110 | + cosign-release: "${{ env.COSIGN_VERSION }}" |
| 111 | + |
| 112 | + - name: Login to GitHub |
| 113 | + uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0 |
| 114 | + with: |
| 115 | + registry: ghcr.io |
| 116 | + username: ${{ github.actor }} |
| 117 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 118 | + |
| 119 | + - name: Sign the Helm chart in GHCR |
| 120 | + env: |
| 121 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 122 | + run: | |
| 123 | + set -euo pipefail |
| 124 | + cosign sign --yes '${{ steps.publish-ghcr.outputs.image_name }}@${{ steps.publish-ghcr.outputs.digest }}' |
| 125 | +
|
| 126 | + create-ghcr-helm-provenance: |
| 127 | + needs: |
| 128 | + - release-helm-chart |
| 129 | + permissions: |
| 130 | + actions: read |
| 131 | + id-token: write |
| 132 | + packages: write |
| 133 | + uses: slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@v2.1.0 |
| 134 | + with: |
| 135 | + image: ${{ needs.release-helm-chart.outputs.image_name }} |
| 136 | + digest: ${{ needs.release-helm-chart.outputs.digest }} |
| 137 | + registry-username: ${{ github.actor }} |
| 138 | + secrets: |
| 139 | + registry-password: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments