@@ -109,14 +109,12 @@ jobs:
109
109
110
110
docker :
111
111
needs : tests
112
-
113
- name : Build (and push) Docker image
112
+ name : Docker image build
114
113
runs-on : ubuntu-latest
115
114
116
115
steps :
117
- - uses : actions/checkout@v2
118
-
119
- - name : Set tag
116
+ - uses : actions/checkout@v3
117
+ - name : Determine tag/commit hash
120
118
id : vars
121
119
run : |
122
120
# Strip git ref prefix from version
@@ -125,21 +123,22 @@ jobs:
125
123
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
126
124
# Use Docker `latest` tag convention
127
125
[ "$VERSION" == "master" ] && VERSION=latest
128
- echo ::set-output name=tag::${VERSION}
126
+ echo "tag=${VERSION}" >> $GITHUB_OUTPUT
127
+ echo "git_hash=${GITHUB_SHA}" >> $GITHUB_OUTPUT
129
128
- name : Build the Docker image
130
- env :
131
- RELEASE_VERSION : ${{ steps.vars.outputs.tag }}
132
- run : docker build . --tag $IMAGE_NAME:$RELEASE_VERSION
133
-
134
- - name : Log into registry
135
- if : github.event_name == 'push' # exclude PRs
136
- run : echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u $ {{ secrets.DOCKER_USERNAME }} --password-stdin
137
-
138
- - name : Push the Docker image
139
- if : github.event_name == 'push' && github.repository_owner == 'maykinmedia' # exclude PRs/forks
140
- env :
141
- RELEASE_VERSION : ${{ steps.vars.outputs.tag }}
142
- run : docker push $IMAGE_NAME:$RELEASE_VERSION
129
+ run : |
130
+ docker build \
131
+ --tag $IMAGE_NAME:${{ steps.vars.outputs.tag }} \
132
+ --build-arg COMMIT_HASH=${{ steps.vars.outputs.git_hash }} \
133
+ --build-arg RELEASE=${{ steps.vars.outputs.tag }} \
134
+ .
135
+ - run : docker image save -o image.tar $IMAGE_NAME:$ {{ steps.vars.outputs.tag }}
136
+ - name : Store image artifact
137
+ uses : actions/upload-artifact@v3
138
+ with :
139
+ name : docker-image
140
+ path : image.tar
141
+ retention-days : 1
143
142
144
143
image_scan :
145
144
runs-on : ubuntu-latest
@@ -167,7 +166,7 @@ jobs:
167
166
- name : Download built image
168
167
uses : actions/download-artifact@v3
169
168
with :
170
- name : docker-image-all-extensions-${{ steps.vars.outputs.tag }}
169
+ name : docker-image
171
170
- name : Scan image with Trivy
172
171
uses : aquasecurity/trivy-action@master
173
172
with :
@@ -180,3 +179,42 @@ jobs:
180
179
with :
181
180
sarif_file : ' trivy-results-docker.sarif'
182
181
182
+ publish :
183
+ needs :
184
+ - tests
185
+ - docker
186
+
187
+ name : Push Docker image
188
+ runs-on : ubuntu-latest
189
+ if : github.event_name == 'push' && github.repository_owner == 'open-klant' # exclude PRs/forks
190
+
191
+ steps :
192
+ - uses : actions/checkout@v3
193
+ - name : Download built image
194
+ uses : actions/download-artifact@v3
195
+ with :
196
+ name : docker-image
197
+
198
+ - name : Determine tag/commit hash
199
+ id : vars
200
+ run : |
201
+ # Strip git ref prefix from version
202
+ VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
203
+
204
+ # Strip "v" prefix from tag name (if present at all)
205
+ [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
206
+
207
+ # Use Docker `latest` tag convention
208
+ [ "$VERSION" == "main" ] && VERSION=latest
209
+
210
+ echo "tag=${VERSION}" >> $GITHUB_OUTPUT
211
+
212
+ - name : Load image
213
+ run : |
214
+ docker image load -i image.tar
215
+
216
+ - name : Log into registry
217
+ run : echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
218
+
219
+ - name : Push the Docker image
220
+ run : docker push $IMAGE_NAME:${{ steps.vars.outputs.tag }}
0 commit comments