added gunicorn

This commit is contained in:
Mohamed Nouffer
2023-05-25 22:41:41 +05:30
parent b59554932d
commit 3afaa09c68
4 changed files with 111 additions and 5 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -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"]

54
docker-compose-prod.yaml Normal file
View File

@ -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:

49
nginx.conf Normal file
View File

@ -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;
}
}
}