Skip to content

Commit c376b3a

Browse files
committed
feat(ci): deployment restart workflow
perf: use apply.sh
1 parent c524cd2 commit c376b3a

File tree

6 files changed

+97
-19
lines changed

6 files changed

+97
-19
lines changed

.github/workflows/k8_cluster_apply.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,7 @@ jobs:
6161
6262
- name: Apply Kustomization
6363
shell: bash
64-
run: kubectl apply -k ${{ env.KUBERNETES_MANIFEST_PATH }}
65-
66-
# Deploys application based on given manifest file
67-
# - name: Deploys application
68-
# uses: Azure/k8s-deploy@v4
69-
# with:
70-
# action: deploy
71-
# manifests: ${{ env.KUBERNETES_MANIFEST_PATH }}
72-
# namespace: ${{ env.KUBERNETES_NAMESPACE }}
64+
run: |
65+
git clone https://github.com/code-kern-ai/cicd-deployment-scripts.git
66+
bash cicd-deployment-scripts/k8-cluster/apply.sh -n ${{ env.KUBERNETES_NAMESPACE }} -p ${{ env.KUBERNETES_MANIFEST_PATH }}
67+

.github/workflows/k8_cluster_destroy.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,3 @@ jobs:
5353
run: |
5454
git clone https://github.com/code-kern-ai/cicd-deployment-scripts.git
5555
bash cicd-deployment-scripts/k8-cluster/destroy.sh -n ${{ env.KUBERNETES_NAMESPACE }}
56-
57-
# Deploys application based on given manifest file
58-
# - name: Deploys application
59-
# uses: Azure/k8s-deploy@v4
60-
# with:
61-
# action: deploy
62-
# manifests: ${{ env.KUBERNETES_MANIFEST_PATH }}
63-
# namespace: ${{ env.KUBERNETES_NAMESPACE }}
64-
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: 'Kubernetes Restart'
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+
k8-cluster-restart:
14+
name: 'K8: Restart Deployments'
15+
runs-on: ubuntu-latest
16+
environment: dev
17+
env:
18+
KUBERNETES_NAMESPACE: "${{ vars.KUBERNETES_NAMESPACE }}"
19+
KUBERNETES_CLUSTER_NAME: "${{ vars.KUBERNETES_CLUSTER_NAME }}"
20+
KUBERNETES_MANIFEST_PATH: "${{ vars.KUBERNETES_MANIFEST_PATH }}"
21+
AZURE_RESOURCE_GROUP: "${{ vars.AZURE_RESOURCE_GROUP }}"
22+
steps:
23+
# Checkout the repository to the GitHub Actions runner
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: GitHub Configuration
28+
run: git config --global url."https://oauth2:${{ secrets.TOKEN_GITHUB }}@github.com".insteadOf https://github.com
29+
30+
# Install the latest version of Kubernetes CLI and configure the Kubernetes CLI configuration file with a Kubernetes Cloud user API token
31+
- name: Azure Login
32+
uses: Azure/login@v2
33+
with:
34+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
35+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
36+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
37+
38+
# Use kubelogin to configure your kubeconfig for Azure auth
39+
- name: Set up kubelogin for non-interactive login
40+
uses: azure/use-kubelogin@v1
41+
with:
42+
kubelogin-version: 'v0.0.25'
43+
44+
- uses: azure/aks-set-context@v3
45+
with:
46+
resource-group: ${{ env.AZURE_RESOURCE_GROUP }}
47+
cluster-name: ${{ env.KUBERNETES_CLUSTER_NAME }}
48+
admin: 'false'
49+
use-kubelogin: 'true'
50+
51+
- name: Restart Deployments
52+
shell: bash
53+
run: |
54+
git clone https://github.com/code-kern-ai/cicd-deployment-scripts.git
55+
bash cicd-deployment-scripts/k8-cluster/restart.sh -n ${{ env.KUBERNETES_NAMESPACE }}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
k8-cluster/apply.sh

k8-cluster/apply.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# !/bin/bash
2+
set -e
3+
4+
KUBERNETES_NAMESPACE=""
5+
KUBERNETES_MANIFEST_PATH=""
6+
7+
while getopts n:p: flag
8+
do
9+
case "${flag}" in
10+
n) KUBERNETES_NAMESPACE=${OPTARG};;
11+
p) KUBERNETES_MANIFEST_PATH=${OPTARG};;
12+
esac
13+
done
14+
15+
kubectl config set-context --current --namespace=$KUBERNETES_NAMESPACE
16+
kubectl apply -k $KUBERNETES_MANIFEST_PATH

k8-cluster/restart.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# !/bin/bash
2+
set -e
3+
4+
KUBERNETES_NAMESPACE=""
5+
6+
while getopts n: flag
7+
do
8+
case "${flag}" in
9+
n) KUBERNETES_NAMESPACE=${OPTARG};;
10+
esac
11+
done
12+
13+
kubectl config set-context --current --namespace=$KUBERNETES_NAMESPACE
14+
KUBERNETES_DEPLOYMENTS=$(kubectl get deployment --output json \
15+
| jq -r '.items[] | select(.metadata.name as $name
16+
| ["caddy", "docker"]
17+
| index($name) | not)
18+
| .metadata.name')
19+
20+
for deploy in $KUBERNETES_DEPLOYMENTS; do
21+
kubectl rollout restart deployment $deploy
22+
done

0 commit comments

Comments
 (0)