Skip to content

Commit 1b9353f

Browse files
committed
refactor: workflow restructure
1 parent a5e0eb5 commit 1b9353f

File tree

5 files changed

+131
-81
lines changed

5 files changed

+131
-81
lines changed

.github/workflows/az_acr_push.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ jobs:
4040
file: 'Dockerfile'
4141
tags: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:${{ matrix.platform}}
4242
push: true
43-
build-args: platform=linux/${{ matrix.platform}}
43+
build-args: |
44+
platform=linux/${{ matrix.platform}}
45+
label=dockerfile-path=https://github.com/${{ github.repository }}/blob/${{ github.sha }}/Dockerfile
4446
4547
- name: Build & Push ${{ github.event.repository.name }}:${{ matrix.platform}}-${{ github.ref_name }}
4648
if: ${{ github.ref != github.repository.default_branch }}
@@ -51,7 +53,9 @@ jobs:
5153
tags: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:${{ matrix.platform}}-${{ github.ref_name }}
5254
cache-from: type=gha
5355
cache-to: type=gha,mode=max
54-
build-args: platform=linux/${{ matrix.platform}}
56+
build-args: |
57+
platform=linux/${{ matrix.platform}}
58+
label=dockerfile-path=https://github.com/${{ github.repository }}/blob/${{ github.sha }}/Dockerfile
5559
5660
- name: Build & Push ${{ github.event.repository.name }}:latest
5761
uses: docker/build-push-action@v5
@@ -62,7 +66,9 @@ jobs:
6266
file: 'Dockerfile'
6367
tags: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:latest
6468
push: true
65-
build-args: platform=linux/amd64
69+
build-args: |
70+
platform=linux/amd64
71+
label=dockerfile-path=https://github.com/${{ github.repository }}/blob/${{ github.sha }}/Dockerfile
6672
6773
- name: Build & Push ${{ github.event.repository.name }}:${{ matrix.platform}}-gpu
6874
if: ${{ github.ref == github.repository.default_branch && hashFiles('gpu.Dockerflie') != '' }}
@@ -73,4 +79,6 @@ jobs:
7379
tags: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:${{ matrix.platform}}-gpu
7480
cache-from: type=gha
7581
cache-to: type=gha,mode=max
76-
build-args: platform=linux/${{ matrix.platform}}
82+
build-args: |
83+
platform=linux/${{ matrix.platform}}
84+
label=dockerfile-path=https://github.com/${{ github.repository }}/blob/${{ github.sha }}/gpu.Dockerfile

.github/workflows/az_acr_release.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: 'ACR: Docker Push Release'
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
az-acr-push:
8+
name: "Docker: Build & Push"
9+
runs-on: ubuntu-latest
10+
environment: ${{ github.event_name == 'release' && 'prod' || 'dev' }}
11+
env:
12+
DOCKERFILE: ${{ vars.DOCKERFILE }}
13+
AZURE_CONTAINER_REGISTRY: ${{ vars.AZURE_CONTAINER_REGISTRY }}
14+
ACR_LOGIN_USERNAME: ${{ secrets.ACR_LOGIN_USERNAME }}
15+
ACR_LOGIN_PASSWORD: ${{ secrets.ACR_LOGIN_PASSWORD }}
16+
IMAGE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || 'amd64' }}
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v3
22+
- name: Log into registry
23+
uses: docker/login-action@v3
24+
with:
25+
registry: "${{ env.AZURE_CONTAINER_REGISTRY }}"
26+
username: "${{ env.ACR_LOGIN_USERNAME }}"
27+
password: "${{ env.ACR_LOGIN_PASSWORD }}"
28+
29+
- name: Build & Push ${{ github.event.repository.name }}:${{ env.IMAGE_TAG }}
30+
uses: docker/build-push-action@v5
31+
with:
32+
cache-from: type=gha
33+
cache-to: type=gha,mode=max
34+
file: ${{ env.DOCKERFILE }}
35+
tags: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:${{ env.IMAGE_TAG }}
36+
push: true
37+
build-args: |
38+
platform=linux/amd64
39+
label=dockerfile-path=https://github.com/${{ github.repository }}/blob/${{ github.sha }}/${{ env.DOCKERFILE }}
40+
41+
- name: Build & Push ${{ github.event.repository.name }}:latest
42+
uses: docker/build-push-action@v5
43+
with:
44+
cache-from: type=gha
45+
cache-to: type=gha,mode=max
46+
file: ${{ env.DOCKERFILE }}
47+
tags: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:latest
48+
push: true
49+
build-args: |
50+
platform=linux/amd64
51+
label=dockerfile-path=https://github.com/${{ github.repository }}/blob/${{ github.sha }}/${{ env.DOCKERFILE }}

