Feat: correct update of workflow files (hopefully) #53
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: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| deploy-nginx: | |
| runs-on: self-hosted | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3.6.0 | |
| - name: Check nginx installation | |
| run: | | |
| if ! command -v nginx &> /dev/null; then | |
| echo "Nginx is not installed" | |
| exit 1 | |
| fi | |
| if ! systemctl is-active --quiet nginx; then | |
| echo "Nginx service is not running" | |
| exit 1 | |
| fi | |
| - name: Set up environment variables | |
| env: | |
| GROUP_ID: ${{ secrets.GROUP_ID }} | |
| PORT_PREFIX: ${{ secrets.PORT_PREFIX }} | |
| DEV_POSTFIX: ${{ secrets.DEV_POSTFIX }} | |
| STAG_POSTFIX: ${{ secrets.STAG_POSTFIX }} | |
| PROD_POSTFIX: ${{ secrets.PROD_POSTFIX }} | |
| GATEWAY_POSTFIX: ${{ secrets.GATEWAY_POSTFIX }} | |
| run: | | |
| 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: Backup existing configuration | |
| run: | | |
| if [ -f /etc/nginx/conf.d/nginx.conf ]; then | |
| sudo cp /etc/nginx/conf.d/nginx.conf /etc/nginx/conf.d/nginx.conf.backup | |
| echo "Created backup of existing configuration" | |
| fi | |
| - name: Replace environment variables in Nginx config | |
| run: | | |
| if [ ! -f nginx_template.txt ]; then | |
| echo "Nginx template file not found" | |
| exit 1 | |
| fi | |
| envsubst '${DEV_PORT_PREFIX} ${PROD_PORT_PREFIX} ${STAG_PORT_PREFIX} ${GATEWAY_POSTFIX}' < nginx_template.txt > ./nginx_securefit.conf | |
| - name: Validate new configuration | |
| run: | | |
| if ! sudo nginx -t -c ./nginx_securefit.conf; then | |
| echo "New nginx configuration is invalid" | |
| exit 1 | |
| fi | |
| - name: Copy configuration to nginx | |
| run: | | |
| sudo cp ./nginx_securefit.conf /etc/nginx/conf.d/nginx.conf || { | |
| echo "Failed to copy new configuration" | |
| exit 1 | |
| } | |
| - name: Test nginx configuration | |
| run: | | |
| sudo nginx -t || { | |
| echo "Nginx configuration test failed" | |
| exit 1 | |
| } | |
| - name: Reload nginx service | |
| run: | | |
| sudo systemctl reload nginx || { | |
| echo "Failed to reload nginx" | |
| exit 1 | |
| } | |
| - name: Verify nginx is running | |
| run: | | |
| if ! systemctl is-active --quiet nginx; then | |
| echo "Nginx service is not running after reload" | |
| exit 1 | |
| fi | |
| echo "Nginx service is running successfully" |