Skip to content

Commit 5ad0d6a

Browse files
authored
Merge pull request #36 from nginxinc/ps-dev-actions-test
Restore Github Actions
2 parents e16fa89 + fae8551 commit 5ad0d6a

File tree

7 files changed

+137
-63
lines changed

7 files changed

+137
-63
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ env:
99
NGINX_DEPLOYMENT_NAME: github-action-test-dep
1010
NGINX_TRANSFORMED_CONFIG_DIR_PATH: /etc/nginx/
1111
NGINX_ROOT_CONFIG_FILE: nginx.conf
12-
TEST_RESOURCE_GROUP_NAME: testenv-0da38993-workload
12+
TEST_RESOURCE_GROUP_NAME: github-action-test
1313
NGINX_CERT_NAME: github-action-test-crt
1414
NGINX_VAULT_NAME: nlbtest-customer
1515

@@ -24,7 +24,7 @@ jobs:
2424
- name: "Checkout repository"
2525
uses: actions/checkout@v2
2626
- name: "AZ CLI Login"
27-
uses: azure/login@v1
27+
uses: azure/login@v2
2828
with:
2929
client-id: ${{ secrets.AZURE_CLIENT_ID }}
3030
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
@@ -33,7 +33,7 @@ jobs:
3333
- name: "Update config - single file"
3434
shell: bash
3535
run: |
36-
sed -i 's/000000/'"$GITHUB_RUN_NUMBER"'/g' github-action/test/configs/single/nginx.conf
36+
sed -i 's/000000/'"$GITHUB_RUN_ID"'/g' github-action/test/configs/single/nginx.conf
3737
cat github-action/test/configs/single/nginx.conf
3838
- name: "Sync NGINX configuration to NGINXaaS for Azure - single file"
3939
uses: nginxinc/[email protected]
@@ -47,7 +47,7 @@ jobs:
4747
- name: "Validate config update - single file"
4848
shell: bash
4949
run: |
50-
wget -O - -o /dev/null http://${{ secrets.NGINX_DEPLOYMENT_IP }} | jq '.request.headers."Github-Run-Id" | test( "'"$GITHUB_RUN_NUMBER"'")'
50+
curl -s -o /dev/null -D - http://${{ secrets.NGINX_DEPLOYMENT_IP }} | grep "Github-Run-Id: $GITHUB_RUN_ID"
5151
- name: "Update config - multi file"
5252
shell: bash
5353
run: |
@@ -70,12 +70,12 @@ jobs:
7070
- name: "Validate config update"
7171
shell: bash
7272
run: |
73-
wget -O - -o /dev/null http://${{ secrets.NGINX_DEPLOYMENT_IP }} | jq '.request.headers."Github-Run-Id" | test( "'"$GITHUB_RUN_ID"'")'
73+
curl -s -o /dev/null -D - http://${{ secrets.NGINX_DEPLOYMENT_IP }} | grep "Github-Run-Id: $GITHUB_RUN_ID"
7474
- name: "Validate certificate update"
75-
uses: azure/CLI@v1
75+
uses: azure/cli@v2
7676
with:
7777
inlineScript: |
7878
echo "-----BEGIN CERTIFICATE-----" > /tmp/$GITHUB_RUN_ID.tmp
7979
az keyvault certificate show --vault-name $NGINX_VAULT_NAME -n $NGINX_CERT_NAME | jq -r .cer | cat >> /tmp/$GITHUB_RUN_ID.tmp
8080
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"'")'
81+
curl -s -o /dev/null -D - https://${{ secrets.NGINX_DEPLOYMENT_IP }} --cacert /tmp/$GITHUB_RUN_ID.tmp | grep "Github-Run-Id: $GITHUB_RUN_ID"

github-action/README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ jobs:
2929
uses: actions/checkout@v2
3030

3131
- name: 'Run Azure Login using an Azure service principal with a secret'
32-
uses: azure/login@v1
32+
uses: azure/login@v2
3333
with:
3434
creds: ${{ secrets.AZURE_CREDENTIALS }}
3535

3636
- name: 'Sync the NGINX configuration from the GitHub repository to the NGINXaaS for Azure deployment'
37-
uses: nginxinc/[email protected].0
37+
uses: nginxinc/[email protected].1
3838
with:
3939
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
4040
resource-group-name: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
@@ -69,14 +69,14 @@ jobs:
6969
uses: actions/checkout@v2
7070

