-
Notifications
You must be signed in to change notification settings - Fork 92
294 lines (256 loc) · 9.36 KB
/
azure-e2e-test.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
name: azure-e2e-test
permissions:
id-token: write
contents: read
env:
PODVM_IMAGE_NAME: "peerpod-image-${{ github.run_id }}-${{ github.run_attempt }}"
SSH_USERNAME: "peerpod"
# VM size used for building image.
VM_SIZE: "Standard_D2as_v5"
CLUSTER_NAME: "e2e-test-${{ github.run_id }}-${{ github.run_attempt }}"
on:
pull_request_target:
branches:
- main
jobs:
authorize:
environment:
${{ (github.event_name == 'pull_request_target' &&
github.event.pull_request.head.repo.full_name != github.repository) &&
'external' || 'internal' }}
runs-on: ubuntu-latest
steps:
- run: true
build-podvm-image:
runs-on: ubuntu-latest
needs: authorize
outputs:
pod-image-version: "${{ steps.generate_image_version.outputs.pod_image_version }}"
steps:
- name: Generate version for pod vm image
id: generate_image_version
run: |
unique_version="$(date '+%m.%d.%H%M%S')${{ github.run_attempt }}"
echo "Generated unique version for the image as: ${unique_version}"
echo "pod_image_version=${unique_version}" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3
with:
path: cloud-api-adaptor
- name: Clone kata repository
uses: actions/checkout@v3
with:
repository: kata-containers/kata-containers
path: kata-containers
ref: CC-0.7.0
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.69.0
default: true
- name: Set up rust build cache
uses: actions/cache@v3
continue-on-error: false
with:
# The paths to cache are documented here: https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci
path: |
~/.cargo/.crates.toml
~/.cargo/.crates2.json
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: rust
- name: Set up Go environment
uses: actions/setup-go@v4
with:
go-version: '1.20'
cache-dependency-path: cloud-api-adaptor/go.sum
- name: Install Dependencies
run: |
rustup target add x86_64-unknown-linux-musl
sudo apt-get install -y musl-tools libdevmapper-dev libgpgme-dev
shell: bash
- name: Set up rust cache for kata-containers repository
uses: actions/cache@v3
with:
path: |
kata-containers/src/agent/target
cloud-api-adaptor/podvm/files/usr/local/bin/kata-agent
key: rust-${{ hashFiles('kata-containers/src/agent/Cargo.lock') }}
- name: Set up umoci, skopeo cache
uses: actions/cache@v3
with:
path: |
cloud-api-adaptor/azure/image/umoci
cloud-api-adaptor/azure/image/skopeo
guest-components/
key: umoci-${{ hashFiles('cloud-api-adaptor/podvm/Makefile.inc') }}
- name: Build binaries
env:
GOPATH: /home/runner/go
run: |
pushd cloud-api-adaptor/azure/image
make binaries
popd
- uses: azure/login@v1
name: 'Az CLI login'
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
- name: Create podvm image
id: create-podvm-image
env:
PKR_VAR_subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
PKR_VAR_resource_group: ${{ secrets.AZURE_RESOURCE_GROUP }}
PKR_VAR_location: ${{ secrets.AZURE_REGION }}
PKR_VAR_az_image_name: ${{ env.PODVM_IMAGE_NAME }}
PKR_VAR_vm_size: ${{ env.VM_SIZE }}
PKR_VAR_ssh_username: ${{ env.SSH_USERNAME }}
PKR_VAR_az_gallery_name: ${{ secrets.AZURE_PODVM_GALLERY_NAME }}
PKR_VAR_az_gallery_image_name: ${{ secrets.AZURE_PODVM_IMAGE_DEF_NAME }}
PKR_VAR_az_gallery_image_version: ${{ steps.generate_image_version.outputs.pod_image_version }}
PKR_VAR_use_azure_cli_auth: "true"
PODVM_DISTRO: "ubuntu"
run: |
pushd cloud-api-adaptor/azure/image
make image
popd
build-caa-container-image:
runs-on: ubuntu-latest
needs: authorize
steps:
- uses: actions/checkout@v3
- name: Set up Go environment
uses: actions/setup-go@v4
with:
go-version: '1.20'
cache-dependency-path: go.sum
- uses: azure/login@v1
name: 'Az CLI login'
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Install build dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y libvirt-dev
- name: Build container image
env:
ARCHES: "linux/amd64"
RELEASE_BUILD: "false"
registry: "${{ secrets.ACR_URL }}"
COMMIT: "${GITHUB_SHA}"
run: |
az acr login --name ${{ secrets.ACR_URL }}
# This builds image in the following format:
# ACR_URL/cloud-api-adaptor:dev-COMMIT
make image
run-e2e-test:
runs-on: ubuntu-latest
needs:
- authorize
- build-podvm-image
- build-caa-container-image
steps:
- uses: actions/checkout@v3
- name: Set up Go environment
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Create provisioner file
env:
TEST_E2E_CREATE_RG: "no"
PODVM_IMAGE_VERSION: "${{ needs.build-podvm-image.outputs.pod-image-version }}"
run: |
cat << EOF > /tmp/provision_azure.properties
AZURE_SUBSCRIPTION_ID="${{ secrets.AZURE_SUBSCRIPTION_ID }}"
AZURE_CLIENT_ID="${{ secrets.AZURE_CLIENT_ID }}"
RESOURCE_GROUP_NAME="${{ secrets.AZURE_RESOURCE_GROUP }}"
CLUSTER_NAME="$CLUSTER_NAME"
LOCATION="${{ secrets.AZURE_REGION }}"
SSH_KEY_ID="id_rsa.pub"
AZURE_IMAGE_ID="/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ secrets.AZURE_RESOURCE_GROUP }}/providers/Microsoft.Compute/galleries/${{ secrets.AZURE_PODVM_GALLERY_NAME }}/images/${{ secrets.AZURE_PODVM_IMAGE_DEF_NAME }}/versions/${PODVM_IMAGE_VERSION}"
SSH_USERNAME="${{ env.SSH_USERNAME }}"
IS_CI_MANAGED_CLUSTER="true"
AZURE_CLI_AUTH="true"
MANAGED_IDENTITY_NAME="${{ secrets.AZURE_MANAGED_IDENTITY_NAME}}"
CAA_IMAGE="${{ secrets.ACR_URL }}/cloud-api-adaptor:dev-${GITHUB_SHA}"
EOF
cat /tmp/provision_azure.properties
- name: Create public ssh key and secrets
run: |
# TODO: This is a temporary fix to create an empty file for env.
touch install/overlays/azure/service-principal.env
ssh-keygen -t rsa -b 4096 -f install/overlays/azure/id_rsa -N "" -C [email protected]
- uses: azure/login@v1
name: 'Az CLI login'
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
- name: Run e2e test
env:
TEST_PROVISION_FILE: "/tmp/provision_azure.properties"
TEST_PROVISION: "yes"
CLOUD_PROVIDER: "azure"
BUILTIN_CLOUD_PROVIDERS: "azure"
run: make test-e2e
# Clean up step, run regardless of the failure state.
- name: Run deprovisioner
if: ${{ always() }}
env:
TEST_PROVISION_FILE: "/tmp/provision_azure.properties"
CLOUD_PROVIDER: "azure"
BUILTIN_CLOUD_PROVIDERS: "azure"
run: |
cd test/tools
make caa-provisioner-cli
# Ignore the error if the deprovision fails.
./caa-provisioner-cli -action=deprovision || true
cleanup-resources:
runs-on: ubuntu-latest
needs:
- authorize
- build-podvm-image
- build-caa-container-image
- run-e2e-test
if: always()
steps:
- uses: actions/checkout@v3
- uses: azure/login@v1
name: 'Az CLI login'
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
- name: Remove podvm image
env:
PODVM_IMAGE_VERSION: "${{ needs.build-podvm-image.outputs.pod-image-version }}"
run: |
# Delete the Pod VM image and its copy from the gallery.
az image delete \
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
--name ${{ env.PODVM_IMAGE_NAME }} || true
az sig image-version delete \
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
--gallery-name ${{ secrets.AZURE_PODVM_GALLERY_NAME }} \
--gallery-image-definition ${{ secrets.AZURE_PODVM_IMAGE_DEF_NAME }} \
--gallery-image-version "${PODVM_IMAGE_VERSION}" || true
# Delete the CAA container image built for this run.
suffix=".azurecr.io"
acr_url=${{ secrets.ACR_URL }}
registry_name="${acr_url%$suffix}"
az acr repository delete \
--name "${registry_name}" \
--image "${{ secrets.ACR_URL }}/cloud-api-adaptor:dev-${GITHUB_SHA}" \
--yes || true
# Delete the cluster even if it has been deleted already or does not exists.
az aks delete \
--name "${CLUSTER_NAME}" \
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
--no-wait \
--yes || true