Skip to content

Commit

Permalink
Attempt to fix nginx config
Browse files Browse the repository at this point in the history
  • Loading branch information
mauritzs committed Mar 27, 2025
1 parent 9dcf83a commit 9a5f94a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 198 deletions.
111 changes: 16 additions & 95 deletions .github/workflows/update_primary_nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,104 +12,25 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3.6.0
uses: actions/checkout@v3

- 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: Dotenv Action
uses: falti/dotenv-action@v1.1.4
with:
export-variables: true
keys-case: bypass

- 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}"
- name: Check environment variables (can expose secrets so dont be stupid here)
run: env

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: Copy nginx config file to temp file
run: envsubst '$PROD_PORT_PREFIX,$GATEWAY_POSTFIX,$DEV_PORT_PREFIX,$STAG_PORT_PREFIX' < ./nginx_template.txt > nginx_securefit.conf

- name: Backup existing configurations
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 nginx.conf"
fi
if [ -f /etc/nginx/nginx.conf ]; then
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup
echo "Created backup of existing main nginx.conf"
fi
- name: Copy temporary file to correct place
run: sudo cp nginx_securefit.conf /etc/nginx/conf.d/nginx_securefit.conf

- name: Generate server nginx configuration
run: |
if [ ! -f nginx.conf ]; then
echo "Server nginx configuration template not found"
exit 1
fi
envsubst '${DEV_PORT_PREFIX} ${PROD_PORT_PREFIX} ${STAG_PORT_PREFIX} ${GATEWAY_POSTFIX}' < nginx.conf > ./nginx_securefit.conf
- name: Reload Nginx
run: sudo systemctl reload nginx

- name: Generate Docker nginx configuration
run: |
if [ ! -f nginx/nginx.conf ]; then
echo "Docker nginx configuration template not found"
exit 1
fi
cp nginx/nginx.conf ./nginx_docker.conf
- name: Validate configurations
run: |
if ! sudo nginx -t -c ./nginx_securefit.conf; then
echo "Server nginx configuration is invalid"
exit 1
fi
if ! sudo nginx -t -c ./nginx_docker.conf; then
echo "Docker nginx configuration is invalid"
exit 1
fi
- name: Copy configurations to nginx
run: |
sudo cp ./nginx_securefit.conf /etc/nginx/conf.d/nginx.conf || {
echo "Failed to copy server configuration"
exit 1
}
sudo cp ./nginx_docker.conf /etc/nginx/conf.d/nginx_docker.conf || {
echo "Failed to copy Docker 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"
- name: Verify that nginx configuration works
run: sudo nginx -t
72 changes: 0 additions & 72 deletions nginx.conf

This file was deleted.

31 changes: 0 additions & 31 deletions nginx_securefit.conf

This file was deleted.

0 comments on commit 9a5f94a

Please sign in to comment.