Skip to content

Commit 0797971

Browse files
committed
Adding github workflow
1 parent e2776b1 commit 0797971

File tree

4 files changed

+139
-0
lines changed

4 files changed

+139
-0
lines changed

.github/workflows/azure-dev.yaml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
on:
2+
workflow_dispatch:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- 'azure.yaml'
8+
- 'infra/**'
9+
- 'src/**'
10+
- 'tests/**'
11+
- '.github/workflows/azure-dev.yml'
12+
13+
permissions:
14+
id-token: write
15+
contents: read
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
env:
21+
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
22+
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
23+
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
24+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
25+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
26+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
27+
GITOPS_REPO: ${{ vars.GITOPS_REPO }}
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v3
31+
- name: Install azd
32+
uses: Azure/[email protected]
33+
- name: pre validation
34+
shell: bash
35+
run: |
36+
for varName in GITHUB_TOKEN AZURE_ENV_NAME AZURE_LOCATION AZURE_SUBSCRIPTION_ID GITOPS_REPO AZURE_TENANT_ID; do
37+
varVal=$(eval echo "\${$varName}")
38+
[[ -z $varVal ]] && {
39+
echo "💥 Error! Required env variable or secret '$varName' is not set!"
40+
envUnset=true
41+
}
42+
done
43+
if [ "$envUnset" = true ]; then
44+
exit 1
45+
fi
46+
47+
- name: Kubectl Install
48+
uses: azure/setup-kubectl@v3
49+
50+
- name: Log in with Azure
51+
if: ${{ env.AZURE_CLIENT_ID != '' }}
52+
run: |
53+
azd auth login --no-prompt `
54+
--client-id "$Env:AZURE_CLIENT_ID" `
55+
--federated-credential-provider "github" `
56+
--tenant-id "$Env:AZURE_TENANT_ID"
57+
shell: pwsh
58+
59+
- name: Azure login (for the preprovision script)
60+
uses: azure/login@v1
61+
with:
62+
client-id: ${{ env.AZURE_CLIENT_ID }}
63+
subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}
64+
tenant-id: ${{ env.AZURE_TENANT_ID }}
65+
66+
- name: Github CLI install
67+
run: |
68+
type -p curl >/dev/null || apt install curl -y
69+
sudo curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
70+
&& chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
71+
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
72+
&& sudo apt update \
73+
&& sudo apt install gh jq gettext-base -y
74+
75+
- name: Azure Dev Provision
76+
run: |
77+
git config --global user.name github-actions
78+
git config --global user.email [email protected]
79+
80+
azd up --no-prompt

scripts/postpipelineconfig.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
PWD=$(dirname "$0")
3+
4+
function sourceAzdEnvVars() {
5+
while IFS='=' read -r key value; do
6+
value=$(echo "$value" | sed 's/^"//' | sed 's/"$//')
7+
export "$key=$value"
8+
done <<EOF
9+
$(azd env get-values)
10+
EOF
11+
}
12+
13+
GIT_CONTROLLER_URL=$(git remote get-url origin)
14+
15+
function pre_validation () {
16+
local git_url=$1
17+
18+
[[ ! -z $git_url ]] && {
19+
echo "💥 Error! Git remote is missing. This script should run after azd pipeline config!"
20+
exit
21+
}
22+
23+
for varName in AZURE_AKS_CLUSTER_NAME GITHUB_TOKEN; do
24+
varVal=$(eval echo "\${$varName}")
25+
[[ -z $varVal ]] && {
26+
echo "💥 Error! Required variable '$varName' is not set!"
27+
varUnset=true
28+
}
29+
done
30+
}
31+
32+
sourceAzdEnvVars
33+
pre_validation
34+
GIT_CONTROLLER_REPO=$(echo $GIT_CONTROLLER_URL | sed 's|https://github.com/||')
35+
36+
gh secret set GH_TOKEN --body "${GITHUB_TOKEN}" --repo $GIT_CONTROLLER_REPO
37+
38+
for env in AZURE_AKS_CLUSTER_NAME; do
39+
echo "setting env variable: ${env} in repo: ${GIT_CONTROLLER_REPO}"
40+
envVal=$(eval echo "\${$env}")
41+
gh variable set $env --body "${envVal}" --repo $GIT_CONTROLLER_REPO
42+
done

src/api/manifests/values.yaml.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ secretStore:
2323
tenantId: ${AZURE_TENANT_ID}
2424
useVMManagedIdentity: "true"
2525
usePodIdentity: "false"
26+
cloudName: AzureCloud
2627
secrets:
2728
- envName: APPLICATIONINSIGHTS_CONNECTION_STRING
2829
objectName: appInsightsConnectionString

src/hooks/preprovision.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ def prompt_user_for_target_clusters(clusters):
1414
Returns:
1515
ManagedCluster: The selected cluster.
1616
"""
17+
18+
# If the AZURE_AKS_CLUSTER_NAME enviornment variable is set, use that to filter the \
19+
# cluster from the clusters list
20+
if os.environ.get("AZURE_AKS_CLUSTER_NAME") is not None:
21+
cluster_name = os.environ.get("AZURE_AKS_CLUSTER_NAME")
22+
clusters = [cluster for cluster in clusters if cluster.name == cluster_name]
23+
24+
if len(clusters) == 0:
25+
raise ValueError(
26+
f"No AKS clusters found with the name {cluster_name}. Please create \
27+
an AKS cluster and set the \
28+
{AZD_ENVIRONMENT_NAME_RESOURCE_TAG} tag."
29+
)
30+
31+
return clusters[0]
32+
1733
title = "Select a Big Bang cluster for your deployment environment"
1834

1935
options = [

0 commit comments

Comments
 (0)