From 0d9e9bf6302aab26e6015768c9890f30680b0fd4 Mon Sep 17 00:00:00 2001 From: Ana Barrera Novas Date: Tue, 4 Mar 2025 15:34:30 +0100 Subject: [PATCH] Update update_primary_nginx.yml --- .github/workflows/update_primary_nginx.yml | 35 +++++++++++----------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/.github/workflows/update_primary_nginx.yml b/.github/workflows/update_primary_nginx.yml index 1aac01a..2fb832d 100644 --- a/.github/workflows/update_primary_nginx.yml +++ b/.github/workflows/update_primary_nginx.yml @@ -1,4 +1,4 @@ -name: UNFINISHED - setup nginx from the configuration file +name: Setup Nginx from the Configuration File on: workflow_dispatch: @@ -6,11 +6,12 @@ on: jobs: deploy: runs-on: self-hosted - + steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Dotenv Action + + - name: Load environment variables uses: falti/dotenv-action@v1.1.4 with: export-variables: true @@ -19,22 +20,20 @@ jobs: - name: Check environment variables run: env - - name: Check Runner User - run: whoami + - name: Escape Nginx variables + run: sed -i 's/\$http_host/\\$http_host/g; s/\$remote_addr/\\$remote_addr/g; s/\$proxy_add_x_forwarded_for/\\$proxy_add_x_forwarded_for/g' ./nginx_template.txt + - name: Substitute environment variables + run: envsubst '${PROD_PORT_PREFIX} ${GATEWAY_POSTFIX} ${DEV_PORT_PREFIX} ${STAG_PORT_PREFIX}' < ./nginx_template.txt > temp_default.conf - #Doesn't work properly, envsubst replaces all instances of $variable and ${variable}, but we want to keep e.g., $host as nginx variables - - name: Create temporary nginx config file - run: | - export $(grep -v '^#' .env | xargs) # Load environment variables - envsubst "$(printf '${%s} ' $(env | cut -d= -f1))" < ./nginx_template.txt > temp_default.conf - - #- name: Create temporary nginx config file - # run: envsubst < ./nginx_template.txt > temp_default.conf - # Maybe look at https://www.baeldung.com/linux/envsubst-command to get an idea - - - name: Copy temporary file to correct place - run: cp -L temp_default.conf /etc/nginx/conf.d/default.conf + - name: Copy Nginx config to server + run: sudo cp temp_default.conf /etc/nginx/conf.d/default.conf - - name: Show nginx file + - name: Show updated Nginx config run: cat /etc/nginx/conf.d/default.conf + + - name: Validate Nginx config + run: sudo nginx -t + + - name: Reload Nginx + run: sudo systemctl reload nginx