7171
- name: 'Run Azure Login using OIDC'
72-
uses: azure/login@v1
72+
uses: azure/login@v2
7373
with:
7474
client-id: ${{ secrets.AZURE_CLIENT_ID }}
7575
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
7676
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
7777

7878
- name: 'Sync the NGINX configuration from the GitHub repository to the NGINXaaS for Azure deployment'
79-
uses: nginxinc/[email protected].0
79+
uses: nginxinc/[email protected].1
8080
with:
8181
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
8282
resource-group-name: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
@@ -86,6 +86,9 @@ jobs:
8686
transformed-nginx-config-directory-path: /etc/nginx/
8787
```
8888
89+
> **Note:**
90+
The service principal being used for authenticating with Azure should have access to manage the NGINXaaS deployment. For simplicity, this guide assumes that the service principal has `Contributor` role to manage the deployment. Refer [prerequisites](https://docs.nginx.com/nginxaas/azure/getting-started/prerequisites/) for details.
91+
8992
## Handling NGINX configuration file paths
9093

9194
To facilitate the migration of the existing NGINX configuration, NGINXaaS for Azure supports multiple-files configuration with each file uniquely identified by a file path, just like how NGINX configuration files are created and used in a self-hosting machine. An NGINX configuration file can include another file using the [include directive](https://docs.nginx.com/nginx/admin-guide/basic-functionality/managing-configuration-files/). The file path used in an `include` directive can either be an absolute path or a relative path to the [prefix path](https://www.nginx.com/resources/wiki/start/topics/tutorials/installoptions/).
@@ -101,7 +104,7 @@ To use this action to sync the configuration files from this example, the direct
101104

102105
```yaml
103106
- name: 'Sync the NGINX configuration from the GitHub repository to the NGINXaaS for Azure deployment'
104-
uses: nginxinc/[email protected].0
107+
uses: nginxinc/[email protected].1
105108
with:
106109
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
107110
resource-group-name: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
@@ -133,7 +136,7 @@ The action supports an optional input `transformed-nginx-config-directory-path`
133136

134137
```yaml
135138
- name: 'Sync the NGINX configuration from the Git repository to the NGINXaaS for Azure deployment'
136-
uses: nginxinc/[email protected].0
139+
uses: nginxinc/[email protected].1
137140
with:
138141
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
139142
resource-group-name: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
@@ -151,11 +154,11 @@ The transformed paths of the two configuration files in the NGINXaaS for Azure d
151154

152155
## Handling NGINX certificates
153156

154-
Since certificates are secrets, it is assumed they are stored in Azure key vault. One can provide multiple certificate entries to the github action as an array of JSON objects with keys:
157+
Since certificates are secrets, it is assumed they are stored in Azure key vault. One can provide multiple certificate entries to the github action as an array of JSON objects with keys:
155158

156159
`certificateName`- A unique name for the certificate entry
157160

158-
`keyvaultSecret`- The secret ID for the certificate on Azure key vault
161+
`keyvaultSecret`- The secret ID for the certificate on Azure key vault
159162

160163
`certificateVirtualPath`- This path must match one or more ssl_certificate directive file arguments in your Nginx configuration; and must be unique between certificates within the same deployment
161164

@@ -165,7 +168,7 @@ See the example below
165168

166169
```yaml
167170
- name: "Sync NGINX certificates to NGINXaaS for Azure"
168-
uses: nginxinc/[email protected].0
171+
uses: nginxinc/[email protected].1
169172
with:
170173
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
171174
resource-group-name: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
@@ -178,7 +181,7 @@ See the example below
178181

