diff --git a/Dockerfile b/Dockerfile index c41a3fb..1f98816 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ # syntax=docker/dockerfile:1 FROM python:3 +ARG OPERATION RUN useradd -d /code xf RUN mkdir -p /code @@ -18,6 +19,10 @@ WORKDIR /code COPY requirements.txt /code/ RUN python -m venv /venv RUN . /venv/bin/activate && pip install -r requirements.txt + # CMD . /venv/bin/activate && uwsgi --ini /conf/uwsgi.ini -CMD . /venv/bin/activate && uvicorn --reload --reload-include *.html --workers 2 --uds /var/run/socks/app.sock app.asgi:application + +CMD if [ "$OPERATION" = "uwsgi" ] ; then . /venv/bin/activate && uwsgi --ini /conf/uwsgi.ini ; else . /venv/bin/activate && exec python manage.py runserver 0.0.0.0:8000; fi + +# CMD . /venv/bin/activate && uvicorn --reload --reload-include *.html --workers 2 --uds /var/run/socks/app.sock app.asgi:application # CMD . /venv/bin/activate && gunicorn -b 0.0.0.0:8000 --reload app.asgi:application -k uvicorn.workers.UvicornWorker \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 48f53c9..9d6992e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,9 +4,13 @@ services: app: image: xf/envelope:prod container_name: envelope - build: . + build: + context: . + args: + OPERATION: ${OPERATION} volumes: - ${PORTAINER_GIT_DIR}:/code + - ${PORTAINER_GIT_DIR}/docker/uwsgi.ini:/conf/uwsgi.ini - ${APP_DATABASE_FILE}:/conf/db.sqlite3 - app_static:${STATIC_ROOT} #ports: @@ -22,11 +26,17 @@ services: condition: service_started collectstatic: condition: service_started + networks: + - default + - xf migration: image: xf/envelope:prod container_name: migration_envelope - build: . + build: + context: . + args: + OPERATION: ${OPERATION} command: sh -c '. /venv/bin/activate && python manage.py migrate --noinput' volumes: - ${PORTAINER_GIT_DIR}:/code @@ -38,7 +48,10 @@ services: collectstatic: image: xf/envelope:prod container_name: collectstatic_envelope - build: . + build: + context: . + args: + OPERATION: ${OPERATION} command: sh -c '. /venv/bin/activate && python manage.py collectstatic --noinput' volumes: - ${PORTAINER_GIT_DIR}:/code @@ -59,15 +72,17 @@ services: hard: 65535 volumes: - ${PORTAINER_GIT_DIR}:/code - - ${PORTAINER_GIT_DIR}/docker/nginx/conf.d:/etc/nginx/conf.d + - ${PORTAINER_GIT_DIR}/docker/nginx/conf.d/${OPERATION}.conf:/etc/nginx/conf.d/default.conf - app_static:${STATIC_ROOT} volumes_from: - tmp + networks: + - default + - xf depends_on: app: condition: service_started - # volumes_from: # - tmp # depends_on: @@ -101,9 +116,10 @@ services: # retries: 15 networks: - default: - external: - name: xf + default: + driver: bridge + xf: + external: true volumes: app_static: {} diff --git a/docker/nginx/conf.d/default.conf b/docker/nginx/conf.d/dev.conf similarity index 71% rename from docker/nginx/conf.d/default.conf rename to docker/nginx/conf.d/dev.conf index 9633c7b..bd3ab31 100644 --- a/docker/nginx/conf.d/default.conf +++ b/docker/nginx/conf.d/dev.conf @@ -1,6 +1,7 @@ upstream django { #server app:8000; - server unix:///var/run/socks/app.sock; + #server unix:///var/run/socks/app.sock; + server app:8000; } server { @@ -9,11 +10,10 @@ server { location = /favicon.ico { access_log off; log_not_found off; } location /static/ { - root /code/core/; + root /conf; } location / { - include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed proxy_pass http://django; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; diff --git a/docker/nginx/conf.d/uwsgi.conf b/docker/nginx/conf.d/uwsgi.conf new file mode 100644 index 0000000..1e19ae9 --- /dev/null +++ b/docker/nginx/conf.d/uwsgi.conf @@ -0,0 +1,24 @@ +upstream django { + server app:8000; + #server unix:///var/run/socks/app.sock; +} + +server { + listen 9999; + + location = /favicon.ico { access_log off; log_not_found off; } + + location /static/ { + root /conf; + } + + location / { + include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed + uwsgi_pass django; + uwsgi_param Host $host; + uwsgi_param X-Real-IP $remote_addr; + uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for; + uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto; + } + +} \ No newline at end of file diff --git a/docker/uwsgi.ini b/docker/uwsgi.ini new file mode 100644 index 0000000..d70a784 --- /dev/null +++ b/docker/uwsgi.ini @@ -0,0 +1,13 @@ +[uwsgi] +chdir=/code +module=app.wsgi:application +env=DJANGO_SETTINGS_MODULE=app.settings +master=1 +pidfile=/tmp/project-master.pid +socket=0.0.0.0:8000 +processes=5 +harakiri=20 +max-requests=5000 +vacuum=1 +home=/venv + diff --git a/requirements.txt b/requirements.txt index e7b404f..8b2d48d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ wheel +uwsgi django pre-commit django-crispy-forms