Skip to content

Commit 4974a83

Browse files
committed
Updated github-action testing to be more dynamic and work with new long-lived deployment
1 parent e16fa89 commit 4974a83

File tree

6 files changed

+141
-126
lines changed

6 files changed

+141
-126
lines changed

.github/workflows/github-action-test-nginxaas-deploy.yml

Lines changed: 70 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ on:
66
- cron: "0 20 * * *"
77

88
env:
9-
NGINX_DEPLOYMENT_NAME: github-action-test-dep
10-
NGINX_TRANSFORMED_CONFIG_DIR_PATH: /etc/nginx/
11-
NGINX_ROOT_CONFIG_FILE: nginx.conf
12-
TEST_RESOURCE_GROUP_NAME: testenv-0da38993-workload
9+
NGINX_CONFIG_DIRECTORY: github-action/test/configs
10+
NGINX_DEPLOYMENT_NAME: n4a-long-westcent-nginxaas
11+
NGINX_TRANSFORMED_CONFIG_DIR_PATH: /
12+
NGINX_ROOT_CONFIG_FILE: /etc/nginx/nginx.conf
13+
TEST_RESOURCE_GROUP_NAME: n4a-long-westcent-workload
1314
NGINX_CERT_NAME: github-action-test-crt
1415
NGINX_VAULT_NAME: nlbtest-customer
1516

@@ -18,64 +19,73 @@ permissions:
1819
contents: read
1920

2021
jobs:
22+
Fetch-NGINX-State:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: "AZ CLI Login"
26+
uses: azure/login@v1
27+
with:
28+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
29+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
30+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
31+
32+
- name: "Fetch deployment state"
33+
uses: azure/CLI@v1
34+
with:
35+
azcliversion: 2.40.0
36+
inlineScript: |
37+
az extension add --source https://azcliprod.blob.core.windows.net/cli-extensions/nginx-0.1.1-py2.py3-none-any.whl -y
38+
az nginx deployment show -g $TEST_RESOURCE_GROUP_NAME -n $NGINX_DEPLOYMENT_NAME --output json > nginx.json
39+
az nginx deployment configuration show -g $TEST_RESOURCE_GROUP_NAME --deployment-name $NGINX_DEPLOYMENT_NAME -n default --output json > nginx.config.json
40+
name: nginx-state
41+
path: |
42+
nginx.json
43+
nginx.config.json
44+
2145
Update-NGINX:
2246
runs-on: ubuntu-latest
2347
steps:
24-
- name: "Checkout repository"
25-
uses: actions/checkout@v2
26-
- name: "AZ CLI Login"
27-
uses: azure/login@v1
28-
with:
29-
client-id: ${{ secrets.AZURE_CLIENT_ID }}
30-
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
31-
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
48+
- name: "Checkout repository"
49+
uses: actions/checkout@v2
50+
51+
- name: "AZ CLI Login"
52+
uses: azure/login@v1
53+
with:
54+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
55+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
56+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
3257

