Skip to content

Commit 6a551aa

Browse files
committed
add release pipeline
1 parent 94fe6b6 commit 6a551aa

14 files changed

+270
-47
lines changed

.github/workflows/_cleanup.yml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,37 @@ on:
66
- cron: "0 0 * * *"
77

88
jobs:
9-
remove-workload-and-cluster:
9+
cleanup_registry:
10+
name: Cleanup Container Registry
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Log into Azure
14+
uses: azure/login@v2
15+
with:
16+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
17+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
18+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
19+
20+
- name: Cleanup Public Azure Container Registry
21+
if: github.event_name != 'pull_request'
22+
run: |
23+
az acr login --name ${{ secrets.AZURE_REGISTRY_NAME }}
24+
az acr repository delete --name ${{ secrets.AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/kafka/consumer:${{ github.sha }} --yes
25+
az acr repository delete --name ${{ secrets.AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/kafka/producer:${{ github.sha }} --yes
26+
27+
- name: Cleanup Test Azure Container Registry
28+
if: github.event_name == 'pull_request'
29+
run: |
30+
az acr login --name ${{ secrets.TEST_AZURE_REGISTRY_NAME }}
31+
az acr repository delete --name ${{ secrets.TEST_AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/kafka/consumer:${{ github.sha }} --yes
32+
az acr repository delete --name ${{ secrets.TEST_AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/kafka/producer:${{ github.sha }} --yes
33+
34+
cleanup-cluster:
1035
name: Clean Up
1136
runs-on: ubuntu-latest
1237
steps:
1338
- name: Log into Azure
14-
uses: azure/login@v1
39+
uses: azure/login@v2
1540
with:
1641
client-id: ${{ secrets.AZURE_CLIENT_ID }}
1742
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
@@ -38,7 +63,11 @@ jobs:
3863
if [[ $clusterstate == *"Succeeded"* ]]; then
3964
echo "Returned result is $clusterstate"
4065
echo "Cluster is ready to be deleted."
41-
az aks stop --resource-group $RESOURCE_GROUP --name $name 2>&1
66+
powerState=$(az aks show -g $RESOURCE_GROUP -n $name --query "powerState.code" -o tsv)
67+
if [[ $powerState != *"Stopped"* ]]; then
68+
echo "Power state is $powerState, stopping"
69+
az aks stop --resource-group $RESOURCE_GROUP --name $name 2>&1
70+
fi
4271
az aks delete --resource-group $RESOURCE_GROUP --name $name --no-wait --yes
4372
elif [[ $clusterstate == *"Stopped"* ]] || [[ $clusterstate == *"Failed"* ]]; then
4473
echo "Returned result is $clusterstate"

.github/workflows/_create_aks_cluster.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@ name: Create AKS Cluster
22

33
on:
44
workflow_call:
5+
inputs:
6+
workflow-id:
7+
description: "Workflow ID"
8+
required: true
9+
type: string
510
outputs:
611
cluster-name:
7-
description: AKS Cluster Name
12+
description: "AKS Cluster Name"
813
value: ${{ jobs.create-aks-cluster.outputs.cluster-name }}
914
workflow_dispatch:
15+
inputs:
16+
workflow-id:
17+
description: "Workflow ID"
18+
required: true
19+
type: string
1020

1121
jobs:
1222
create-aks-cluster:
@@ -18,11 +28,7 @@ jobs:
1828
cluster-name: ${{ steps.create-aks-cluster.outputs.cluster-name }}
1929
steps:
2030
- name: Checkout
21-
uses: actions/checkout@v4
22-
23-
- name: Get Workflow ID
24-
id: generate-id
25-
run: echo "id=$(openssl rand -hex 8 | tr -d '\n')" >> $GITHUB_OUTPUT
31+
uses: actions/checkout@v4
2632

2733
- name: Install Dependencies
2834
id: install-dependencies
@@ -37,7 +43,7 @@ jobs:
3743
fi
3844
3945
- name: Log into Azure
40-
uses: azure/login@v1
46+
uses: azure/login@v2
4147
with:
4248
client-id: ${{ secrets.AZURE_CLIENT_ID }}
4349
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
@@ -47,10 +53,10 @@ jobs:
4753
id: create-aks-cluster
4854
if: steps.install-dependencies.outcome == 'success'
4955
env:
50-
RUN_ID: ${{ steps.generate-id.outputs.id}}
56+
RUN_ID: ${{ inputs.workflow-id }}
5157
run: |
5258
az aks create --resource-group $RESOURCE_GROUP \
53-
--name skr-kafka-demo-${RUN_ID} \
59+
--name kafka-${RUN_ID} \
5460
--os-sku AzureLinux \
5561
--node-vm-size Standard_DC4as_cc_v5 \
5662
--tags "Owner=accct" \
@@ -59,4 +65,4 @@ jobs:
5965
--workload-runtime KataCcIsolation \
6066
--node-count 1 \
6167
--generate-ssh-keys
62-
echo "cluster-name=skr-kafka-demo-${RUN_ID}" >> $GITHUB_OUTPUT
68+
echo "cluster-name=kafka-${RUN_ID}" >> $GITHUB_OUTPUT

.github/workflows/_deploy_kafka_test.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
inputs:
66
cluster-name:
77
required: true
8-
description: AKS Cluster Name
8+
description: "AKS Cluster Name"
99
type: string
1010
key-release-image:
1111
required: true
@@ -19,6 +19,14 @@ on:
1919
description: "Producer Image"
2020
required: true
2121
type: string
22+
repo-type:
23+
description: "Azure Container Registry to push the image to"
24+
required: true
25+
type: string
26+
workflow-id:
27+
description: "Workflow ID"
28+
required: true
29+
type: string
2230
jobs:
2331
deploy-kafka:
2432
name: Deploy Kafka Test
@@ -30,11 +38,19 @@ jobs:
3038
path: main
3139

3240
- name: Log into Azure
33-
uses: azure/login@v1
41+
uses: azure/login@v2
3442
with:
3543
client-id: ${{ secrets.AZURE_CLIENT_ID }}
3644
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
3745
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
46+
47+
- name: Log in to Public Azure Container Registry
48+
if: github.event_name != 'pull_request'
49+
run: az acr login --name ${{ secrets.AZURE_REGISTRY_NAME }}
50+
51+
- name: Log in to Test Azure Container Registry
52+
if: github.event_name == 'pull_request'
53+
run: az acr login --name ${{ secrets.TEST_AZURE_REGISTRY_NAME }}
3854

3955
- name: Install Dependencies
4056
id: install-dependencies
@@ -55,13 +71,13 @@ jobs:
5571
5672
- name: Run Workload
5773
env:
58-
AZURE_AKV_RESOURCE_ENDPOINT: ${{ secrets.SKR_CLIENT_AKV_ENDPOINT }}
74+
AZURE_AKV_RESOURCE_ENDPOINT: ${{ secrets.SKR_CLIENT_AKV_ENDPOINTT }}
5975
MAA_ENDPOINT: ${{ secrets.SKR_CLIENT_MAA_ENDPOINT }}
6076
CLUSTER_NAME: ${{ inputs.cluster-name }}
6177
RESOURCE_GROUP: ${{ vars.RESOURCE_GROUP }}
6278
SIDECAR_IMAGE: ${{ inputs.key-release-image }}
63-
CONSUMER_IMAGE: ${{ inputs.consumer-image }}
64-
PRODUCER_IMAGE: ${{ inputs.producer-image }}
79+
CONSUMER_IMAGE: ${{ (github.event_name == 'pull_request' && secrets.TEST_AZURE_REGISTRY_URL) || secrets.AZURE_REGISTRY_URL }}/${{ inputs.consumer-image }}
80+
PRODUCER_IMAGE: ${{ (github.event_name == 'pull_request' && secrets.TEST_AZURE_REGISTRY_URL) || secrets.AZURE_REGISTRY_URL }}/${{ inputs.producer-image }}
6581
id: run-workload
6682
run: |
6783
az aks get-credentials --name $CLUSTER_NAME --resource-group $RESOURCE_GROUP --overwrite-existing

.github/workflows/_push_image.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Push Image
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
repo_type:
7+
description: "Azure Container Registry to push the image to"
8+
required: true
9+
type: string
10+
image_tag:
11+
description: "Tag to push the image with"
12+
required: true
13+
type: string
14+
docker_context:
15+
description: "Docker Context to Use"
16+
required: true
17+
type: string
18+
19+
jobs:
20+
push-example-image:
21+
name: Push Image (${{ inputs.image_tag }})
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Log into Azure
28+
uses: azure/login@v2
29+
with:
30+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
31+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
32+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
33+
34+
- name: Log in to Public Azure Container Registry
35+
if: ${{ inputs.repo_type == 'public' }}
36+
run: az acr login --name ${{ secrets.AZURE_REGISTRY_NAME }}
37+
38+
- name: Log in to Test Azure Container Registry
39+
if: ${{ inputs.repo_type == 'private' }}
40+
run: az acr login --name ${{ secrets.TEST_AZURE_REGISTRY_NAME }}
41+
42+
- name: Build and Push Docker Image
43+
uses: docker/build-push-action@v5
44+
with:
45+
context: ${{ inputs.docker_context }}
46+
file: ${{ inputs.docker_context }}/Dockerfile
47+
push: true
48+
tags: ${{ inputs.repo_type == 'public' && secrets.AZURE_REGISTRY_URL || inputs.repo_type == 'private' && secrets.TEST_AZURE_REGISTRY_URL }}/${{ inputs.image_tag }}

.github/workflows/_setup_aks_cluster.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
inputs:
66
cluster-name:
77
required: true
8-
description: AKS Cluster Name
8+
description: "AKS Cluster Name"
99
type: string
1010
workflow_dispatch:
1111

@@ -21,7 +21,7 @@ jobs:
2121
uses: actions/checkout@v4
2222

2323
- name: Log into Azure
24-
uses: azure/login@v1
24+
uses: azure/login@v2
2525
with:
2626
client-id: ${{ secrets.AZURE_CLIENT_ID }}
2727
tenant-id: ${{ secrets.AZURE_TENANT_ID }}

.github/workflows/_test_workload.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
inputs:
66
cluster-name:
77
required: true
8-
description: AKS Cluster Name
8+
description: "AKS Cluster Name"
99
type: string
1010

1111
jobs:
@@ -19,7 +19,7 @@ jobs:
1919
path: main
2020

2121
- name: Log into Azure
22-
uses: azure/login@v1
22+
uses: azure/login@v2
2323
with:
2424
client-id: ${{ secrets.AZURE_CLIENT_ID }}
2525
tenant-id: ${{ secrets.AZURE_TENANT_ID }}

.github/workflows/kafka_demo_test.yml

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ on:
44
pull_request:
55
branches:
66
- main
7+
paths:
8+
- .github/workflows/**
9+
- kafka/**
10+
- '!**/README.md'
11+
- '!.github/workflows/release.yml'
12+
- '!.github/workflows/ci.yml'
713
workflow_dispatch:
814
inputs:
915
sidecar-registry:
@@ -32,9 +38,11 @@ on:
3238
merge_group:
3339
branches:
3440
- main
41+
3542
permissions:
3643
id-token: write # This is required for requesting the JWT
3744
contents: read # This is required for actions/checkout
45+
3846
jobs:
3947
prepare:
4048
name: Extract Environment Variables
@@ -52,54 +60,78 @@ jobs:
5260
run: |
5361
echo "Extracting Environment Variables"
5462
echo "Triggering event is ${{ github.event_name }}"
63+
# uses default SKR but builds new Kafka images from source for PR
5564
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
5665
echo "key-release-image=mcr.microsoft.com/aci/skr:2.7" >> $GITHUB_OUTPUT
57-
echo "consumer-image=mcr.microsoft.com/acc/samples/kafka/consumer:2.0" >> $GITHUB_OUTPUT
58-
echo "producer-image=mcr.microsoft.com/acc/samples/kafka/producer:2.0" >> $GITHUB_OUTPUT
66+
echo "consumer-image=private/${{ github.actor }}/acc/samples/kafka/consumer:${{ github.sha }}" >> $GITHUB_OUTPUT
67+
echo "producer-image=private/${{ github.actor }}/acc/samples/kafka/producer:${{ github.sha }}" >> $GITHUB_OUTPUT
68+
# uses the provided SKR and Kafka images or defaults for workflow_dispatch
5969
else
6070
echo "key-release-image=${{ format('{0}/{1}', inputs.sidecar-registry, inputs.key-release-image) }}" >> $GITHUB_OUTPUT
6171
echo "consumer-image=${{ inputs.consumer-image }}" >> $GITHUB_OUTPUT
6272
echo "producer-image=${{ inputs.producer-image }}" >> $GITHUB_OUTPUT
6373
fi
6474
75+
push_images:
76+
name: Push Images to Private Registry for Testing
77+
needs: [prepare]
78+
uses: ./.github/workflows/_push_image.yml
79+
if: github.event_name == 'pull_request'
80+
secrets: inherit
81+
strategy:
82+
matrix:
83+
image: ["kafka/consumer", "kafka/producer"]
84+
with:
85+
image_tag: "private/${{ github.actor }}/acc/samples/${{ matrix.image }}:${{ github.sha }}"
86+
docker_context: ${{ matrix.image }}
87+
repo_type: private
88+
6589
create-aks-cluster:
6690
name: Create AKS Cluster
67-
needs: [prepare]
91+
needs: [prepare, push_images]
6892
uses: ./.github/workflows/_create_aks_cluster.yml
93+
if: always() && (needs.push_images.result == 'success' || needs.push_images.result == 'skipped')
6994
secrets: inherit
95+
with:
96+
workflow-id: ${{ github.sha }}
7097

7198
setup-aks-cluster:
7299
name: Setup AKS Cluster
73-
needs: [prepare, create-aks-cluster]
100+
needs: [prepare, push_images, create-aks-cluster]
74101
uses: ./.github/workflows/_setup_aks_cluster.yml
102+
if: always() && (needs.push_images.result == 'success' || needs.push_images.result == 'skipped')
75103
secrets: inherit
76104
with:
77105
cluster-name: ${{ needs.create-aks-cluster.outputs.cluster-name }}
78106

79107
deploy-kafka-test:
80108
name: Deploy Kafka Demo Test
81109
uses: ./.github/workflows/_deploy_kafka_test.yml
82-
needs: [prepare, create-aks-cluster, setup-aks-cluster]
110+
needs: [prepare, push_images, create-aks-cluster, setup-aks-cluster]
111+
if: always() && (needs.push_images.result == 'success' || needs.push_images.result == 'skipped')
83112
secrets: inherit
84113
with:
85114
cluster-name: ${{ needs.create-aks-cluster.outputs.cluster-name }}
86115
key-release-image: ${{ needs.prepare.outputs.key-release-image }}
87116
consumer-image: ${{ needs.prepare.outputs.consumer-image }}
88117
producer-image: ${{ needs.prepare.outputs.producer-image }}
118+
repo-type: ${{ (github.event_name == 'pull_request' && 'private') || 'public' }}
119+
workflow-id: ${{ github.sha }}
89120

90121
test-workload:
91122
name: Test Workload
92123
uses: ./.github/workflows/_test_workload.yml
93-
needs: [prepare, create-aks-cluster, setup-aks-cluster, deploy-kafka-test]
124+
needs: [push_images, create-aks-cluster, deploy-kafka-test]
125+
if: always() && (needs.push_images.result == 'success' || needs.push_images.result == 'skipped')
94126
secrets: inherit
95127
with:
96128
cluster-name: ${{ needs.create-aks-cluster.outputs.cluster-name }}
97129

98130
cleanup:
99131
name: Clean Up
100-
if: always()
132+
if: always() && (needs.push_images.result == 'success' || needs.push_images.result == 'skipped')
101133
uses: ./.github/workflows/_cleanup.yml
102-
needs: [prepare, create-aks-cluster, setup-aks-cluster, deploy-kafka-test, test-workload]
134+
needs: [push_images, test-workload]
103135
secrets: inherit
104136

105137

0 commit comments

Comments
 (0)