1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-22 22:39:36 +02:00

Fast. Easy. Fun. Deployment 🚀

This commit is contained in:
Sean Morley 2024-10-25 22:57:10 -04:00
parent 78ab387055
commit ef3f2aee10
3 changed files with 63 additions and 31 deletions

View file

@ -1,5 +1,4 @@
# Dockerfile # Use the official Python slim image as the base image
FROM python:3.10-slim FROM python:3.10-slim
LABEL Developers="Sean Morley" LABEL Developers="Sean Morley"
@ -11,9 +10,9 @@ ENV PYTHONUNBUFFERED 1
# Set the working directory # Set the working directory
WORKDIR /code WORKDIR /code
# Install system dependencies # Install system dependencies (Nginx included)
RUN apt-get update \ RUN apt-get update \
&& apt-get install -y git postgresql-client gdal-bin libgdal-dev \ && apt-get install -y git postgresql-client gdal-bin libgdal-dev nginx \
&& apt-get clean && apt-get clean
# Install Python dependencies # Install Python dependencies
@ -24,10 +23,18 @@ RUN pip install -r requirements.txt
# Copy the Django project code into the Docker image # Copy the Django project code into the Docker image
COPY ./server /code/ COPY ./server /code/
# Copy Nginx configuration
COPY ./nginx.conf /etc/nginx/nginx.conf
# Collect static files # Collect static files
RUN python3 manage.py collectstatic --noinput --verbosity 2 RUN python3 manage.py collectstatic --noinput --verbosity 2
# Set the entrypoint script # Set the entrypoint script
COPY ./entrypoint.sh /code/entrypoint.sh COPY ./entrypoint.sh /code/entrypoint.sh
RUN chmod +x /code/entrypoint.sh RUN chmod +x /code/entrypoint.sh
ENTRYPOINT ["/code/entrypoint.sh"]
# Expose ports for NGINX and Gunicorn
EXPOSE 80 8000
# Command to start Nginx and Gunicorn
CMD ["bash", "-c", "service nginx start && /code/entrypoint.sh"]

38
backend/nginx.conf Normal file
View file

@ -0,0 +1,38 @@
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream django {
server server:8000; # Use the internal Docker networking
}
server {
listen 80; # NGINX always listens on port 80 inside the container
server_name localhost;
location / {
proxy_pass http://server:8000; # Explicitly forward to Django service
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /static/ {
alias /code/staticfiles/; # Serve static files directly
}
location /media/ {
alias /code/media/; # Serve media files directly
}
}
}

View file

@ -1,15 +1,15 @@
services: services:
web: web:
#build: ./frontend/ build: ./frontend/
image: ghcr.io/seanmorley15/adventurelog-frontend:latest #image: ghcr.io/seanmorley15/adventurelog-frontend:latest
container_name: adventurelog-frontend container_name: adventurelog-frontend
restart: unless-stopped restart: unless-stopped
environment: environment:
- PUBLIC_SERVER_URL=http://server:8000 # MOST DOCKER USERS WILL NEVER NEED TO CHANGE THIS, EVEN IF YOU CHANGE THE PORTS - PUBLIC_SERVER_URL=http://server:8000 # MOST DOCKER USERS WILL NOT NEED TO CHANGE THIS EVER EVEN IF YOU CHANGE THE OUTWARD PORT
- ORIGIN=http://localhost:8080 - ORIGIN=http://localhost:8015
- BODY_SIZE_LIMIT=Infinity # This is measured in bytes - BODY_SIZE_LIMIT=Infinity
ports: ports:
- "8080:3000" - "8015:3000"
depends_on: depends_on:
- server - server
@ -25,43 +25,30 @@ services:
- postgres_data:/var/lib/postgresql/data/ - postgres_data:/var/lib/postgresql/data/
server: server:
#build: ./backend/ build: ./backend/
image: ghcr.io/seanmorley15/adventurelog-backend:latest #image: ghcr.io/seanmorley15/adventurelog-backend:latest
container_name: adventurelog-backend container_name: adventurelog-backend
restart: unless-stopped restart: unless-stopped
environment: environment:
- PGHOST=db - PGHOST=db
- PGDATABASE=database - PGDATABASE=database
- PGUSER=adventure - PGUSER=adventure
- PGPASSWORD=changeme123 # This should be the same as the POSTGRES_PASSWORD in the db service - PGPASSWORD=changeme123
- SECRET_KEY=changeme123 - SECRET_KEY=changeme123
- DJANGO_ADMIN_USERNAME=admin - DJANGO_ADMIN_USERNAME=admin
- DJANGO_ADMIN_PASSWORD=admin - DJANGO_ADMIN_PASSWORD=admin
- DJANGO_ADMIN_EMAIL=admin@example.com - DJANGO_ADMIN_EMAIL=admin@example.com
- PUBLIC_URL='http://localhost:81' # NOTE: THIS IS THE PUBLIC URL TO THE **NGINX** SERVER USED FOR MEDIA FILES! - PUBLIC_URL='http://localhost:8016' # Match the outward port, used for the creation of image urls
- CSRF_TRUSTED_ORIGINS=https://api.adventurelog.app,https://adventurelog.app # This is a comma separated list of trusted origins for CSRF, this should include where your frontend is hosted. - CSRF_TRUSTED_ORIGINS=http://localhost:8016 # Comma separated list of trusted origins for CSRF
- DEBUG=False - DEBUG=False
- FRONTEND_URL='http://localhost:8080' # This is the URL of the frontend server - FRONTEND_URL='http://localhost:8015' # Used for email generation. This should be the url of the frontend
#- DISABLE_REGISTRATION=True
ports: ports:
- "8000:8000" - "8016:80" # User can change this to any outward port without breaking the setup
depends_on: depends_on:
- db - db
volumes: volumes:
- adventurelog_media:/code/media/ - adventurelog_media:/code/media/
nginx:
image: nginx:latest
container_name: adventurelog-nginx
restart: unless-stopped
ports:
- "81:80"
volumes:
- adventurelog_media:/app/media
- ./proxy/nginx.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- server
volumes: volumes:
postgres_data: postgres_data:
adventurelog_media: adventurelog_media: