Deploy nginx configuration to TDT4242 server #42
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy nginx configuration to TDT4242 server | |
| on: | |
| # push: | |
| # branches: | |
| # - main | |
| workflow_dispatch: | |
| jobs: | |
| deploy-nginx: | |
| runs-on: self-hosted | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| # This is bad practise as environment variables should be stored in a secure location, but hey it works now. | |
| # Can be fixed through utilizing predefined custom workflow, or github runners-secrets | |
| - name: Export environment variables | |
| run: | | |
| export GROUP_ID="05" | |
| export PORT_PREFIX="2" | |
| export DEV_POSTFIX="1" | |
| export STAG_POSTFIX="2" | |
| export PROD_POSTFIX="3" | |
| export GATEWAY_POSTFIX="6" | |
| export DEV_PORT_PREFIX="${PORT_PREFIX}${GROUP_ID}${DEV_POSTFIX}" | |
| export STAG_PORT_PREFIX="${PORT_PREFIX}${GROUP_ID}${STAG_POSTFIX}" | |
| export PROD_PORT_PREFIX="${PORT_PREFIX}${GROUP_ID}${PROD_POSTFIX}" | |
| echo "DEV_PORT_PREFIX=$DEV_PORT_PREFIX" >> $GITHUB_ENV | |
| echo "STAG_PORT_PREFIX=$STAG_PORT_PREFIX" >> $GITHUB_ENV | |
| echo "PROD_PORT_PREFIX=$PROD_PORT_PREFIX" >> $GITHUB_ENV | |
| echo "GATEWAY_POSTFIX=$GATEWAY_POSTFIX" >> $GITHUB_ENV | |
| - name: Replace environment variables in Nginx config | |
| run: | | |
| envsubst '${DEV_PORT_PREFIX} ${PROD_PORT_PREFIX} ${STAG_PORT_PREFIX} ${GATEWAY_POSTFIX}' < nginx_template.txt > nginx_secfit.conf | |
| - name: Copy variables to conf file | |
| run: | | |
| sudo cp nginx_secfit.conf /etc/nginx/conf.d/nginx.conf | |
| - name: Test setup | |
| run: | | |
| sudo nginx -t | |
| # Restarting nginx service | |
| - name: Restart nginx service | |
| run: | | |
| sudo systemctl restart nginx |