Skip to content

Commit 293f4b1

Browse files
committed
ci(perf): private _k8s_deploy
1 parent 0d52855 commit 293f4b1

File tree

2 files changed

+106
-84
lines changed

2 files changed

+106
-84
lines changed

.github/workflows/_k8s_deploy.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: 'K8: Deploy'
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
environment:
7+
required: true
8+
type: string
9+
10+
11+
# Special permissions required for OIDC authentication
12+
permissions:
13+
id-token: write
14+
contents: read
15+
actions: read
16+
17+
jobs:
18+
k8-deploy:
19+
name: 'K8: Deploy'
20+
runs-on: ubuntu-latest
21+
environment: ${{ inputs.environment }}
22+
env:
23+
KUBELOGIN_VERSION: "v0.0.25"
24+
KUBERNETES_CLUSTER_REPO_NAME: "${{ vars.KUBERNETES_CLUSTER_REPO_NAME }}"
25+
KUBERNETES_CLUSTER_NAME: "${{ vars.KUBERNETES_CLUSTER_NAME }}"
26+
KUBERNETES_NAMESPACE: "${{ vars.KUBERNETES_NAMESPACE }}"
27+
KUBERNETES_MANIFEST_PATH: "${{ vars.KUBERNETES_MANIFEST_PATH }}"
28+
AZURE_RESOURCE_GROUP: "${{ vars.AZURE_RESOURCE_GROUP }}"
29+
AZURE_CONTAINER_REGISTRY: "${{ vars.AZURE_CONTAINER_REGISTRY }}"
30+
IMAGE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || 'amd64' }}
31+
steps:
32+
# Checkout the repository to the GitHub Actions runner
33+
- name: Checkout
34+
uses: actions/checkout@v4
35+
with:
36+
token: ${{ secrets.TOKEN_GITHUB }}
37+
repository: ${{ github.repository_owner }}/${{ env.KUBERNETES_CLUSTER_REPO_NAME }}
38+
ref: refs/heads/dev
39+
40+
# Install the latest version of Kubernetes CLI and configure the Kubernetes CLI configuration file with a Kubernetes Cloud user API token
41+
- name: Azure Cloud Login
42+
uses: Azure/login@v2
43+
with:
44+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
45+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
46+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
47+
48+
# Use kubelogin to configure your kubeconfig for Azure auth
49+
- name: Set up kubelogin for non-interactive login
50+
uses: azure/use-kubelogin@v1
51+
with:
52+
kubelogin-version: ${{ env.KUBELOGIN_VERSION }}
53+
54+
- uses: azure/aks-set-context@v3
55+
with:
56+
resource-group: ${{ env.AZURE_RESOURCE_GROUP }}
57+
cluster-name: ${{ env.KUBERNETES_CLUSTER_NAME }}
58+
admin: 'false'
59+
use-kubelogin: 'true'
60+
61+
- name: Generate Kustomization
62+
shell: bash
63+
env:
64+
KUBECTL_EXTERNAL_DIFF: "colordiff -N -u"
65+
run: |
66+
kubectl kustomize ${{ env.KUBERNETES_MANIFEST_PATH }} --output apply.yml
67+
kubectl diff --filename apply.yml || true
68+
69+
- name: Generate Deployment
70+
uses: Azure/k8s-deploy@v5
71+
timeout-minutes: 10
72+
with:
73+
namespace: ${{ env.KUBERNETES_NAMESPACE }}
74+
manifests: apply.yml
75+
pull-images: false
76+
images: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:${{ env.IMAGE_TAG }}
77+
strategy: canary
78+
action: deploy
79+
percentage: 20
80+
81+
- name: Promote Deployment
82+
uses: Azure/k8s-deploy@v5
83+
if: success()
84+
with:
85+
namespace: ${{ env.KUBERNETES_NAMESPACE }}
86+
manifests: apply.yml
87+
pull-images: false
88+
images: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:${{ env.IMAGE_TAG }}
89+
strategy: canary
90+
action: promote
91+
92+
- name: Reject Deployment
93+
uses: Azure/k8s-deploy@v5
94+
if: failure() || cancelled()
95+
with:
96+
namespace: ${{ env.KUBERNETES_NAMESPACE }}
97+
manifests: apply.yml
98+
pull-images: false
99+
images: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:${{ env.IMAGE_TAG }}
100+
strategy: canary
101+
action: reject

.github/workflows/k8s_deploy.yml

