88 - ' docs/**'
99 - ' examples/**'
1010 - ' **.md'
11+ tags :
12+ - ' v[0-9]+.[0-9]+.[0-9]+'
1113 pull_request :
1214 branches :
1315 - master
1921 - ' docs/**'
2022 - ' examples/**'
2123 - ' **.md'
22- create :
23- tags :
24- - ' v[0-9]+.[0-9]+.[0-9]+*'
2524
2625env :
2726 DOCKER_BUILDKIT : 1
2827
28+ concurrency :
29+ group : ${{ github.ref_name }}-ci
30+ cancel-in-progress : true
31+
2932jobs :
3033
3134 vars :
@@ -34,21 +37,15 @@ jobs:
3437 outputs :
3538 sha_short : ${{ steps.vars.outputs.sha }}
3639 go_version : ${{ steps.vars.outputs.go_version }}
37- git_tag : ${{ steps.vars.outputs.git_tag }}
3840 repo_name : ${{ steps.vars.outputs.repo }}
3941 steps :
40- - name : Cancel Previous Runs
41- uses : styfle/cancel-workflow-action@0.9.1
42- with :
43- access_token : ${{ secrets.GITHUB_TOKEN }}
4442 - name : Checkout Repository
4543 uses : actions/checkout@v2
4644 - name : Output Variables
4745 id : vars
4846 run : |
4947 echo "::set-output name=sha::$(echo ${GITHUB_SHA} | cut -c1-7)"
5048 echo "::set-output name=go_version::$(grep "go 1." go.mod | cut -d " " -f 2)"
51- echo "::set-output name=git_tag::$(echo ${GITHUB_REF/refs\/tags\//} | tr -d v)"
5249 echo "::set-output name=repo::$(echo ${GITHUB_REPOSITORY} | cut -d '/' -f 2)"
5350
5451 binary :
@@ -96,23 +93,43 @@ jobs:
9693 with :
9794 path : ${{ github.workspace }}/bin/manager
9895 key : nginx-ingress-operator-${{ github.run_id }}-${{ github.run_number }}
96+ - name : DockerHub Login
97+ uses : docker/login-action@v1
98+ with :
99+ username : ${{ secrets.DOCKER_USERNAME }}
100+ password : ${{ secrets.DOCKER_PASSWORD }}
101+ if : github.event_name != 'pull_request'
99102 - name : Docker Buildx
100103 uses : docker/setup-buildx-action@v1
104+ - name : Docker meta
105+ id : meta
106+ uses : docker/metadata-action@v3
107+ with :
108+ images : |
109+ nginx/nginx-ingress-operator
110+ tags : |
111+ type=edge
112+ type=ref,event=pr
113+ type=semver,pattern={{version}}
114+ labels : |
115+ org.opencontainers.image.documentation=https://docs.nginx.com/nginx-ingress-controller
116+ org.opencontainers.image.vendor=NGINX Inc <kubernetes@nginx.com>
101117 - name : Build Image
102118 uses : docker/build-push-action@v2
103119 with :
104120 context : ' .'
105121 cache-from : type=gha
106122 cache-to : type=gha,mode=max
107- tags : nginx/nginx-ingress-operator:${{ github.sha }}
108- push : false
123+ tags : ${{ steps.meta.outputs.tags }}
124+ labels : ${{ steps.meta.outputs.labels }}
125+ load : ${{ github.event_name == 'pull_request' }}
126+ push : ${{ github.event_name != 'pull_request' }}
109127 pull : true
110- load : true
111128 - name : Run Trivy vulnerability scanner
112- uses : aquasecurity/trivy-action@0.2.0
129+ uses : aquasecurity/trivy-action@0.2.1
113130 continue-on-error : true
114131 with :
115- image-ref : nginx/nginx-ingress-operator:${{ github.sha }}
132+ image-ref : nginx/nginx-ingress-operator:${{ steps.meta.outputs.version }}
116133 format : ' template'
117134 template : ' @/contrib/sarif.tpl'
118135 output : ' trivy-results.sarif'
@@ -121,7 +138,7 @@ jobs:
121138 uses : github/codeql-action/upload-sarif@v1
122139 continue-on-error : true
123140 with :
124- sarif_file : ' trivy-result .sarif'
141+ sarif_file : ' trivy-results .sarif'
125142 - name : Upload Scan Results
126143 uses : actions/upload-artifact@v2
127144 continue-on-error : true
@@ -130,46 +147,11 @@ jobs:
130147 path : ' trivy-results.sarif'
131148 if : always()
132149
133- release-docker :
134- name : Release Image
135- runs-on : ubuntu-20.04
136- needs : [vars, build, unit-tests]
137- if :
138- github.repository == 'nginxinc/nginx-ingress-operator' &&
139- github.event_name == 'create' &&
140- contains(github.ref, 'refs/tags/')
141- steps :
142- - name : Checkout Repository
143- uses : actions/checkout@v2
144- - name : Fetch Cached Artifacts
145- uses : actions/cache@v2
146- with :
147- path : ${{ github.workspace }}/build/_output/bin/nginx-ingress-operator
148- key : nginx-ingress-operator-${{ github.run_id }}-${{ github.run_number }}
149- - name : Docker Buildx
150- uses : docker/setup-buildx-action@v1
151- - name : DockerHub Login
152- uses : docker/login-action@v1
153- with :
154- username : ${{ secrets.DOCKER_USERNAME }}
155- password : ${{ secrets.DOCKER_PASSWORD }}
156- - name : Push to Dockerhub
157- uses : docker/build-push-action@v2
158- with :
159- file : Dockerfile
160- context : ' .'
161- cache-from : type=gha
162- cache-to : type=gha,mode=max
163- tags : |
164- nginx/nginx-ingress-operator:latest
165- nginx/nginx-ingress-operator:${{ needs.vars.outputs.git_tag }}
166- push : true
167- pull : true
168150
169151 notify :
170152 name : Notify
171153 runs-on : ubuntu-20.04
172- needs : [vars, release-docker ]
154+ needs : [vars, build ]
173155 if : always() && github.ref == 'refs/heads/master'
174156 steps :
175157 - name : Workflow Status
0 commit comments