Skip to content

Commit

Permalink
Merge pull request #11 from SirSanctified/3-the-room-model-does-not-h…
Browse files Browse the repository at this point in the history
…ave-a-field-to-track-the-number-of-beds-that-are-occupied

Update Docker configuration and nginx setup
  • Loading branch information
SirSanctified committed Mar 7, 2024
2 parents 298c841 + 447f24d commit 98d98e3
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 27 deletions.
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build:
docker compose up --build -d --remove-orphans

build-server:
docker compose up --build -d server
docker compose up --build -d api nginx

down:
docker compose down
Expand All @@ -19,16 +19,16 @@ show-logs:
docker compose logs

migrate:
docker compose exec server python3 manage.py migrate
docker compose exec api python3 manage.py migrate

makemigrations:
docker compose exec server python3 manage.py makemigrations
docker compose exec api python3 manage.py makemigrations

superuser:
docker compose exec server python3 manage.py createsuperuser
docker compose exec api python3 manage.py createsuperuser

collectstatic:
docker compose exec server python3 manage.py collectstatic --no-input --clear
docker compose exec api python3 manage.py collectstatic --no-input --clear

down-v:
docker compose down -v
Expand All @@ -37,13 +37,13 @@ roomio-db:
docker compose exec db psql --username=postgres --dbname=postgres

shell:
docker compose exec server python3 manage.py shell
docker compose exec api python3 manage.py shell

test:
docker compose exec server pytest -p no:warnings --cov=.
docker compose exec api pytest -p no:warnings --cov=.

test-html:
docker compose exec server pytest -p no:warnings --cov=. --cov-report=html
docker compose exec api pytest -p no:warnings --cov=. --cov-report=html

stop:
docker compose stop
Expand Down
30 changes: 30 additions & 0 deletions backend/docker/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
upstream api {
server api:8000;
}

server {
client_max_body_size 20M;
listen 80;
server_name api;
location / {
proxy_pass http://api;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}

location /admin {
proxy_pass http://api;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}

location /staticfiles/ {
alias /app/staticfiles/;
}

location /mediafiles/ {
alias /app/mediafiles/;
}
}
5 changes: 5 additions & 0 deletions backend/docker/nginx/nginx.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM nginx:1.25.4

RUN rm /etc/nginx/conf.d/default.conf

COPY ./default.conf /etc/nginx/conf.d/default.conf
13 changes: 3 additions & 10 deletions backend/student_accommodation/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv("DEBUG")

ALLOWED_HOSTS = [
"localhost",
"server",
"server:8000",
"localhost:8000",
"127.0.0.1:8000",
"server:3000",
"localhost:3000",
"127.0.0.1:3000",
]
ALLOWED_HOSTS = ["*"]


# Application definition
Expand Down Expand Up @@ -179,3 +170,5 @@
# CORS
CORS_ALLOW_ALL_ORIGINS = True
CORS_ALLOW_CREDENTIALS = True

CSRF_TRUSTED_ORIGINS = ["http://localhost:8080", "http://localhost:3000"]
32 changes: 23 additions & 9 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ networks:
driver: bridge

services:
server:
container_name: server
image: sirsanctified/server:latest
api:
container_name: api
image: sirsanctified/roomio-api:latest
build:
context: .
dockerfile: ./backend/docker/django/server.dockerfile
command: ./start.sh
ports:
- "8000:8000"
volumes:
- static_volume:/app/staticfiles
- media_volume:/app/mediafiles
Expand Down Expand Up @@ -46,7 +44,7 @@ services:

client:
container_name: client
image: sirsanctified/client:latest
image: sirsanctified/roomio-client:latest
build: ./client
ports:
- "3000:3000"
Expand All @@ -55,7 +53,7 @@ services:
networks:
- student-accommodation
depends_on:
- server
- api
develop:
watch:
- path: ./client
Expand Down Expand Up @@ -83,16 +81,32 @@ services:

pgadmin:
container_name: pgadmin
image: dpage/pgadmin4
image: fenglc/pgadmin4
ports:
- "5050:80"
- "5050:5050"
networks:
- student-accommodation
env_file:
- ./backend/.env
depends_on:
- db

nginx:
restart: always
container_name: nginx
build:
context: ./backend/docker/nginx
dockerfile: nginx.dockerfile
ports:
- "8080:80"
volumes:
- static_volume:/app/staticfiles
- media_volume:/app/mediafiles
networks:
- student-accommodation
depends_on:
- api

volumes:
pg_data:
static_volume:
Expand Down

0 comments on commit 98d98e3

Please sign in to comment.