Skip to content

Commit 72171d2

Browse files
committed
ci: implement semver for docker images and create release in pipeline
1 parent 85c134d commit 72171d2

File tree

1 file changed

+55
-6
lines changed

1 file changed

+55
-6
lines changed

.github/workflows/app-pipeline.yml

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ jobs:
129129
uses: docker/setup-buildx-action@v3
130130

131131
- uses: actions/checkout@v4
132+
with:
133+
fetch-depth: 0
134+
135+
- name: fetch-tags
136+
run: git fetch --tags origin
137+
shell: bash
132138

133139
- name: Set up Python version
134140
uses: actions/setup-python@v4.7.1
@@ -151,9 +157,15 @@ jobs:
151157
run: |
152158
checkov -d . --framework dockerfile --skip-check CKV_DOCKER_2
153159
160+
- id: bump-version
161+
name: Bump to Next Semver Version
162+
uses: armakuni/github-actions/bump-version@0.14.11
163+
154164
- name: Build Docker Image
155165
run: |
156-
docker build -t "${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ github.run_id }}" .
166+
echo "The next tag version is ::: ${{ steps.bump-version.outputs.current_version }}"
167+
echo "${{ steps.bump-version.outputs.current_version }}" > tag-version.txt
168+
docker build -t "${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ steps.bump-version.outputs.current_version }}" .
157169
echo "docker image built successfully"
158170
159171
- name: Scan Docker Image Vulnerabilities
@@ -168,9 +180,15 @@ jobs:
168180

169181
- name: Push Docker Image
170182
run: |
171-
docker tag "${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ github.run_id }}" "${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest"
172-
docker push "${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ github.run_id }}"
183+
docker tag "${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ steps.bump-version.outputs.current_version }}" "${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest"
184+
docker push "${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ steps.bump-version.outputs.current_version }}"
173185
docker push "${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest"
186+
187+
- name: Upload Next Tag Version
188+
uses: actions/upload-artifact@v3
189+
with:
190+
name: tag-version
191+
path: tag-version.txt
174192

175193
dev-deploy-to-az-container-apps:
176194
runs-on: ubuntu-latest
@@ -201,10 +219,17 @@ jobs:
201219
ARM_SUBSCRIPTION_ID: ${{ secrets.AZ_SUBSCRIPTION_ID }}
202220
ARM_TENANT_ID: ${{ secrets.AZ_TENANT_ID }}
203221
ARM_USE_OIDC: true
222+
223+
- name: Download Next Tag Version
224+
uses: actions/download-artifact@v3
225+
with:
226+
name: tag-version
204227

205228
- name: Terraform Apply
206229
run: |
207-
terraform apply --auto-approve -var-file=./dev/terraform.tfvars -var="registry_username=${{ secrets.DOCKERHUB_USERNAME }}" -var="registry_password=${{ secrets.DOCKERHUB_TOKEN }}" -var="image=${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ github.run_id }}"
230+
cat tag-version.txt
231+
TAG_VERSION=$(cat tag-version.txt)
232+
terraform apply --auto-approve -var-file=./dev/terraform.tfvars -var="registry_username=${{ secrets.DOCKERHUB_USERNAME }}" -var="registry_password=${{ secrets.DOCKERHUB_TOKEN }}" -var="image=${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:$TAG_VERSION"
208233
env:
209234
ARM_CLIENT_ID: ${{ secrets.AZ_CLIENT_ID }}
210235
ARM_SUBSCRIPTION_ID: ${{ secrets.AZ_SUBSCRIPTION_ID }}
@@ -225,8 +250,13 @@ jobs:
225250
needs:
226251
- placeholder-dev-e2e-test
227252
steps:
253+
- name: Download Next Tag Version
254+
uses: actions/download-artifact@v3
255+
with:
256+
name: tag-version
228257
- name: Placeholder pre-deploy-to-az-container-apps
229258
run: |
259+
cat tag-version.txt
230260
echo "Implement pre-deploy-to-az-container-apps and execute them here in the pipeline"
231261
232262
placeholder-pre-e2e-test:
@@ -272,8 +302,13 @@ jobs:
272302
needs:
273303
- placeholder-change-management-entry
274304
steps:
305+
- name: Download Next Tag Version
306+
uses: actions/download-artifact@v3
307+
with:
308+
name: tag-version
275309
- name: Placeholder pre-deploy-to-az-container-apps
276310
run: |
311+
cat tag-version.txt
277312
echo "Implement pre-deploy-to-az-container-apps and execute them here in the pipeline"
278313
279314
placeholder-prod-deploy-to-az-container-apps:
@@ -290,10 +325,24 @@ jobs:
290325
needs:
291326
- placeholder-prod-deploy-to-az-container-apps
292327
steps:
293-
- name: Placeholder pre-deploy-to-az-container-apps
328+
- name: Download Next Tag Version
329+
uses: actions/download-artifact@v3
330+
with:
331+
name: tag-version
332+
- name: Placeholder prod-deploy-to-az-container-apps
294333
run: |
295-
echo "Implement pre-deploy-to-az-container-apps and execute them here in the pipeline"
334+
cat tag-version.txt
335+
echo "Implement prod-deploy-to-az-container-apps and execute them here in the pipeline"
296336
337+
create-release:
338+
needs:
339+
- placeholder-prod-deploy-to-az-container-apps
340+
if: github.ref == 'refs/heads/main'
341+
uses: armakuni/github-actions/.github/workflows/tag-and-release.yml@v0.14.10
342+
secrets: inherit
343+
with:
344+
download-artifacts: true
345+
297346
placeholder-prod-pen-test:
298347
runs-on: ubuntu-latest
299348
needs:

0 commit comments

Comments
 (0)