From 16b4b6fcad3b068ab07ddaf8303dd46c2e4227fa Mon Sep 17 00:00:00 2001 From: bartool Date: Sun, 24 Nov 2024 19:11:41 +0000 Subject: [PATCH] setup nginx docker --- Dockerfile | 13 ---------- docker-compose.yml | 22 +++++++++++++---- nginx/Dockerfile | 4 +++ nginx/nginx.conf | 16 ++++++++++++ web/Dockerfile | 31 ++++++++++++++++++++++++ requirements.txt => web/requirements.txt | 0 6 files changed, 68 insertions(+), 18 deletions(-) delete mode 100644 Dockerfile create mode 100644 nginx/Dockerfile create mode 100644 nginx/nginx.conf create mode 100644 web/Dockerfile rename requirements.txt => web/requirements.txt (100%) diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 86535de..0000000 --- a/Dockerfile +++ /dev/null @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 27f3544..fc72e51 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 0000000..df3b3f4 --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,4 @@ +FROM nginx:latest + +RUN rm /etc/nginx/conf.d/default.conf +COPY nginx.conf /etc/nginx/conf.d \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..3d9f140 --- /dev/null +++ b/nginx/nginx.conf @@ -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; + } + +} \ No newline at end of file diff --git a/web/Dockerfile b/web/Dockerfile new file mode 100644 index 0000000..759ece5 --- /dev/null +++ b/web/Dockerfile @@ -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 \ No newline at end of file diff --git a/requirements.txt b/web/requirements.txt similarity index 100% rename from requirements.txt rename to web/requirements.txt