33-
- name: "Update config - single file"
34-
shell: bash
35-
run: |
36-
sed -i 's/000000/'"$GITHUB_RUN_NUMBER"'/g' github-action/test/configs/single/nginx.conf
37-
cat github-action/test/configs/single/nginx.conf
38-
- name: "Sync NGINX configuration to NGINXaaS for Azure - single file"
39-
uses: nginxinc/nginx-for-azure-deploy-action@v0.3.1
40-
with:
41-
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
42-
resource-group-name: $TEST_RESOURCE_GROUP_NAME
43-
nginx-deployment-name: $NGINX_DEPLOYMENT_NAME
44-
nginx-config-directory-path: github-action/test/configs/single/
45-
nginx-root-config-file: $NGINX_ROOT_CONFIG_FILE
46-
transformed-nginx-config-directory-path: $NGINX_TRANSFORMED_CONFIG_DIR_PATH
47-
- name: "Validate config update - single file"
48-
shell: bash
49-
run: |
50-
wget -O - -o /dev/null http://${{ secrets.NGINX_DEPLOYMENT_IP }} | jq '.request.headers."Github-Run-Id" | test( "'"$GITHUB_RUN_NUMBER"'")'
51-
- name: "Update config - multi file"
52-
shell: bash
53-
run: |
54-
sed -i 's/000000/'"$GITHUB_RUN_ID"'/g' github-action/test/configs/multi/nginx.conf
55-
cat github-action/test/configs/multi/nginx.conf
56-
sed -i 's/000000/'"$GITHUB_RUN_ID"'/g' github-action/test/configs/multi/conf.d/proxy.conf
57-
cat github-action/test/configs/multi/conf.d/proxy.conf
58-
- name: "Sync NGINX configuration and certificate to NGINXaaS for Azure - multi file"
59-
uses: nginxinc/nginx-for-azure-deploy-action@v0.3.1
60-
with:
61-
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
62-
resource-group-name: $TEST_RESOURCE_GROUP_NAME
63-
nginx-deployment-name: $NGINX_DEPLOYMENT_NAME
64-
nginx-deployment-location: "westcentralus"
65-
nginx-config-directory-path: github-action/test/configs/multi/
66-
nginx-root-config-file: $NGINX_ROOT_CONFIG_FILE
67-
transformed-nginx-config-directory-path: $NGINX_TRANSFORMED_CONFIG_DIR_PATH
68-
nginx-certificates: '[{"certificateName": "$NGINX_CERT_NAME", "keyvaultSecret": "https://$NGINX_VAULT_NAME.vault.azure.net/secrets/$NGINX_CERT_NAME", "certificateVirtualPath": "/etc/nginx/ssl/$GITHUB_RUN_ID/my-cert.crt", "keyVirtualPath": "/etc/nginx/ssl/$GITHUB_RUN_ID/my-cert.key" } ]'
58+
- name: Download math result for job 1
59+
uses: actions/download-artifact@v4
60+
with:
61+
name: nginx-state
6962

70-
- name: "Validate config update"
71-
shell: bash
72-
run: |
73-
wget -O - -o /dev/null http://${{ secrets.NGINX_DEPLOYMENT_IP }} | jq '.request.headers."Github-Run-Id" | test( "'"$GITHUB_RUN_ID"'")'
74-
- name: "Validate certificate update"
75-
uses: azure/CLI@v1
76-
with:
77-
inlineScript: |
78-
echo "-----BEGIN CERTIFICATE-----" > /tmp/$GITHUB_RUN_ID.tmp
79-
az keyvault certificate show --vault-name $NGINX_VAULT_NAME -n $NGINX_CERT_NAME | jq -r .cer | cat >> /tmp/$GITHUB_RUN_ID.tmp
80-
echo "-----END CERTIFICATE-----" >> /tmp/$GITHUB_RUN_ID.tmp
81-
wget -O - -o /dev/null https://${{ secrets.NGINX_DEPLOYMENT_IP }} --ca-certificate=/tmp/$GITHUB_RUN_ID.tmp | jq '.request.headers."Github-Run-Id" | test( "'"$GITHUB_RUN_ID"'")'
63+
- name: "Prep Config Files"
64+
shell: bash
65+
run: |
66+
./github-action/test/scripts/config_to_files.sh -f $PWD/nginx.config.json -o $NGINX_CONFIG_DIRECTORY
67+
sed -i 's/000000/'"$GITHUB_RUN_ID"'/g' $NGINX_CONFIG_DIRECTORY/github_action.conf
68+
mv $NGINX_CONFIG_DIRECTORY/github_action.conf $NGINX_CONFIG_DIRECTORY/etc/nginx/conf.d/servers/github_action.conf
69+
cat $NGINX_CONFIG_DIRECTORY/etc/nginx/conf.d/servers/github_action.conf
70+
- name: "Sync NGINX configuration and certificate to NGINXaaS for Azure"
71+
uses: nginxinc/nginx-for-azure-deploy-action@v0.3.1
72+
with:
73+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
74+
resource-group-name: $TEST_RESOURCE_GROUP_NAME
75+
nginx-deployment-name: $NGINX_DEPLOYMENT_NAME
76+
nginx-deployment-location: "westcentralus"
77+
nginx-config-directory-path: $NGINX_CONFIG_DIRECTORY
78+
nginx-root-config-file: $NGINX_ROOT_CONFIG_FILE
79+
transformed-nginx-config-directory-path: $NGINX_TRANSFORMED_CONFIG_DIR_PATH
80+
nginx-certificates: '[{"certificateName": "$NGINX_CERT_NAME", "keyvaultSecret": "https://$NGINX_VAULT_NAME.vault.azure.net/secrets/$NGINX_CERT_NAME", "certificateVirtualPath": "/etc/nginx/ssl/$GITHUB_RUN_ID/my-cert.crt", "keyVirtualPath": "/etc/nginx/ssl/$GITHUB_RUN_ID/my-cert.key" } ]'
81+
82+
- name: "Validate certificate and config update"
83+
uses: azure/CLI@v1
84+
with:
85+
inlineScript: |
86+
export NGINX_DEPLOYMENT_IP=$(cat nginx.json | jq '.properties.ipAddress')
87+
wget -O - -o /dev/null http://${{ NGINX_DEPLOYMENT_IP }}/github-action | grep '$GITHUB_RUN_ID'
88+
echo "-----BEGIN CERTIFICATE-----" > /tmp/$GITHUB_RUN_ID.tmp
89+
az keyvault certificate show --vault-name $NGINX_VAULT_NAME -n $NGINX_CERT_NAME | jq -r .cer | cat >> /tmp/$GITHUB_RUN_ID.tmp
90+
echo "-----END CERTIFICATE-----" >> /tmp/$GITHUB_RUN_ID.tmp
91+
wget -O - -o /dev/null https://${{ NGINX_DEPLOYMENT_IP }}:8443/github-action --ca-certificate=/tmp/$GITHUB_RUN_ID.tmp | grep '$GITHUB_RUN_ID'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
server {
2+
listen 8443 ssl;
3+
server_name example.com;
4+
status_zone status_page;
5+
6+
# SSL/TLS certificate and key for the server
7+
ssl_certificate {{ ssl_certificate_path}};
8+
ssl_certificate_key {{ ssl_certificate_key_path }};
9+
10+
location /github-action {
11+
return 200, 'Github-Run-Id 000000';
12+
}
13+
}