Lines changed: 5 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -53,91 +53,12 @@ jobs:
5353
build-args: platform=linux/amd64
5454

5555
k8-deploy:
56-
name: 'K8: Deploy'
57-
runs-on: ubuntu-latest
56+
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/_k8s_deploy.yml@dev
5857
needs: [az-acr-push]
59-
environment: ${{ github.event_name == 'release' && 'prod' || 'dev' }}
60-
env:
61-
KUBELOGIN_VERSION: "v0.0.25"
62-
KUBERNETES_CLUSTER_REPO_NAME: "${{ vars.KUBERNETES_CLUSTER_REPO_NAME }}"
63-
KUBERNETES_CLUSTER_NAME: "${{ vars.KUBERNETES_CLUSTER_NAME }}"
64-
KUBERNETES_NAMESPACE: "${{ vars.KUBERNETES_NAMESPACE }}"
65-
KUBERNETES_MANIFEST_PATH: "${{ vars.KUBERNETES_MANIFEST_PATH }}"
66-
AZURE_RESOURCE_GROUP: "${{ vars.AZURE_RESOURCE_GROUP }}"
67-
AZURE_CONTAINER_REGISTRY: "${{ vars.AZURE_CONTAINER_REGISTRY }}"
68-
IMAGE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || 'amd64' }}
69-
steps:
70-
# Checkout the repository to the GitHub Actions runner
71-
- name: Checkout
72-
uses: actions/checkout@v4
73-
with:
74-
token: ${{ secrets.TOKEN_GITHUB }}
75-
repository: ${{ github.repository_owner }}/${{ env.KUBERNETES_CLUSTER_REPO_NAME }}
76-
ref: refs/heads/dev
77-
78-
# Install the latest version of Kubernetes CLI and configure the Kubernetes CLI configuration file with a Kubernetes Cloud user API token
79-
- name: Azure Cloud Login
80-
uses: Azure/login@v2
81-
with:
82-
client-id: ${{ secrets.AZURE_CLIENT_ID }}
83-
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
84-
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
85-
86-
# Use kubelogin to configure your kubeconfig for Azure auth
87-
- name: Set up kubelogin for non-interactive login
88-
uses: azure/use-kubelogin@v1
89-
with:
90-
kubelogin-version: ${{ env.KUBELOGIN_VERSION }}
91-
92-
- uses: azure/aks-set-context@v3
93-
with:
94-
resource-group: ${{ env.AZURE_RESOURCE_GROUP }}
95-
cluster-name: ${{ env.KUBERNETES_CLUSTER_NAME }}
96-
admin: 'false'
97-
use-kubelogin: 'true'
98-
99-
- name: Generate Kustomization
100-
shell: bash
101-
env:
102-
KUBECTL_EXTERNAL_DIFF: "colordiff -N -u"
103-
run: |
104-
kubectl kustomize ${{ env.KUBERNETES_MANIFEST_PATH }} --output apply.yml
105-
kubectl diff --filename apply.yml || true
106-
107-
- name: Generate Deployment
108-
uses: Azure/k8s-deploy@v5
109-
timeout-minutes: 10
110-
with:
111-
namespace: ${{ env.KUBERNETES_NAMESPACE }}
112-
manifests: apply.yml
113-
pull-images: false
114-
images: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:${{ env.IMAGE_TAG }}
115-
strategy: canary
116-
action: deploy
117-
percentage: 20
118-
119-
- name: Promote Deployment
120-
uses: Azure/k8s-deploy@v5
121-
if: success()
122-
with:
123-
namespace: ${{ env.KUBERNETES_NAMESPACE }}
124-
manifests: apply.yml
125-
pull-images: false
126-
images: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:${{ env.IMAGE_TAG }}
127-
strategy: canary
128-
action: promote
129-
130-
- name: Reject Deployment
131-
uses: Azure/k8s-deploy@v5
132-
if: failure() || cancelled()
133-
with:
134-
namespace: ${{ env.KUBERNETES_NAMESPACE }}
135-
manifests: apply.yml
136-
pull-images: false
137-
images: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:${{ env.IMAGE_TAG }}
138-
strategy: canary
139-
action: reject
140-
58+
secrets: inherit
59+
with:
60+
environment: ${{ github.event_name == 'release' && 'prod' || 'dev' }}
61+
14162
gh-release-publish:
14263
name: 'GitHub: Publish Release'
14364
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)