Skip to content

Error #1

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GROUP_ID=00
GROUP_ID=05
DOMAIN=localhost
URL_PREFIX=http://
PORT_PREFIX=2
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/deploy_dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy to development

on:
push:
branches:
- main

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

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

# 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
run: env

# Stop and remove existing Docker containers
- name: Stop and remove existing containers
run: |
sudo docker compose down || true
# Pull the latest Docker images (if using remote images)
- name: Pull latest Docker images
run: sudo docker compose pull || true

# Build Docker images if there are any changes
- name: Build Docker images
run: sudo docker compose build --no-cache

# Start Docker containers (detached mode)
- name: Start Docker containers
run: sudo docker compose up -d

# Verify that the containers are running
- name: Verify running Docker containers
run: sudo docker ps -a
9 changes: 5 additions & 4 deletions .github/workflows/deploy_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ jobs:
env:
REPO_NAME: ${{ github.event.repository.name }}
COMPOSE_FILE: ${{ github.event.inputs.config }}

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

- name: Dotenv Action
uses: falti/dotenv-action@v1.1.4
with:
Expand All @@ -35,9 +36,9 @@ jobs:
docker compose version
cd $GITHUB_WORKSPACE
docker compose -f $COMPOSE_FILE --verbose config && printf "OK\n" || exit 1
- name: Build and run docker image
- name: Build and run docker image
run: docker compose -f $COMPOSE_FILE up --force-recreate --build -d

- name: Verify that gateway is available
run: docker ps
63 changes: 41 additions & 22 deletions .github/workflows/update_primary_nginx.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
name: UNFINISHED - setup nginx from the configuration file
name: Deploy nginx configuration to TDT4242 server

on:
push:
branches:
- main
workflow_dispatch:

jobs:
deploy:
deploy-nginx:
runs-on: self-hosted

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Dotenv Action
uses: falti/dotenv-action@v1.1.4
with:
export-variables: true
keys-case: bypass

- name: Check environment variables
run: env

#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: 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 temp_default.conf /etc/nginx/conf.d/default.conf

- name: Show nginx file
run: cat /etc/nginx/conf.d/default.conf

- 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_securefit.conf
- name: Copy variables to conf file
run: |
sudo cp ./nginx_securefit.conf /etc/nginx/conf.d/nginx.conf
- name: Test setup
run: |
sudo nginx -t
# Restarting nginx service
- name: Restart nginx service
run: |
sudo systemctl reload nginx
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
backend/secfit/.vscode/
backend/secfit/*/migrations/__pycache__/
backend/secfit/*/__pycache__/
backend/secfit/db.sqlite3
backend/secfit/db.sqlite3
31 changes: 31 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
server {
listen 80;

location / {
proxy_pass http://0.0.0.0:23/;
proxy_set_header Host ;
proxy_set_header X-Real-IP ;
proxy_set_header X-Forwarded-For ;
}
}

server {
listen 217;
location / {
proxy_pass http://0.0.0.0:21/;
proxy_set_header Host ;
proxy_set_header X-Real-IP ;
proxy_set_header X-Forwarded-For ;
}
}


server {
listen 227;
location / {
proxy_pass http://0.0.0.0:22/;
proxy_set_header Host ;
proxy_set_header X-Real-IP ;
proxy_set_header X-Forwarded-For ;
}
}
2 changes: 1 addition & 1 deletion nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ http {
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
}
31 changes: 31 additions & 0 deletions nginx_securefit.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
server {
listen 80;

location / {
proxy_pass http://0.0.0.0:${PROD_PORT_PREFIX}${GATEWAY_POSTFIX}/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

server {
listen ${DEV_PORT_PREFIX}7;
location / {
proxy_pass http://0.0.0.0:${DEV_PORT_PREFIX}${GATEWAY_POSTFIX}/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}


server {
listen ${STAG_PORT_PREFIX}7;
location / {
proxy_pass http://0.0.0.0:${STAG_PORT_PREFIX}${GATEWAY_POSTFIX}/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}