.github/workflows/gh_release.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: 'GitHub: Release'
2+
3+
on:
4+
workflow_call:
5+
6+
# Special permissions required for OIDC authentication
7+
permissions:
8+
id-token: write
9+
contents: read
10+
actions: read
11+
12+
jobs:
13+
gh-release-publish:
14+
name: 'GitHub: Publish Release'
15+
runs-on: ubuntu-latest
16+
if: github.event_name == 'release' && success()
17+
env:
18+
GH_TOKEN: ${{ secrets.TOKEN_GITHUB }}
19+
steps:
20+
- name: Publish Release
21+
run: |
22+
gh release edit ${{ github.event.release.tag_name }} \
23+
--prerelease=false \
24+
--draft=false \
25+
--latest \
26+
--repo ${{ github.repository }}
27+
28+
echo "::notice::Release Published"
29+
30+
gh-release-delete:
31+
name: 'GitHub: Delete Prerelease'
32+
runs-on: ubuntu-latest
33+
if: github.event_name == 'release' && failure() || cancelled()
34+
env:
35+
GH_TOKEN: ${{ secrets.TOKEN_GITHUB }}
36+
steps:
37+
- name: Delete Prerelease
38+
run: |
39+
gh release delete ${{ github.event.release.tag_name }} \
40+
--cleanup-tag \
41+
--yes \
42+
--repo ${{ github.repository }}
43+
44+
echo "::error::Prerelease and Tag Deleted"

.github/workflows/k8s_deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
KUBERNETES_MANIFEST_PATH: "${{ vars.KUBERNETES_MANIFEST_PATH }}"
3030
AZURE_RESOURCE_GROUP: "${{ vars.AZURE_RESOURCE_GROUP }}"
3131
AZURE_CONTAINER_REGISTRY: "${{ vars.AZURE_CONTAINER_REGISTRY }}"
32-
IMAGE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || 'amd64' }}
32+
IMAGE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || 'latest' }}
3333
steps:
3434
# Checkout the repository to the GitHub Actions runner
3535
- name: Checkout
@@ -82,7 +82,7 @@ jobs:
8282
with:
8383
namespace: ${{ env.KUBERNETES_NAMESPACE }}
8484
manifests: apply.yml
85-
pull-images: true
85+
pull-images: false
8686
images: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:${{ env.IMAGE_TAG }}
8787
strategy: canary
8888
action: deploy

.github/workflows/k8s_release.yml

Lines changed: 22 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -10,86 +10,33 @@ permissions:
1010
actions: read
1111