github-action/test/configs/multi/conf.d/proxy.conf

Lines changed: 0 additions & 8 deletions
This file was deleted.

github-action/test/configs/multi/nginx.conf

Lines changed: 0 additions & 32 deletions
This file was deleted.

github-action/test/configs/single/nginx.conf

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
# Function to print usage
4+
print_usage() {
5+
echo "Usage: $0 [-f <json_file>] [-o <output_filepath>]"
6+
echo "Options:"
7+
echo " -f <json_file> Specify the JSON file to generate the config from (required)"
8+
echo " -o <output_filepath> Specify the base output filepath (optional)"
9+
exit 1
10+
}
11+
12+
# Parse command line options
13+
json_file=''
14+
output_filepath=$PWD
15+
16+
while getopts ":o:f:" opt; do
17+
case $opt in
18+
f) json_file="$OPTARG";;
19+
o) output_filepath="$OPTARG";;
20+
\?) echo "Error: Invalid option -$OPTARG" >&2; print_usage;;
21+
esac
22+
done
23+
24+
# Check if the JSON file exists
25+
if [ ! -f "$json_file" ]; then
26+
echo "Error: JSON file '$json_file' not found."
27+
exit 1
28+
fi
29+
30+
# Extract base64 encoded content and virtualPath
31+
# Use mapfile to store the output of jq into arrays
32+
while IFS= read -r content; do
33+
content_list+=("$content")
34+
done < <(jq -r '.properties.files[].content' "$json_file")
35+
36+
while IFS= read -r virtual_path; do
37+
virtual_path_list+=("$virtual_path")
38+
done < <(jq -r '.properties.files[].virtualPath' "$json_file")
39+
40+
# Decode and write content to files, keeping track of created files
41+
created_files=()
42+
for (( i=0; i<${#content_list[@]}; i++ )); do
43+
content=$(echo "${content_list[$i]}" | base64 -d)
44+
virtual_path="${virtual_path_list[$i]}"
45+
echo "Extracting file $virtual_path to ${output_filepath}${virtual_path}"
46+
47+
# Extract the directory path and create parent directories if they don't exist
48+
parent_dir=$(dirname "${output_filepath}${virtual_path}")
49+
mkdir -p "$parent_dir"
50+
51+
# Write content to file
52+
echo "$content" > "${output_filepath}${virtual_path}"
53+
54+
# Add created file to the list
55+
created_files+=("${output_filepath}${virtual_path}")
56+
done
57+
58+
echo "Extracted ${#created_files[@]} files"

0 commit comments

Comments
 (0)