diff --git a/.DS_Store b/.DS_Store index 54b0aff..4e171ba 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Dockerfile.gdal b/Dockerfile.gdal index fc6f31a..77fb835 100644 --- a/Dockerfile.gdal +++ b/Dockerfile.gdal @@ -7,26 +7,21 @@ LABEL maintainer="nouffer@gmail.com" LABEL description="Development image for the Rogaining JP" ENV PYTHONDONTWRITEBYTECODE 1 - ENV PYTHONUNBUFFERED 1 ARG TZ Asia/Tokyo \ DEBIAN_FRONTEND=noninteractive - RUN apt-get update -y # Install GDAL dependencies RUN apt-get install -y libgdal-dev g++ --no-install-recommends && \ apt-get clean -y - - # Update C env vars so compiler can find gdal ENV CPLUS_INCLUDE_PATH=/usr/include/gdal ENV C_INCLUDE_PATH=/usr/include/gdal - RUN apt-get update \ && apt-get -y install netcat gcc postgresql \ && apt-get clean @@ -49,6 +44,9 @@ RUN apt-get update COPY ./requirements.txt /app/requirements.txt +# Install Gunicorn +RUN pip install gunicorn + #COPY ./wait-for.sh . #RUN ["chmod", "+x", "wait-for.sh"] @@ -57,3 +55,8 @@ RUN pip install -r requirements.txt COPY . /app +# Collect static files +RUN python manage.py collectstatic --noinput + +# Use Gunicorn as the entrypoint +CMD ["gunicorn", "config.wsgi:application", "--bind", "0.0.0.0:8000"] diff --git a/docker-compose-prod.yaml b/docker-compose-prod.yaml new file mode 100644 index 0000000..fdf7398 --- /dev/null +++ b/docker-compose-prod.yaml @@ -0,0 +1,54 @@ +version: "3.9" + +services: + postgres-db: + image: kartoza/postgis:12.0 + ports: + - 5432:5432 + volumes: + - postgres_data:/var/lib/postgresql + - ./custom-postgresql.conf:/etc/postgresql/12/main/postgresql.conf + environment: + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASS=${POSTGRES_PASS} + - POSTGRES_DBNAME=${POSTGRES_DBNAME} + - POSTGRES_MAX_CONNECTIONS=600 + restart: "on-failure" + networks: + - rog-api + + app: + build: + context: . + dockerfile: Dockerfile.gdal + command: gunicorn config.wsgi:application --bind 0.0.0.0:8000 + volumes: + - .:/app + - static_volume:/app/static + env_file: + - .env + restart: "on-failure" + depends_on: + - postgres-db + networks: + - rog-api + + nginx: + image: nginx:1.19 + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf + - static_volume:/app/static + ports: + - 8100:80 + depends_on: + - app + networks: + - rog-api + +networks: + rog-api: + driver: bridge + +volumes: + postgres_data: + static_volume: diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..0bc6489 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,49 @@ +user nginx; +worker_processes 1; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + #gzip on; + + server { + listen 80; + server_name localhost; + + location /static/ { + alias /app/static/; + } + + location / { + proxy_pass http://app:8000; + 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; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + } +}