|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + platforms: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + image: |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + tag: |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + |
| 16 | +defaults: |
| 17 | + run: |
| 18 | + shell: bash |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: read |
| 22 | + |
| 23 | +jobs: |
| 24 | + build: |
| 25 | + permissions: |
| 26 | + contents: read # for docker/build-push-action to read repo content |
| 27 | + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results |
| 28 | + packages: write # for docker/build-push-action to push to GHCR |
| 29 | + id-token: write # for docker/login to login to NGINX registry |
| 30 | + runs-on: ${{ github.event_name != 'pull_request' && contains(inputs.image, 'plus') && 'kic-plus' || 'ubuntu-22.04' }} |
| 31 | + services: |
| 32 | + registry: |
| 33 | + image: registry:2 |
| 34 | + ports: |
| 35 | + - 5000:5000 |
| 36 | + steps: |
| 37 | + - name: Checkout Repository |
| 38 | + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 |
| 39 | + with: |
| 40 | + ref: ${{ inputs.tag != '' && format('refs/tags/v{0}', inputs.tag) || github.ref }} |
| 41 | + |
| 42 | + - name: Fetch Cached Artifacts |
| 43 | + uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0 |
| 44 | + with: |
| 45 | + path: ${{ github.workspace }}/dist |
| 46 | + key: nginx-gateway-fabric-${{ github.run_id }}-${{ github.run_number }} |
| 47 | + |
| 48 | + - name: Docker Buildx |
| 49 | + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 |
| 50 | + with: |
| 51 | + driver-opts: network=host |
| 52 | + |
| 53 | + - name: Setup QEMU |
| 54 | + uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0 |
| 55 | + with: |
| 56 | + platforms: arm64 |
| 57 | + |
| 58 | + - name: Login to GitHub Container Registry |
| 59 | + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 |
| 60 | + if: ${{ github.event_name != 'pull_request' && ! contains(inputs.image, 'plus') }} |
| 61 | + with: |
| 62 | + registry: ghcr.io |
| 63 | + username: ${{ github.repository_owner }} |
| 64 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 65 | + |
| 66 | + - name: Get Id Token |
| 67 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 68 | + id: idtoken |
| 69 | + with: |
| 70 | + script: | |
| 71 | + let id_token = await core.getIDToken() |
| 72 | + core.setOutput('id_token', id_token) |
| 73 | + if: ${{ github.event_name != 'pull_request' && contains(inputs.image, 'plus')}} |
| 74 | + |
| 75 | + - name: Login to NGINX Registry |
| 76 | + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 |
| 77 | + with: |
| 78 | + registry: docker-mgmt.nginx.com |
| 79 | + username: ${{ steps.idtoken.outputs.id_token }} |
| 80 | + password: ${{ github.actor }} |
| 81 | + if: ${{ github.event_name != 'pull_request' && contains(inputs.image, 'plus') }} |
| 82 | + |
| 83 | + - name: Docker meta |
| 84 | + id: meta |
| 85 | + uses: docker/metadata-action@dbef88086f6cef02e264edb7dbf63250c17cef6c # v5.5.0 |
| 86 | + with: |
| 87 | + images: | |
| 88 | + name=ghcr.io/nginxinc/nginx-gateway-fabric,enable=${{ inputs.image == 'ngf' && github.event_name != 'pull_request' }} |
| 89 | + name=ghcr.io/nginxinc/nginx-gateway-fabric/nginx,enable=${{ inputs.image == 'nginx' && github.event_name != 'pull_request' }} |
| 90 | + name=docker-mgmt.nginx.com/nginx-gateway-fabric/nginx-plus,enable=${{ inputs.image == 'nginx-plus' && github.event_name != 'pull_request' }} |
| 91 | + name=localhost:5000/nginx-gateway-fabric/${{ inputs.image }} |
| 92 | + flavor: | |
| 93 | + latest=${{ (inputs.tag != '' && 'true') || 'auto' }} |
| 94 | + tags: | |
| 95 | + type=semver,pattern={{version}} |
| 96 | + type=edge |
| 97 | + type=ref,event=pr |
| 98 | + type=ref,event=branch,suffix=-rc,enable=${{ startsWith(github.ref, 'refs/heads/release') }} |
| 99 | + type=raw,value=${{ inputs.tag }},enable=${{ inputs.tag != '' }} |
| 100 | + labels: | |
| 101 | + org.opencontainers.image.documentation=https://docs.nginx.com/nginx-gateway-fabric |
| 102 | + org.opencontainers.image.vendor=NGINX Inc <[email protected]> |
| 103 | + env: |
| 104 | + DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index |
| 105 | + |
| 106 | + - name: Build Docker Image |
| 107 | + uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0 |
| 108 | + with: |
| 109 | + file: build/Dockerfile${{ inputs.image == 'nginx' && '.nginx' || '' }}${{ inputs.image == 'nginx-plus' && '.nginxplus' || '' }} |
| 110 | + context: "." |
| 111 | + target: ${{ inputs.image == 'ngf' && 'goreleaser' || '' }} |
| 112 | + tags: ${{ steps.meta.outputs.tags }} |
| 113 | + labels: ${{ steps.meta.outputs.labels }} |
| 114 | + annotations: ${{ steps.meta.outputs.annotations }} |
| 115 | + push: true |
| 116 | + platforms: ${{ inputs.platforms }} |
| 117 | + cache-from: type=gha,scope=${{ inputs.image }} |
| 118 | + cache-to: type=gha,scope=${{ inputs.image }},mode=max |
| 119 | + pull: true |
| 120 | + no-cache: ${{ github.event_name != 'pull_request' }} |
| 121 | + sbom: true |
| 122 | + provenance: true |
| 123 | + build-args: | |
| 124 | + NJS_DIR=internal/mode/static/nginx/modules/src |
| 125 | + NGINX_CONF_DIR=internal/mode/static/nginx/conf |
| 126 | + BUILD_AGENT=gha |
| 127 | + secrets: | |
| 128 | + ${{ contains(inputs.image, 'plus') && format('"nginx-repo.crt={0}"', secrets.NGINX_CRT) || '' }} |
| 129 | + ${{ contains(inputs.image, 'plus') && format('"nginx-repo.key={0}"', secrets.NGINX_KEY) || '' }} |
| 130 | +
|
| 131 | + - name: Inspect SBOM |
| 132 | + run: | |
| 133 | + docker buildx imagetools inspect localhost:5000/nginx-gateway-fabric/${{ inputs.image }}:${{ steps.meta.outputs.version }} --format '{{ json (index .SBOM "linux/amd64").SPDX }}' > sbom-${{ inputs.image }}.json |
| 134 | +
|
| 135 | + - name: Scan SBOM |
| 136 | + id: scan |
| 137 | + uses: anchore/scan-action@1d59d90b47fc11ff8f97822da6c25eec888f81cf # v3.5.0 |
| 138 | + with: |
| 139 | + sbom: "sbom-${{ inputs.image }}.json" |
| 140 | + only-fixed: true |
| 141 | + add-cpes-if-none: true |
| 142 | + |
| 143 | + - name: Upload scan result to GitHub Security tab |
| 144 | + uses: github/codeql-action/upload-sarif@b7bf0a3ed3ecfa44160715d7c442788f65f0f923 # v3.23.2 |
| 145 | + continue-on-error: true |
| 146 | + with: |
| 147 | + sarif_file: ${{ steps.scan.outputs.sarif }} |
| 148 | + |
| 149 | + - name: Upload Scan Results |
| 150 | + uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0 |
| 151 | + continue-on-error: true |
| 152 | + with: |
| 153 | + name: scan-results-${{ inputs.image }}.sarif |
| 154 | + path: ${{ steps.scan.outputs.sarif }} |
| 155 | + if: always() |
0 commit comments