Skip to content

Commit 3c17933

Browse files
committed
ci: restructure workflows
1 parent 0c07c95 commit 3c17933

File tree

4 files changed

+88
-61
lines changed

4 files changed

+88
-61
lines changed

.github/workflows/az_acr_delete.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: 'ACR: Delete Docker Image'
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
image_tag:
7+
description: 'Image Tag'
8+
required: true
9+
type: string
10+
11+
jobs:
12+
az-acr-delete:
13+
name: "ACR: Delete Test Image"
14+
runs-on: ubuntu-latest
15+
environment: dev
16+
env:
17+
AZURE_CONTAINER_REGISTRY: ${{ vars.AZURE_CONTAINER_REGISTRY }}
18+
ACR_LOGIN_USERNAME: ${{ secrets.ACR_LOGIN_USERNAME }}
19+
ACR_LOGIN_PASSWORD: ${{ secrets.ACR_LOGIN_PASSWORD }}
20+
steps:
21+
- name: Azure Cloud Login
22+
uses: Azure/login@v2
23+
with:
24+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
25+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
26+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
27+
28+
- name: Delete Test Container Image
29+
uses: azure/cli@v2
30+
with:
31+
inlineScript: |
32+
az acr repository delete \
33+
--name ${{ env.AZURE_CONTAINER_REGISTRY }} \
34+
--image ${{ github.event.repository.name }}:${{ inputs.image_tag }} \
35+
--yes

.github/workflows/az_acr_test.yml

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

.github/workflows/k8s_test.yml

Lines changed: 11 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,14 @@ permissions:
1515
actions: read
1616

1717
jobs:
18-
az-acr-push:
19-
name: "Docker: Build & Push (Test)"
20-
runs-on: ubuntu-latest
21-
environment: dev
22-
env:
23-
AZURE_CONTAINER_REGISTRY: ${{ vars.AZURE_CONTAINER_REGISTRY }}
24-
ACR_LOGIN_USERNAME: ${{ secrets.ACR_LOGIN_USERNAME }}
25-
ACR_LOGIN_PASSWORD: ${{ secrets.ACR_LOGIN_PASSWORD }}
26-
steps:
27-
- name: Checkout repository
28-
uses: actions/checkout@v4
29-
- name: Set up Docker Buildx
30-
uses: docker/setup-buildx-action@v3
31-
- name: Log into registry
32-
uses: docker/login-action@v3
33-
with:
34-
registry: "${{ env.AZURE_CONTAINER_REGISTRY }}"
35-
username: "${{ env.ACR_LOGIN_USERNAME }}"
36-
password: "${{ env.ACR_LOGIN_PASSWORD }}"
37-
38-
- name: Build & Push ${{ github.event.repository.name }}:test-${{ github.head_ref }}
39-
uses: docker/build-push-action@v5
40-
with:
41-
cache-from: type=gha
42-
cache-to: type=gha,mode=max
43-
file: 'dev.Dockerfile'
44-
tags: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:test-${{ github.head_ref }}
45-
push: true
46-
build-args: platform=linux/amd64
18+
call-az-acr-push:
19+
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/az_acr_test.yml@dev
20+
secrets: inherit
4721

4822
k8-test:
4923
name: 'K8: Test'
5024
runs-on: ubuntu-latest
51-
needs: [az-acr-push]
25+
needs: [call-az-acr-push]
5226
environment: dev
5327
env:
5428
KUBELOGIN_VERSION: "v0.0.25"
@@ -95,32 +69,13 @@ jobs:
9569
bash cicd-deployment-scripts/k8s/test.sh \
9670
-n ${{ env.KUBERNETES_NAMESPACE }} \
9771
-d ${{ github.event.repository.name }} \
98-
-h ${{ github.head_ref }} \
72+
-t test-${{ github.head_ref }} \
9973
-r ${{ env.AZURE_CONTAINER_REGISTRY }} \
100-
-t "${{ inputs.test_cmd }}"
74+
-c "${{ inputs.test_cmd }}"
10175
102-
az-acr-delete:
103-
name: "ACR: Delete Test Image"
104-
runs-on: ubuntu-latest
76+
call-az-acr-delete:
77+
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/az_acr_delete.yml@dev
10578
needs: [k8-test]
106-
environment: dev
107-
env:
108-
AZURE_CONTAINER_REGISTRY: ${{ vars.AZURE_CONTAINER_REGISTRY }}
109-
ACR_LOGIN_USERNAME: ${{ secrets.ACR_LOGIN_USERNAME }}
110-
ACR_LOGIN_PASSWORD: ${{ secrets.ACR_LOGIN_PASSWORD }}
111-
steps:
112-
- name: Azure Cloud Login
113-
uses: Azure/login@v2
114-
with:
115-
client-id: ${{ secrets.AZURE_CLIENT_ID }}
116-
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
117-
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
118-
119-
- name: Delete Test Container Image
120-
uses: azure/cli@v2
121-
with:
122-
inlineScript: |
123-
az acr repository delete \
124-
--name ${{ env.AZURE_CONTAINER_REGISTRY }} \
125-
--image ${{ github.event.repository.name }}:test-${{ github.head_ref }} \
126-
--yes
79+
secrets: inherit
80+
with:
81+
image_tag: "test-${{ github.head_ref }}"

k8s/test.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -e
33

44
KUBERNETES_NAMESPACE=""
55
KUBERNETES_DEPLOYMENT_NAME=""
6-
GITHUB_HEAD_REF=""
6+
TEST_IMAGE_TAG=""
77
AZURE_CONTAINER_REGISTRY=""
88
TEST_CMD=""
99

@@ -12,9 +12,9 @@ do
1212
case "${flag}" in
1313
n) KUBERNETES_NAMESPACE=${OPTARG};;
1414
d) KUBERNETES_DEPLOYMENT_NAME=${OPTARG};;
15-
h) GITHUB_HEAD_REF=${OPTARG};;
15+
t) TEST_IMAGE_TAG=${OPTARG};;
1616
r) AZURE_CONTAINER_REGISTRY=${OPTARG};;
17-
t) TEST_CMD=${OPTARG};;
17+
c) TEST_CMD=${OPTARG};;
1818
esac
1919
done
2020

@@ -25,8 +25,8 @@ KUBERNETES_POD_EXISTING_IMAGE=$(kubectl get pod --output json \
2525
--selector app=${KUBERNETES_DEPLOYMENT_NAME} \
2626
| jq -r '.items[0] | .spec.containers[0].image')
2727

28-
kubectl set image deployment/${KUBERNETES_DEPLOYMENT_NAME} ${KUBERNETES_DEPLOYMENT_NAME}=${AZURE_CONTAINER_REGISTRY}/${KUBERNETES_DEPLOYMENT_NAME}:test-${GITHUB_HEAD_REF}
29-
echo "::warning::using ${AZURE_CONTAINER_REGISTRY}/${KUBERNETES_DEPLOYMENT_NAME}:test-${GITHUB_HEAD_REF}"
28+
kubectl set image deployment/${KUBERNETES_DEPLOYMENT_NAME} ${KUBERNETES_DEPLOYMENT_NAME}=${AZURE_CONTAINER_REGISTRY}/${KUBERNETES_DEPLOYMENT_NAME}:${TEST_IMAGE_TAG}
29+
echo "::warning::using ${AZURE_CONTAINER_REGISTRY}/${KUBERNETES_DEPLOYMENT_NAME}:${TEST_IMAGE_TAG}"
3030

3131
kubectl rollout status deployment ${KUBERNETES_DEPLOYMENT_NAME}
3232

0 commit comments

Comments
 (0)