|
| 1 | +name: Update Docker Images |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "0 2 * * *" # run every day at 02:00 UTC |
| 6 | + |
| 7 | +defaults: |
| 8 | + run: |
| 9 | + shell: bash |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: ${{ github.ref_name }}-update-images |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + |
| 18 | +env: |
| 19 | + platforms: "linux/arm64, linux/amd64" |
| 20 | + |
| 21 | +jobs: |
| 22 | + variables: |
| 23 | + name: Get versions of base images |
| 24 | + runs-on: ubuntu-22.04 |
| 25 | + outputs: |
| 26 | + nkg_tag: ${{ steps.nkg.outputs.tag }} |
| 27 | + nginx_version: ${{ steps.nginx.outputs.nginx_version }} |
| 28 | + steps: |
| 29 | + - name: Checkout Repository |
| 30 | + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 |
| 31 | + with: |
| 32 | + fetch-depth: 0 |
| 33 | + |
| 34 | + - name: Set NKG version |
| 35 | + id: nkg |
| 36 | + run: | |
| 37 | + tag="$(git tag --sort=-version:refname | head -n1)" |
| 38 | + echo "tag=${tag//v}" >> $GITHUB_OUTPUT |
| 39 | +
|
| 40 | + - name: Checkout Repository at ${{ steps.nkg.outputs.tag }} |
| 41 | + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 |
| 42 | + with: |
| 43 | + ref: refs/tags/v${{ steps.nkg.outputs.tag }} |
| 44 | + |
| 45 | + - name: Set NGINX version |
| 46 | + id: nginx |
| 47 | + run: | |
| 48 | + version=library/nginx:$(grep -m1 "FROM.*nginx:.*alpine" < build/Dockerfile.nginx | awk -F"[ :]" '{print $3}') |
| 49 | + echo nginx_version=${version} >> $GITHUB_OUTPUT |
| 50 | +
|
| 51 | + check: |
| 52 | + name: Check if updates are needed |
| 53 | + runs-on: ubuntu-22.04 |
| 54 | + needs: variables |
| 55 | + outputs: |
| 56 | + needs-updating: ${{ steps.needs.outputs.needs-updating }} |
| 57 | + steps: |
| 58 | + - name: Check if update available for nginx image |
| 59 | + id: update |
| 60 | + uses: lucacome/docker-image-update-checker@f50d56412b948cfdbb842c5419372681e0db3df1 # v1.2.1 |
| 61 | + with: |
| 62 | + base-image: ${{ needs.variables.outputs.nginx_version }} |
| 63 | + image: ghcr.io/nginxinc/nginx-kubernetes-gateway/nginx:${{ needs.variables.outputs.nkg_tag }} |
| 64 | + platforms: ${{ env.platforms }} |
| 65 | + |
| 66 | + - id: needs |
| 67 | + run: echo "needs-updating=${{ steps.update.outputs.needs-updating }}" >> $GITHUB_OUTPUT |
| 68 | + |
| 69 | + build: |
| 70 | + name: Build Image |
| 71 | + runs-on: ubuntu-22.04 |
| 72 | + needs: [variables, check] |
| 73 | + if: ${{ needs.check.outputs.needs-updating }} |
| 74 | + strategy: |
| 75 | + fail-fast: false |
| 76 | + permissions: |
| 77 | + contents: read # for docker/build-push-action to read repo content |
| 78 | + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results |
| 79 | + packages: write # for docker/build-push-action to push to GHCR |
| 80 | + steps: |
| 81 | + - name: Checkout Repository |
| 82 | + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 |
| 83 | + |
| 84 | + - name: Docker Buildx |
| 85 | + uses: docker/setup-buildx-action@885d1462b80bc1c1c7f0b00334ad271f09369c55 # v2.10.0 |
| 86 | + |
| 87 | + - name: Setup QEMU |
| 88 | + uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 # v2.2.0 |
| 89 | + with: |
| 90 | + platforms: arm64 |
| 91 | + |
| 92 | + - name: Login to GitHub Container Registry |
| 93 | + uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0 |
| 94 | + with: |
| 95 | + registry: ghcr.io |
| 96 | + username: ${{ github.repository_owner }} |
| 97 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 98 | + |
| 99 | + - name: Docker meta |
| 100 | + id: meta |
| 101 | + uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 # v4.6.0 |
| 102 | + with: |
| 103 | + images: | |
| 104 | + name=ghcr.io/nginxinc/nginx-kubernetes-gateway/nginx |
| 105 | + tags: | |
| 106 | + ${{ needs.variables.outputs.nkg_tag }} |
| 107 | +
|
| 108 | + - name: Build Docker Image |
| 109 | + uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1 |
| 110 | + with: |
| 111 | + file: 'build/Dockerfile.nginx' |
| 112 | + context: "." |
| 113 | + tags: ${{ steps.meta.outputs.tags }} |
| 114 | + labels: ${{ steps.meta.outputs.labels }} |
| 115 | + push: true |
| 116 | + platforms: ${{ env.platforms }} |
| 117 | + pull: true |
| 118 | + no-cache: true |
| 119 | + sbom: true |
| 120 | + provenance: false |
| 121 | + build-args: | |
| 122 | + NJS_DIR=internal/mode/static/nginx/modules/src |
| 123 | + NGINX_CONF_DIR=internal/mode/static/nginx/conf |
| 124 | +
|
| 125 | + - name: Run Trivy vulnerability scanner |
| 126 | + uses: aquasecurity/trivy-action@41f05d9ecffa2ed3f1580af306000f734b733e54 # 0.11.2 |
| 127 | + continue-on-error: true |
| 128 | + with: |
| 129 | + image-ref: ghcr.io/nginxinc/nginx-kubernetes-gateway/nginx:${{ needs.variables.outputs.nkg_tag }} |
| 130 | + format: "sarif" |
| 131 | + output: trivy-results-nginx-kubernetes-gateway-nginx |
| 132 | + ignore-unfixed: "true" |
| 133 | + |
| 134 | + - name: Upload Trivy scan results to GitHub Security tab |
| 135 | + uses: github/codeql-action/upload-sarif@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8 # v2.21.5 |
| 136 | + continue-on-error: true |
| 137 | + with: |
| 138 | + sarif_file: trivy-results-nginx-kubernetes-gateway-nginx |
| 139 | + |
| 140 | + - name: Upload Scan Results |
| 141 | + uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 |
| 142 | + continue-on-error: true |
| 143 | + with: |
| 144 | + name: trivy-results-nginx-kubernetes-gateway-nginx |
| 145 | + path: trivy-results-nginx-kubernetes-gateway-nginx |
| 146 | + if: always() |
0 commit comments