-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (52 loc) · 2.53 KB
/
aks.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: Update AKS infrastucture
on:
push:
branches:
- main
paths:
- 'deployement/aks-deployment/*'
env:
ARM_USE_MSI: true
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
ORG_NAME: ${{ secrets.ORG_NAME }}
REPO_NAME: ${{ secrets.REPO_NAME }}
jobs:
build-and-deploy-aks:
runs-on: self-hosted
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Azure login
uses: azure/login@v1
with:
auth-type: IDENTITY
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Terraform
id: terraform
working-directory: deployement/aks-deployment
run: |
echo -n ${{ secrets.REGISTRY_ID }} > ./registry_id.txt
terraform init
terraform plan -out aks.tfplan
terraform apply aks.tfplan
declare -A keys
keys["KUBERNETES_CLUSTER_NAME"]=$(terraform output -raw kubernetes_cluster_name)
keys["AKS_RESOURCE_GROUP_NAME"]=$(terraform output -raw resource_group_name)
keys["AKS_RESOURCE_GROUP_LOCATION"]=$(terraform output -raw resource_group_location)
public_ip_resource_group_name=MC_${keys["AKS_RESOURCE_GROUP_NAME"]}_${keys["KUBERNETES_CLUSTER_NAME"]}_${keys["AKS_RESOURCE_GROUP_LOCATION"]}
az aks get-credentials --resource-group ${keys["AKS_RESOURCE_GROUP_NAME"]} --name ${keys["KUBERNETES_CLUSTER_NAME"]}
kubectl get nodes
cd ..
public_key_info=$(curl -H "Authorization: token $ACCESS_TOKEN" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/$ORG_NAME/$REPO_NAME/actions/secrets/public-key)
public_key_value=$(echo "$public_key_info" | jq -r '.key')
public_key_id=$(echo "$public_key_info" | jq -r '.key_id')
for credential in "${!keys[@]}"; do
keys[$credential]=$(python3 encrypt-secret.py ${keys[$credential]} $public_key_value)
echo '{"encrypted_value":"'${keys[$credential]}'","key_id":"'$public_key_id'"}' > body.json
curl -L -X PUT -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $ACCESS_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/$ORG_NAME/$REPO_NAME/actions/secrets/$credential -d @body.json
done