Skip to content

Commit

Permalink
Feat: correct update of workflow files (hopefully)
Browse files Browse the repository at this point in the history
  • Loading branch information
mauritzs committed Mar 27, 2025
1 parent 4d04633 commit 09f6770
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 67 deletions.
34 changes: 28 additions & 6 deletions .github/workflows/deploy_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,59 @@ on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
deploy-dev:
runs-on: self-hosted # Ensure you're using your self-hosted runner
runs-on: self-hosted

steps:
- name: Checkout repository
uses: actions/checkout@v3 # Checkout the latest code
uses: actions/checkout@v3.6.0

- name: Check Docker installation
run: |
if ! command -v docker &> /dev/null; then
echo "Docker is not installed"
exit 1
fi
if ! docker info &> /dev/null; then
echo "Docker daemon is not running"
exit 1
fi
# Optionally, set environment variables (if needed)
- name: Set up environment variables
uses: falti/dotenv-action@v1.1.4
with:
export-variables: true
keys-case: bypass

- name: Check environment variables
- name: Check environment variables (should not really be here as you might expose secrets )
run: env

# Remove existing docker containers
- name: Stop and remove existing containers
run: |
docker compose down || true
docker system prune -f || true
# Pull the latest Docker images
- name: Pull latest Docker images
run: docker compose pull || true
run: |
docker compose pull || {
echo "Failed to pull Docker images"
exit 1
}
# Build Docker images if there are any changes
- name: Build Docker images
run: docker compose build --no-cache
run: |
docker compose build --no-cache || {
echo "Failed to build Docker images"
exit 1
}
# Start Docker containers (detached mode)
- name: Start Docker containers
Expand Down
44 changes: 0 additions & 44 deletions .github/workflows/deploy_test.yml

This file was deleted.

77 changes: 60 additions & 17 deletions .github/workflows/update_primary_nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,28 @@ jobs:

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

# 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
- name: Check nginx installation
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"
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}"
Expand All @@ -34,19 +43,53 @@ jobs:
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: Copy variables to conf file
- 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 cp ./nginx_securefit.conf /etc/nginx/conf.d/nginx.conf
sudo nginx -t || {
echo "Nginx configuration test failed"
exit 1
}
- name: Test setup
- name: Reload nginx service
run: |
sudo nginx -t
sudo systemctl reload nginx || {
echo "Failed to reload nginx"
exit 1
}
# Restarting nginx service
- name: Restart nginx service
- name: Verify nginx is running
run: |
sudo systemctl reload nginx
if ! systemctl is-active --quiet nginx; then
echo "Nginx service is not running after reload"
exit 1
fi
echo "Nginx service is running successfully"

0 comments on commit 09f6770

Please sign in to comment.