-
Notifications
You must be signed in to change notification settings - Fork 0
338 lines (283 loc) · 9.74 KB
/
stage.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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
---
name: Stage deployment
on:
workflow_dispatch:
env:
DO_PAT: ${{secrets.DIGITALOCEAN_ACCESS_TOKEN}}
AWS_ACCESS_KEY_ID: ${{secrets.DIGITALOCEAN_SPACES_ACCESS_TOKEN}}
AWS_SECRET_ACCESS_KEY: ${{secrets.DIGITALOCEAN_SPACES_SECRET_KEY}}
REGION: ${{secrets.DIGITALOCEAN_REGION}}
MOUNT_POINT: "/opt/rkub"
BUCKET: "rkub-github-action-${{ github.run_id }}"
#BUCKET: "terraform-backend-github"
CONTROLLER_COUNT: "1"
WORKER_COUNT: "0"
SIZE: "s-4vcpu-8gb"
jobs:
bucket:
name: Bucket
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Set up S3cmd cli tool
uses: s3-actions/s3cmd@main
with:
provider: digitalocean
region: ${{secrets.DIGITALOCEAN_REGION}}
access_key: ${{secrets.DIGITALOCEAN_SPACES_ACCESS_TOKEN}}
secret_key: ${{secrets.DIGITALOCEAN_SPACES_SECRET_KEY}}
- name: Create Space Bucket
run: |
sed -i -e 's/signature_v2.*$/signature_v2 = True/' ~/.s3cfg
if [[ $BUCKET != "terraform-backend-github" ]]; then s3cmd mb s3://${BUCKET}; fi
sleep 10
package:
name: Package
runs-on: ubuntu-latest
needs: Bucket
timeout-minutes: 60
steps:
- name: Install s3fs-fuse on Ubuntu
run: |
sudo apt-get install automake autotools-dev fuse g++ git libcurl4-gnutls-dev libfuse-dev libssl-dev libxml2-dev make pkg-config
git clone https://github.com/s3fs-fuse/s3fs-fuse.git
cd s3fs-fuse
./autogen.sh
./configure
make
sudo make install
- name: Mount Space Bucket
run: |
echo "${{secrets.DIGITALOCEAN_SPACES_ACCESS_TOKEN}}:${{secrets.DIGITALOCEAN_SPACES_SECRET_KEY}}" > ./passwd-s3fs
chmod 600 ./passwd-s3fs
mkdir -p ${MOUNT_POINT}
s3fs ${BUCKET} ${MOUNT_POINT} -o url=https://${REGION}.digitaloceanspaces.com -o passwd_file=./passwd-s3fs
df -Th ${MOUNT_POINT}
- name: Checkout files
uses: actions/checkout@v4
- name: Build
run: |
cd ./test
if [[ $BUCKET != "terraform-backend-github" ]]; then \
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook playbooks/hauler_build.yml -e dir_build="${MOUNT_POINT}" -e archive="false"; \
fi
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: Bucket
timeout-minutes: 20
defaults:
run:
shell: bash
working-directory: ./test
steps:
- name: Checkout files
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.7.3"
- name: Terraform Init
id: init
run: |
cd ./DO/infra
terraform init -backend-config="bucket=${BUCKET}"
- name: Terraform Validate
id: validate
run: |
cd ./DO/infra
terraform validate -no-color
- name: Terraform Plan
id: plan
run: |
cd ./DO/infra
terraform plan -out=terraform.tfplan \
-var "GITHUB_RUN_ID=$GITHUB_RUN_ID" \
-var "do_token=${DO_PAT}" \
-var "do_worker_count=${WORKER_COUNT}" \
-var "do_controller_count=${CONTROLLER_COUNT}" \
-var "do_instance_size=${SIZE}" \
-var "spaces_access_key_id=${{secrets.DIGITALOCEAN_SPACES_ACCESS_TOKEN}}" \
-var "spaces_access_key_secret=${{secrets.DIGITALOCEAN_SPACES_SECRET_KEY}}" \
-var "mount_point=${MOUNT_POINT}" \
-var "terraform_backend_bucket_name=${BUCKET}"
continue-on-error: true
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
- name: Terraform Apply
run: |
cd ./DO/infra
terraform apply terraform.tfplan
- name: Display inventory
run: |
ls -l ${{ github.workspace }}/test/inventory/hosts.ini
cat inventory/hosts.ini
# No relative path allowed
- name: Inventory artifacts
uses: actions/upload-artifact@v4
with:
name: inventory
path: |
${{ github.workspace }}/test/inventory/hosts.ini
if-no-files-found: error
reachable:
name: Reachable
runs-on: ubuntu-latest
needs: deploy
timeout-minutes: 10
defaults:
run:
shell: bash
working-directory: ./test
steps:
- name: Checkout files
uses: actions/checkout@v4
- name: Download inventory
uses: actions/download-artifact@v4
with:
name: inventory
- name: Check if inventory present
run: |
cat ${{ github.workspace }}/hosts.ini
- name: Set up Python
id: setup_python
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip3 install ansible pytest-testinfra
ansible --version
- name: Get key and hosts.ini
run: |
echo "$SSH_KEY" > .key
chmod 400 .key
cp ${{ github.workspace }}/hosts.ini inventory/hosts.ini
shell: bash
env:
SSH_KEY: ${{secrets.SSH_PRIVATE_KEY}}
- name: Test if reachable
run: |
ANSIBLE_HOST_KEY_CHECKING=False ansible RKE2_CLUSTER -m ping -u root -vv --private-key .key
- name: Wait for cloud-init to finish
run: |
ANSIBLE_HOST_KEY_CHECKING=False ansible RKE2_CLUSTER -m shell -a "cloud-init status --wait" -u root -v --private-key .key
install:
name: Install
runs-on: ubuntu-latest
needs: [ Reachable, Package ]
timeout-minutes: 60
defaults:
run:
shell: bash
working-directory: ./test
steps:
- name: Checkout files
uses: actions/checkout@v4
- name: Install requirements
run: |
cd ..
make prerequis
- name: Download inventory
uses: actions/download-artifact@v4
with:
name: inventory
- name: Get key and hosts.ini
run: |
echo "$SSH_KEY" > .key
chmod 400 .key
cp ${{ github.workspace }}/hosts.ini inventory/hosts.ini
shell: bash
env:
SSH_KEY: ${{secrets.SSH_PRIVATE_KEY}}
- name: Run playbook hauler_server.yml
run: |
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u root --private-key .key playbooks/hauler_server.yml -e dir_target=${MOUNT_POINT}
- name: Run playbook install.yml
run: |
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u root --private-key .key playbooks/install.yml -e dir_target=${MOUNT_POINT}
#- name: Run playbook rancher.yml
# run: |
# ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u root --private-key .key playbooks/rancher.yml
#- name: Run playbook longhorn.yml
# run: |
# ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u root --private-key .key playbooks/longhorn.yml
#- name: Run playbook neuvector.yml
# run: |
# ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u root --private-key .key playbooks/neuvector.yml
#- name: Run Python Tests
# run: |
# export DEFAULT_PRIVATE_KEY_FILE=.key
# pytest --hosts=rke2_servers --ansible-inventory=hosts.ini --force-ansible --connection=ansible --sudo test/basic_server_tests.py
# pytest --hosts=rke2_agents --ansible-inventory=hosts.ini --force-ansible --connection=ansible --sudo test/basic_agent_tests.py
delay:
name: Delay
runs-on: ubuntu-latest
needs: Install
if: always()
steps:
- name: Delay half an hour
uses: whatnick/wait-action@master
with:
time: '1800s'
cleanup:
name: Cleanup
runs-on: ubuntu-latest
needs: Delay
if: always()
timeout-minutes: 30
defaults:
run:
shell: bash
working-directory: ./test/DO/infra
steps:
- name: Checkout files
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.7.3"
- name: Get key
run: |
echo "$SSH_KEY" > .key
chmod 400 .key
shell: bash
env:
SSH_KEY: ${{secrets.SSH_PRIVATE_KEY}}
- name: Terraform Init
id: init
run: |
terraform init -backend-config="bucket=${BUCKET}"
continue-on-error: true
- name: Terraform plan delete stack
id: plan
run: |
terraform plan -destroy -out=terraform.tfplan \
-var "GITHUB_RUN_ID=$GITHUB_RUN_ID" \
-var "do_token=${DO_PAT}" \
-var "do_worker_count=${WORKER_COUNT}" \
-var "do_controller_count=${CONTROLLER_COUNT}" \
-var "do_instance_size=${SIZE}" \
-var "spaces_access_key_id=${{secrets.DIGITALOCEAN_SPACES_ACCESS_TOKEN}}" \
-var "spaces_access_key_secret=${{secrets.DIGITALOCEAN_SPACES_SECRET_KEY}}" \
-var "mount_point=${MOUNT_POINT}" \
-var "terraform_backend_bucket_name=${BUCKET}"
continue-on-error: true
- name: Terraform Apply
run: |
terraform apply terraform.tfplan
continue-on-error: true
- name: Set up S3cmd cli tool
uses: s3-actions/s3cmd@main
with:
provider: digitalocean
region: ${{secrets.DIGITALOCEAN_REGION}}
access_key: ${{secrets.DIGITALOCEAN_SPACES_ACCESS_TOKEN}}
secret_key: ${{secrets.DIGITALOCEAN_SPACES_SECRET_KEY}}
- name: Remove Space bucket
run: |
sed -i -e 's/signature_v2.*$/signature_v2 = True/' ~/.s3cfg
if [[ $BUCKET != "terraform-backend-github" ]]; then s3cmd rb s3://${BUCKET} --recursive; fi
sleep 10