Skip to content

Commit ebe12ba

Browse files
committed
create hello world ACI test pipeline
1 parent d6ae0e3 commit ebe12ba

36 files changed

+1331
-338
lines changed

.github/workflows/_cleanup.yml

Lines changed: 86 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,77 @@ on:
44
workflow_call:
55
inputs:
66
cluster-name:
7-
required: true
7+
required: false
88
description: AKS Cluster Name
99
type: string
1010
skr-client-kid:
11-
required: true
11+
required: false
1212
description: SKR key id
1313
default: "default-skr-client-kid"
1414
type: string
15+
debug:
16+
description: "Debug Flag"
17+
default: false
18+
required: false
19+
type: boolean
20+
test-name:
21+
description: "Test Name"
22+
required: true
23+
type: string
24+
schedule:
25+
- cron: "0 0 * * *"
1526

1627
jobs:
28+
cleanup-running-acis:
29+
name: Cleanup Running Container Groups
30+
runs-on: ubuntu-latest
31+
if: ${{ !inputs.debug }}
32+
env:
33+
RESOURCE_GROUP: ${{ vars.RESOURCE_GROUP }}
34+
steps:
35+
- name: Log into Azure
36+
uses: azure/login@v2
37+
with:
38+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
39+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
40+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
41+
42+
- name: Delete All Container Groups
43+
run: |
44+
RUNNING_CONTAINERS=$(az container list \
45+
--resource-group $RESOURCE_GROUP \
46+
--query "[?!starts_with(name, 'uptime-')]")
47+
48+
for container in $(echo $RUNNING_CONTAINERS | jq -r '.[].id'); do
49+
echo "Deleting container group: ${container}"
50+
az resource delete --ids ${container}
51+
done
52+
53+
cleanup-failed-acis:
54+
name: Cleanup Failed Container Groups
55+
runs-on: ubuntu-latest
56+
if: ${{ !inputs.debug }}
57+
env:
58+
RESOURCE_GROUP: ${{ vars.RESOURCE_GROUP }}
59+
steps:
60+
- name: Log into Azure
61+
uses: azure/login@v2
62+
with:
63+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
64+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
65+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
66+
67+
- name: Delete Failed Container Groups
68+
run: |
69+
NON_RUNNING_CONTAINERS=$(az container list \
70+
--resource-group $RESOURCE_GROUP \
71+
--query "[?provisioningState=='Failed' || provisioningState=='Unhealthy']")
72+
73+
for container in $(echo $NON_RUNNING_CONTAINERS | jq -r '.[].id'); do
74+
echo "Deleting container group: ${container}"
75+
az resource delete --ids ${container}
76+
done
77+
1778
cleanup_registry:
1879
name: Cleanup Container Registry
1980
runs-on: ubuntu-latest
@@ -25,23 +86,32 @@ jobs:
2586
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
2687
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
2788

