setup nginx docker

This commit is contained in:
2024-11-24 19:11:41 +00:00
parent d3a01fe93d
commit 16b4b6fcad
6 changed files with 68 additions and 18 deletions

View File

@@ -1,13 +0,0 @@
FROM python:3-slim
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt

View File

@@ -1,10 +1,22 @@
services:
web:
build: .
build: ./web
command: gunicorn bartool_ovh.wsgi:application --bind 0.0.0.0:8000
volumes:
- ./app/:/usr/src/app/
ports:
- 8100:8000
- ./app/:/home/app/web
expose:
- 8000
env_file:
- ./env.dev
- ./web/env.dev
nginx:
build: ./nginx
volumes:
- static_volume:/home/app/web/staticfiles
ports:
- 1337:80
depends_on:
- web
volumes:
static_volume:

4
nginx/Dockerfile Normal file
View File

@@ -0,0 +1,4 @@
FROM nginx:latest
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d

16
nginx/nginx.conf Normal file
View File

@@ -0,0 +1,16 @@
upstream bartool_ovh {
server web:8000;
}
server {
listen 80;
location / {
proxy_pass http://bartool_ovh;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
}

31
web/Dockerfile Normal file
View File

@@ -0,0 +1,31 @@
FROM python:3-slim
# set work directory
# WORKDIR /usr/src/app
# create directory for the app user
RUN mkdir -p /home/app
# create the app user
RUN addgroup --system app && adduser --system --group app
# create the appropriate directories
ENV HOME=/home/app
ENV APP_HOME=/home/app/web
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt
# chown all the files to the app user
RUN chown -R app:app $APP_HOME
# change to the app user
USER app