179182
```yaml
180183
- name: "Sync NGINX configuration- multi file and certificate to NGINXaaS for Azure"
181-
uses: nginxinc/[email protected].0
184+
uses: nginxinc/[email protected].1
182185
with:
183186
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
184187
resource-group-name: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
@@ -188,4 +191,4 @@ See the example below
188191
nginx-root-config-file: nginx.conf
189192
transformed-nginx-config-directory-path: /etc/nginx/
190193
nginx-certificates: '[{"certificateName": "$NGINX_CERT_NAME", "keyvaultSecret": "https://$NGINX_VAULT_NAME.vault.azure.net/secrets/$NGINX_CERT_NAME", "certificateVirtualPath": "/etc/nginx/ssl/my-cert.crt", "keyVirtualPath": "/etc/nginx/ssl/my-cert.key" } ]'
191-
```
194+
```

github-action/action.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,26 @@ inputs:
2323
default: "nginx.conf"
2424
transformed-nginx-config-directory-path:
2525
description: >
26-
'The transformed absolute path of the NGINX configuration directory in NGINXaaS for Azure deployment, example: "/etc/nginx/".
27-
If the "include" directive in the NGINX configuration files uses absolute paths, the path transformation
26+
'The transformed absolute path of the NGINX configuration directory in NGINXaaS for Azure deployment, example: "/etc/nginx/".
27+
If the "include" directive in the NGINX configuration files uses absolute paths, the path transformation
2828
can be used to overwrite the file paths when the action synchronizes the files to the NGINXaaS for Azure deployment.'
2929
required: false
3030
default: ""
3131
nginx-certificates:
3232
description: 'An array of JSON objects each with keys nginx_cert_name, keyvault_secret, certificate_virtual_path and key_virtual_path. Example: [{"certificateName": "server1", "keyvaultSecret": "https://...", "certificateVirtualPath": "/etc/ssl/certs/server1.crt", "keyVirtualPath": "/etc/ssl/certs/server1.key" }, {"name": "server2", "keyvaultSecret": "https://...", "certificateVirtualPath": "/etc/ssl/certs/server2.crt", "keyVirtualPath": "/etc/ssl/certs/server2.key" }] '
3333
required: false
34+
debug:
35+
description: "Enable/Disable debug output."
36+
required: false
37+
default: "false"
3438
runs:
3539
using: "composite"
3640
steps:
3741
- name: "Synchronize NGINX certificate(s) from the Git repository to an NGINXaaS for Azure deployment"
38-
run: ${{github.action_path}}/src/deploy-certificate.sh --subscription_id=${{ inputs.subscription-id }} --resource_group_name=${{ inputs.resource-group-name }} --nginx_deployment_name=${{ inputs.nginx-deployment-name }} --nginx_resource_location=${{ inputs.nginx-deployment-location }} --certificates=${{ toJSON(inputs.nginx-certificates) }}
42+
run: ${{github.action_path}}/src/deploy-certificate.sh --subscription_id=${{ inputs.subscription-id }} --resource_group_name=${{ inputs.resource-group-name }} --nginx_deployment_name=${{ inputs.nginx-deployment-name }} --nginx_resource_location=${{ inputs.nginx-deployment-location }} --certificates=${{ toJSON(inputs.nginx-certificates) }} --debug=${{ inputs.debug }}
3943
if: ${{ inputs.nginx-deployment-location != '' && inputs.nginx-certificates != '' }}
4044
shell: bash
4145
- name: "Synchronize NGINX configuration from the Git repository to an NGINXaaS for Azure deployment"
42-
run: ${{github.action_path}}/src/deploy-config.sh --subscription_id=${{ inputs.subscription-id }} --resource_group_name=${{ inputs.resource-group-name }} --nginx_deployment_name=${{ inputs.nginx-deployment-name }} --config_dir_path=${{ inputs.nginx-config-directory-path }} --root_config_file=${{ inputs.nginx-root-config-file }} --transformed_config_dir_path=${{ inputs.transformed-nginx-config-directory-path }}
46+
run: ${{github.action_path}}/src/deploy-config.sh --subscription_id=${{ inputs.subscription-id }} --resource_group_name=${{ inputs.resource-group-name }} --nginx_deployment_name=${{ inputs.nginx-deployment-name }} --config_dir_path=${{ inputs.nginx-config-directory-path }} --root_config_file=${{ inputs.nginx-root-config-file }} --transformed_config_dir_path=${{ inputs.transformed-nginx-config-directory-path }} --debug=${{ inputs.debug }}
4347
if: ${{ inputs.nginx-config-directory-path != '' }}
4448
shell: bash

github-action/src/deploy-certificate.sh

100644100755
Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,27 @@ do
77
case $i in
88
--subscription_id=*)
99
subscription_id="${i#*=}"
10-
shift
10+
shift
1111
;;
1212
--resource_group_name=*)
1313
resource_group_name="${i#*=}"
14-
shift
14+
shift
1515
;;
1616
--nginx_deployment_name=*)
1717
nginx_deployment_name="${i#*=}"
18-
shift
18+
shift
1919
;;
2020
--nginx_resource_location=*)
2121
nginx_resource_location="${i#*=}"
22-
shift
22+
shift
2323
;;
2424
--certificates=*)
2525
certificates="${i#*=}"
26-
shift
26+
shift
27+
;;
28+
--debug=*)
29+
debug="${i#*=}"
30+
shift
2731
;;
2832
*)
2933
echo "Not matched option '${i#*=}' passed in."
@@ -35,27 +39,27 @@ done
3539
if [[ ! -v subscription_id ]];
3640
then
3741
echo "Please set 'subscription-id' ..."
38-
exit 1
42+
exit 1
3943
fi
4044
if [[ ! -v resource_group_name ]];
4145
then
4246
echo "Please set 'resource-group-name' ..."
43-
exit 1
47+
exit 1
4448
fi
4549
if [[ ! -v nginx_deployment_name ]];
4650
then
4751
echo "Please set 'nginx-deployment-name' ..."
48-
exit 1
52+
exit 1
4953
fi
5054
if [[ ! -v nginx_resource_location ]];
5155
then
5256
echo "Please set 'nginx-resource-location' ..."
53-
exit 1
57+
exit 1
5458
fi
5559
if [[ ! -v certificates ]];
5660
then
5761
echo "Please set 'nginx-certificates' ..."
58-
exit 1
62+
exit 1
5963
fi
6064

6165
arm_template_file="nginx-for-azure-certificate-template.json"
@@ -69,13 +73,13 @@ echo ""
6973

7074
az account set -s "$subscription_id" --verbose
7175

72-
count=$(echo $certificates | jq '. | length')
76+
count=$(echo "$certificates" | jq '. | length')
7377
for (( i=0; i<count; i++ ));
7478
do
75-
nginx_cert_name=$(echo $certificates | jq -r '.['"$i"'].certificateName')
76-
nginx_cert_file=$(echo $certificates | jq -r '.['"$i"'].certificateVirtualPath')
77-
nginx_key_file=$(echo $certificates | jq -r '.['"$i"'].keyVirtualPath')
78-
keyvault_secret=$(echo $certificates | jq -r '.['"$i"'].keyvaultSecret')
79+
nginx_cert_name=$(echo "$certificates" | jq -r '.['"$i"'].certificateName')
80+
nginx_cert_file=$(echo "$certificates" | jq -r '.['"$i"'].certificateVirtualPath')
81+
nginx_key_file=$(echo "$certificates" | jq -r '.['"$i"'].keyVirtualPath')
82+
keyvault_secret=$(echo "$certificates" | jq -r '.['"$i"'].keyvaultSecret')
7983

8084
do_nginx_arm_deployment=1
8185
err_msg=" "
@@ -103,9 +107,9 @@ do
103107
uuid="$(cat /proc/sys/kernel/random/uuid)"
104108
template_file="template-$uuid.json"
105109
template_deployment_name="${nginx_deployment_name:0:20}-$uuid"
106-
110+
107111
cp "$arm_template_file" "$template_file"
108-
112+
109113
echo "Synchronizing NGINX certificate"
110114
echo "Subscription ID: $subscription_id"
111115
echo "Resource group name: $resource_group_name"
@@ -120,11 +124,32 @@ do
120124

121125
if [ $do_nginx_arm_deployment -eq 1 ]
122126
then
127+
az_cmd=(
128+
"az"
129+
"deployment"
130+
"group"
131+
"create"
132+
"--name" "$template_deployment_name"
133+
"--resource-group" "$resource_group_name"
134+
"--template-file" "$template_file"
135+
"--parameters"
136+
"name=$nginx_cert_name"
137+
"location=$nginx_resource_location"
138+
"nginxDeploymentName=$nginx_deployment_name"
139+
"certificateVirtualPath=$nginx_cert_file"
140+
"keyVirtualPath=$nginx_key_file"
141+
"keyVaultSecretID=$keyvault_secret"
142+
"--verbose"
143+
)
144+
if [[ "$debug" == true ]]; then
145+
az_cmd+=("--debug")
146+
fi
147+
echo "${az_cmd[@]}"
123148
set +e
124-
az deployment group create --name "$template_deployment_name" --resource-group "$resource_group_name" --template-file "$template_file" --parameters name="$nginx_cert_name" location="$nginx_resource_location" nginxDeploymentName="$nginx_deployment_name" certificateVirtualPath="$nginx_cert_file" keyVirtualPath="$nginx_key_file" keyVaultSecretID="$keyvault_secret" --verbose
125-
set -e
126-
else
149+
"${az_cmd[@]}"
150+
set -e
151+
else
127152
echo "Skipping JSON object $i cert deployment with error:$err_msg"
128153
echo ""
129-
fi
154+
fi
130155
done

0 commit comments

Comments
 (0)