28-
- name: Cleanup Public Azure Container Registry
29-
if: github.event_name != 'pull_request'
89+
- name: Cleanup Hello World ACI Images
90+
if: ${{ inputs.test-name == 'hello-world-aci' }}
91+
run: |
92+
# adding || true so that it doesn't fail if the image doesn't exist (i.e. helloworld didn't run)
93+
az acr login --name ${{ github.event_name == 'pull_request' && secrets.TEST_AZURE_REGISTRY_NAME || secrets.AZURE_REGISTRY_NAME }}
94+
az acr repository delete --name ${{ github.event_name == 'pull_request' && secrets.TEST_AZURE_REGISTRY_NAME || secrets.AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/aci/helloworld:${{ github.sha }} --yes || true
95+
96+
- name: Cleanup Hello World AKS Images
97+
if: ${{ inputs.test-name == 'hello-world-aks' }}
3098
run: |
31-
az acr login --name ${{ secrets.AZURE_REGISTRY_NAME }}
32-
az acr repository delete --name ${{ secrets.AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/kafka/consumer:${{ github.sha }} --yes
33-
az acr repository delete --name ${{ secrets.AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/kafka/producer:${{ github.sha }} --yes
99+
# adding || true so that it doesn't fail if the image doesn't exist (i.e. helloworld didn't run)
100+
az acr login --name ${{ github.event_name == 'pull_request' && secrets.TEST_AZURE_REGISTRY_NAME || secrets.AZURE_REGISTRY_NAME }}
101+
az acr repository delete --name ${{ github.event_name == 'pull_request' && secrets.TEST_AZURE_REGISTRY_NAME || secrets.AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/aks/helloworld:${{ github.sha }} --yes || true
34102
35-
- name: Cleanup Test Azure Container Registry
36-
if: github.event_name == 'pull_request'
103+
- name: Cleanup Kafka Images
104+
if: ${{ inputs.test-name == 'kafka' }}
37105
run: |
38-
az acr login --name ${{ secrets.TEST_AZURE_REGISTRY_NAME }}
39-
az acr repository delete --name ${{ secrets.TEST_AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/kafka/consumer:${{ github.sha }} --yes
40-
az acr repository delete --name ${{ secrets.TEST_AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/kafka/producer:${{ github.sha }} --yes
106+
# adding || true so that it doesn't fail if the image doesn't exist (i.e. kafka didn't run)
107+
az acr login --name ${{ github.event_name == 'pull_request' && secrets.TEST_AZURE_REGISTRY_NAME || secrets.AZURE_REGISTRY_NAME }}
108+
az acr repository delete --name ${{ github.event_name == 'pull_request' && secrets.TEST_AZURE_REGISTRY_NAME || secrets.AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/kafka/consumer:${{ github.sha }} --yes || true
109+
az acr repository delete --name ${{ github.event_name == 'pull_request' && secrets.TEST_AZURE_REGISTRY_NAME || secrets.AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/kafka/producer:${{ github.sha }} --yes || true
41110
42111
cleanup-cluster:
43-
name: Clean Up
112+
name: Clean Up Cluster
44113
runs-on: ubuntu-latest
114+
if: ${{ inputs.cluster-name != '' }}
45115
steps:
46116
- name: Log into Azure
47117
uses: azure/login@v2
@@ -52,12 +122,12 @@ jobs:
52122

53123
- name: Clean Up
54124
id: cleanup
55-
env:
125+
env:
56126
RESOURCE_GROUP: ${{ vars.RESOURCE_GROUP }}
57127
CLUSTER_NAME: ${{ inputs.cluster-name }}
58128
SKR_CLIENT_KID: ${{ inputs.skr-client-kid }}
59-
run: |
60-
# cannot rely on the job success/fail indicator to determine whether the SKR_CLIENT_KID exists or not so attempt to delete anyway
129+
run: |
130+
# cannot rely on the job success/fail indicator to determine whether the SKR_CLIENT_KID exists or not so attempt to delete anyway
61131
az keyvault key delete --vault-name kafka-test-pipeline-akv --name $SKR_CLIENT_KID 2>&1 || true
62132
result=$(az aks list -g $RESOURCE_GROUP --query "[].name" -o tsv)
63133

.github/workflows/_cleanup_all_clusters.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Cleanup All AKS Cluster in Resource Group
1+
name: Cleanup All AKS Cluster in Resource Group
22

33
on:
44
workflow_call:
@@ -11,19 +11,19 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Log into Azure
14-
uses: azure/login@v1
14+
uses: azure/login@v2
1515
with:
1616
client-id: ${{ secrets.AZURE_CLIENT_ID }}
1717
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
1818
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
1919

2020
- name: Clean Up
2121
id: cleanup
22-
env:
22+
env:
2323
RESOURCE_GROUP: ${{ vars.RESOURCE_GROUP }}
24-
run: |
24+
run: |
2525
result=$(az aks list -g $RESOURCE_GROUP --query "[].name" -o tsv)
26-
for name in $result
26+
for name in $result
2727
do
2828
max_retries=5
2929
retries=0

.github/workflows/_create_aks_cluster.yml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: Create AKS Cluster
33
on:
44
workflow_call:
55
inputs:
6+
demo-name:
7+
description: "Demo Name"
8+
required: true
9+
type: string
610
workflow-id:
711
description: "Workflow ID"
812
required: true
@@ -17,21 +21,21 @@ on:
1721
description: "Workflow ID"
1822
required: true
1923
type: string
20-
24+
2125
jobs:
2226
create-aks-cluster:
2327
name: Create AKS Cluster
2428
runs-on: ubuntu-latest
25-
env:
26-
RESOURCE_GROUP: ${{ vars.RESOURCE_GROUP }}
29+
env:
30+
RESOURCE_GROUP: ${{ vars.RESOURCE_GROUP }}
2731
outputs:
2832
cluster-name: ${{ steps.create-aks-cluster.outputs.cluster-name }}
2933
steps:
3034
- name: Checkout
31-
uses: actions/checkout@v4
35+
uses: actions/checkout@v4
3236

33-
- name: Install Dependencies
34-
id: install-dependencies
37+
- name: Install Dependencies
38+
id: install-dependencies
3539
run: |
3640
result=$(az extension list -o table 2>&1 || true)
3741
if [[ $result == *"aks-preview"* ]]; then
@@ -41,22 +45,22 @@ jobs:
4145
echo "aks-preview extension not found. Installing aks-preview..."
4246
az extension add --name aks-preview
4347
fi
44-
48+
4549
- name: Log into Azure
4650
uses: azure/login@v2
4751
with:
4852
client-id: ${{ secrets.AZURE_CLIENT_ID }}
4953
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
5054
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
51-
55+
5256
- name: Create AKS Cluster
5357
id: create-aks-cluster
5458
if: steps.install-dependencies.outcome == 'success'
55-
env:
56-
RUN_ID: ${{ inputs.workflow-id }}
59+
env:
60+
CLUSTER_NAME: ${{ inputs.demo-name }}-${{ inputs.workflow-id }}
5761
run: |
5862
az aks create --resource-group $RESOURCE_GROUP \
59-
--name kafka-${RUN_ID} \
63+
--name ${CLUSTER_NAME} \
6064
--os-sku AzureLinux \
6165
--node-vm-size Standard_DC4as_cc_v5 \
6266
--tags "Owner=accct" \
@@ -68,4 +72,4 @@ jobs:
6872
--auto-upgrade-channel patch \
6973
--node-os-upgrade-channel NodeImage
7074
71-
echo "cluster-name=kafka-${RUN_ID}" >> $GITHUB_OUTPUT
75+
echo "cluster-name=${CLUSTER_NAME}" >> $GITHUB_OUTPUT

.github/workflows/_deploy_aci.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Deploy ACI
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
workflow-id:
7+
description: "Workflow ID"
8+
required: true
9+
type: string
10+
helloworld-image:
11+
description: "Hello World ACI Image"
12+
default: "mcr.microsoft.com/acc/samples/aci/helloworld:2.9"
13+
required: true
14+
type: string
15+
debug:
16+
description: "Debug Flag"
17+
default: false
18+
required: false
19+
type: boolean
20+
workflow_dispatch:
21+
inputs:
22+
workflow-id:
23+
description: "Workflow ID"
24+
required: true
25+
type: string
26+
helloworld-image:
27+
description: "Hello World ACI Image"
28+
default: "mcr.microsoft.com/acc/samples/aci/helloworld:2.9"
29+
required: true
30+
type: string
31+
debug:
32+
description: "Debug Flag"
33+
default: false
34+
required: false
35+
type: boolean
36+
37+
jobs:
38+
deploy-aci:
39+
name: Deploy ACI
40+
runs-on: ubuntu-latest
41+
env:
42+
RESOURCE_GROUP: ${{ vars.RESOURCE_GROUP }}
43+
WORKFLOW_ID: ${{ inputs.workflow-id }}
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v4
47+
48+
- name: Log into Azure
49+
uses: azure/login@v2
50+
with:
51+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
52+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
53+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
54+
55+
- name: Login to Public Azure Container Registry
56+
if: github.event_name != 'pull_request'
57+
run: |
58+
az acr login --name ${{ secrets.AZURE_REGISTRY_NAME }}
59+
60+
- name: Login to Test Azure Container Registry
61+
if: github.event_name == 'pull_request'
62+
run: |
63+
az acr login --name ${{ secrets.TEST_AZURE_REGISTRY_NAME }}
64+
65+
- name: Install Dependencies
66+
id: install-dependencies
67+
run: |
68+
result=$(az extension list -o table 2>&1 || true)
69+
if [[ $result == *"confcom"* ]]; then
70+
echo "confcom already installed, upgrading confcom version."
71+
az extension update --name confcom
72+
else
73+
echo "confcom extension not found. Installing confcom..."
74+
az extension add --name confcom
75+
fi
76+
77+
- name: Setup Hello World Image Environment Variable
78+
run: |
79+
# check if official image
80+
if [[ "${{ inputs.helloworld-image }}" == *"mcr.microsoft.com"* ]]; then
81+
echo HELLO_WORLD_IMAGE='${{ inputs.helloworld-image }}' >> $GITHUB_ENV
82+
else
83+
echo HELLO_WORLD_IMAGE='${{ (github.event_name != 'pull_request' && secrets.AZURE_REGISTRY_URL) || secrets.TEST_AZURE_REGISTRY_URL }}'/'${{ inputs.helloworld-image }}' >> $GITHUB_ENV
84+
fi
85+
86+
- name: Substitute Environment Variables
87+
id: substitute-envs
88+
run: |
89+
python util/env_substitution.py --file hello-world/ACI/arm-template.json --file-type json
90+
91+
- name: Generate Security Policy
92+
id: generate-security-policy
93+
run: |
94+
sudo usermod -aG docker $USER
95+
if [[ ${{ inputs.debug }} ]]; then
96+
az confcom acipolicygen -a hello-world/ACI/arm-template.json --debug
97+
else
98+
az confcom acipolicygen -a hello-world/ACI/arm-template.json
99+
fi
100+
101+
- name: Deploy ARM Template
102+
id: deploy-arm-template
103+
run: |
104+
az deployment group create \
105+
--resource-group $RESOURCE_GROUP \
106+
--template-file hello-world/ACI/arm-template.json
107+
108+
- name: Check Container is Running
109+
run: |
110+
max_retries=5
111+
retries=0
112+
while [ $retries -lt $max_retries ]; do
113+
CONTAINER_STATE=$(az container show \
114+
--name helloworld-aci-$WORKFLOW_ID \
115+
--resource-group $RESOURCE_GROUP \
116+
)
117+
if [[ $(echo $CONTAINER_STATE | jq -r '.instanceView.state') == "Running" ]]; then
118+
echo "Container is running."
119+
break # Exit the loop on successful attempt
120+
else
121+
echo "Container is not running yet, retrying in 5 seconds..."
122+
echo "Container state is: "
123+
echo $CONTAINER_STATE | jq
124+
retries=$((retries+1))
125+
sleep 5 # give the container a chance to stabilize
126+
fi
127+
done
128+
129+
if [ $retries -eq $max_retries ]; then
130+
echo "The operation has been tried $retries times without success."
131+
exit 1
132+
fi

0 commit comments

Comments
 (0)