1212
jobs:
13-
az-acr-push:
14-
name: "Docker: Build & Push"
15-
runs-on: ubuntu-latest
16-
environment: ${{ github.event_name == 'release' && 'prod' || 'dev' }}
17-
env:
18-
DOCKERFILE: ${{ vars.DOCKERFILE }}
19-
AZURE_CONTAINER_REGISTRY: ${{ vars.AZURE_CONTAINER_REGISTRY }}
20-
ACR_LOGIN_USERNAME: ${{ secrets.ACR_LOGIN_USERNAME }}
21-
ACR_LOGIN_PASSWORD: ${{ secrets.ACR_LOGIN_PASSWORD }}
22-
IMAGE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || 'amd64' }}
23-
steps:
24-
- name: Checkout repository
25-
uses: actions/checkout@v4
26-
- name: Set up Docker Buildx
27-
uses: docker/setup-buildx-action@v3
28-
- name: Log into registry
29-
uses: docker/login-action@v3
30-
with:
31-
registry: "${{ env.AZURE_CONTAINER_REGISTRY }}"
32-
username: "${{ env.ACR_LOGIN_USERNAME }}"
33-
password: "${{ env.ACR_LOGIN_PASSWORD }}"
34-
35-
- name: Build & Push ${{ github.event.repository.name }}:${{ env.IMAGE_TAG }}
36-
uses: docker/build-push-action@v5
37-
with:
38-
cache-from: type=gha
39-
cache-to: type=gha,mode=max
40-
file: ${{ env.DOCKERFILE }}
41-
tags: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:${{ env.IMAGE_TAG }}
42-
push: true
43-
build-args: platform=linux/amd64
13+
call-gh-validate-release:
14+
if: github.event_name == 'release'
15+
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/gh_validate_release.yml@dev
16+
secrets: inherit
4417

45-
- name: Build & Push ${{ github.event.repository.name }}:latest
46-
uses: docker/build-push-action@v5
47-
with:
48-
cache-from: type=gha
49-
cache-to: type=gha,mode=max
50-
file: ${{ env.DOCKERFILE }}
51-
tags: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:latest
52-
push: true
53-
build-args: platform=linux/amd64
18+
call-az-acr-release:
19+
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/az_acr_release.yml@dev
20+
needs: [call-gh-validate-release]
21+
if: always() && !failure()
22+
secrets: inherit
5423

55-
k8-deploy:
24+
call-k8-deploy:
5625
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/k8s_deploy.yml@dev
57-
needs: [az-acr-push]
26+
needs: [call-az-acr-release]
27+
if: always() && !failure()
5828
secrets: inherit
5929
with:
6030
environment: ${{ github.event_name == 'release' && 'prod' || 'dev' }}
6131

62-
gh-release-publish:
63-
name: 'GitHub: Publish Release'
64-
runs-on: ubuntu-latest
65-
needs: [k8-deploy]
66-
if: github.event_name == 'release' && success()
67-
env:
68-
GH_TOKEN: ${{ secrets.TOKEN_GITHUB }}
69-
steps:
70-
- name: Publish Release
71-
run: |
72-
gh release edit ${{ github.event.release.tag_name }} \
73-
--prerelease=false \
74-
--draft=false \
75-
--latest \
76-
--repo ${{ github.repository }}
77-
78-
echo "::notice::Release Published"
32+
call-gh-release:
33+
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/gh_release.yml@dev
34+
needs: [call-k8-deploy]
35+
if: always() && github.event_name == 'release'
36+
secrets: inherit
7937

80-
gh-release-delete:
81-
name: 'GitHub: Delete Prerelease'
82-
runs-on: ubuntu-latest
83-
needs: [k8-deploy]
84-
if: github.event_name == 'release' && failure() || cancelled()
85-
env:
86-
GH_TOKEN: ${{ secrets.TOKEN_GITHUB }}
87-
steps:
88-
- name: Delete Prerelease
89-
run: |
90-
gh release delete ${{ github.event.release.tag_name }} \
91-
--cleanup-tag \
92-
--yes \
93-
--repo ${{ github.repository }}
94-
95-
echo "::error::Prerelease and Tag Deleted"
38+
call-gh-delete-branch:
39+
needs: [call-k8-deploy]
40+
if: github.event_name == 'pull_request' && github.event.pull_request.merged == 'true' && !failure()
41+
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/gh_delete_branch.yml@dev
42+
secrets: inherit

0 commit comments

Comments
 (0)