-
Notifications
You must be signed in to change notification settings - Fork 7
167 lines (141 loc) · 5.46 KB
/
workflow.yaml
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: 'Terraform CI'
on:
pull_request:
release:
types: [published]
workflow_dispatch:
inputs:
dist:
required: true
description: Distribution type
default: dev
concurrency: ci
env:
RG_NAME: weka-ci
PREFIX: ci
CLUSTER_NAME: wekacluster
GET_WEKA_IO_TOKEN: ${{ secrets.GET_WEKA_IO_TOKEN }}
SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
CLIENT_ID: ${{ secrets.CLIENT_ID }}
TENANT_ID: ${{ secrets.TENANT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
INITIAL_CAPACITY: 6
INITIALIZATION_TIMEOUT: 30
NEW_CAPACITY: 7
SCALE_UP_TIMEOUT: 20
SCALE_DOWN_TIMEOUT: 20
jobs:
function-app-dist:
name: Function app code distribution
runs-on: ubuntu-latest
env:
DIST: ${{ github.event_name == 'release' && 'release' || 'dev' }}
defaults:
run:
shell: bash
working-directory: ./function-app/distribution
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
cache-dependency-path: function-app/code/go.mod
- name: Install Task
uses: arduino/setup-task@v1
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Authenticate to Azure Cloud
uses: azure/login@v1
with:
# see https://github.com/Azure/login#configure-a-service-principal-with-a-secret
creds: ${{ secrets.RND_AZURE_CREDENTIALS }}
- name: Run create_and_upload_zip
if: github.event_name != 'workflow_dispatch'
run: task create_and_upload_zip DIST=$DIST
- name: Run create_and_upload_zip (workflow_dispatch)
if: github.event_name == 'workflow_dispatch'
run: task create_and_upload_zip DIST=${{ inputs.dist }}
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'chore: update function_app_version'
file_pattern: 'variables.tf'
weka_deployment:
name: Test Weka Deployment
needs: function-app-dist
runs-on: ubuntu-latest
if: github.event_name != 'release'
defaults:
run:
working-directory: ./ci/deployment
steps:
- name: Checkout
uses: actions/checkout@v3
- id: auth
name: Authenticate to Azure Cloud
uses: azure/login@v1
with:
creds: ${{secrets.AZURE_CREDENTIALS}}
- name: Create Azure resource group
uses: azure/CLI@v1
with:
inlineScript: |
az group create --name $RG_NAME --location eastus
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.5.2
- name: Terraform Init
run: terraform init
- name: Terraform Apply
run: terraform apply -var="rg_name=$RG_NAME" -var="prefix=$PREFIX" -var="cluster_name=$CLUSTER_NAME" -var="get_weka_io_token=$GET_WEKA_IO_TOKEN" -var="client_id=$CLIENT_ID" -var="tenant_id=$TENANT_ID" -var="client_secret=$CLIENT_SECRET" -var="subscription_id=$SUBSCRIPTION_ID" -var="cluster_size=$INITIAL_CAPACITY" -auto-approve
- name: Wait for weka cluster
uses: azure/CLI@v1
with:
inlineScript: |
chmod +x $GITHUB_WORKSPACE/ci/deployment/wait_for_cluster.sh
$GITHUB_WORKSPACE/ci/deployment/wait_for_cluster.sh $PREFIX $CLUSTER_NAME $RG_NAME $SUBSCRIPTION_ID $INITIAL_CAPACITY $INITIALIZATION_TIMEOUT
- name: Scale up. Increase cluster capacity by 1
uses: azure/CLI@v1
with:
inlineScript: |
chmod +x $GITHUB_WORKSPACE/ci/deployment/resize.sh
$GITHUB_WORKSPACE/ci/deployment/resize.sh $PREFIX $CLUSTER_NAME $RG_NAME $SUBSCRIPTION_ID $NEW_CAPACITY
- name: Wait for scaled up weka cluster
uses: azure/CLI@v1
with:
inlineScript: |
chmod +x $GITHUB_WORKSPACE/ci/deployment/wait_for_cluster.sh
$GITHUB_WORKSPACE/ci/deployment/wait_for_cluster.sh $PREFIX $CLUSTER_NAME $RG_NAME $SUBSCRIPTION_ID $NEW_CAPACITY $SCALE_UP_TIMEOUT
- name: Scale down. Decrease cluster capacity by 1
uses: azure/CLI@v1
with:
inlineScript: |
chmod +x $GITHUB_WORKSPACE/ci/deployment/resize.sh
$GITHUB_WORKSPACE/ci/deployment/resize.sh $PREFIX $CLUSTER_NAME $RG_NAME $SUBSCRIPTION_ID $INITIAL_CAPACITY
- name: Wait for scaled down weka cluster
uses: azure/CLI@v1
with:
inlineScript: |
chmod +x $GITHUB_WORKSPACE/ci/deployment/wait_for_cluster.sh
$GITHUB_WORKSPACE/ci/deployment/wait_for_cluster.sh $PREFIX $CLUSTER_NAME $RG_NAME $SUBSCRIPTION_ID $INITIAL_CAPACITY $SCALE_DOWN_TIMEOUT
- name: Terraform Destroy
if: always()
run: terraform destroy -var="rg_name=$RG_NAME" -var="prefix=$PREFIX" -var="cluster_name=$CLUSTER_NAME" -var="get_weka_io_token=$GET_WEKA_IO_TOKEN" -var="client_id=$CLIENT_ID" -var="tenant_id=$TENANT_ID" -var="client_secret=$CLIENT_SECRET" -var="subscription_id=$SUBSCRIPTION_ID" -var="cluster_size=$INITIAL_CAPACITY" -auto-approve
- name: Delete Azure resource group
if: always()
uses: azure/CLI@v1
with:
inlineScript: |
az group delete --name $RG_NAME --yes
- name: Logout from Azure Cloud
if: always()
uses: azure/CLI@v1
with:
inlineScript: |
az logout
az cache purge
az account clear