From 537b5ad4be595ac793acaac91d543ab23118c894 Mon Sep 17 00:00:00 2001 From: WP Studio Date: Tue, 8 Apr 2025 17:13:21 +0300 Subject: [PATCH] + python services and python nginx conf example + also example of Dockerfile for python project and needed to place onto your project directory --- .env.example | 1 + config/nginx/conf.d/z-python.conf.example | 2 +- docker-compose.base.yml | 1 + docker-compose.python.yml.example | 16 ++++++++++++++++ dockerfiles/python/Dockerfile.example | 27 +++++++++++++++++++++++++++ dockerfiles/python/README.md | 2 ++ 6 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 docker-compose.python.yml.example create mode 100644 dockerfiles/python/Dockerfile.example create mode 100644 dockerfiles/python/README.md diff --git a/.env.example b/.env.example index 7fed70d..00687ae 100644 --- a/.env.example +++ b/.env.example @@ -3,6 +3,7 @@ # For UFW allowing ports on the host system: ufw allow to 172.18.0.1 port 9000,9003 DOCKER_HOST_IP=172.18.0.1 PROJECTS_DIR=/home/youruser/PhpstormProjects +PYTHON_PROJECTS_DIR=/home/dimti/PythonProjects ### Common ############################################### CUSTOM_TZ=Europe/Moscow diff --git a/config/nginx/conf.d/z-python.conf.example b/config/nginx/conf.d/z-python.conf.example index 386ab6c..7b3dcc0 100644 --- a/config/nginx/conf.d/z-python.conf.example +++ b/config/nginx/conf.d/z-python.conf.example @@ -1,5 +1,5 @@ map $http_host $python_upstream { - someproject.local.wpstudio.ru http://workspace74:8000; + someproject.local.wpstudio.ru http://python-someproject:8000; } map $http_host $python_root { diff --git a/docker-compose.base.yml b/docker-compose.base.yml index 0fe216c..5e5701f 100755 --- a/docker-compose.base.yml +++ b/docker-compose.base.yml @@ -4,6 +4,7 @@ services: restart: always volumes: - ${PROJECTS_DIR}:/usr/share/nginx/html + - ${PYTHON_PROJECTS_DIR}:/usr/share/nginx/python - ./config/nginx/conf.d:/etc/nginx/conf.d - ./config/nginx/includes.d:/etc/nginx/includes.d - ./config/nginx/ssl.d:/etc/nginx/ssl.d diff --git a/docker-compose.python.yml.example b/docker-compose.python.yml.example new file mode 100755 index 0000000..93cda52 --- /dev/null +++ b/docker-compose.python.yml.example @@ -0,0 +1,16 @@ +services: + python-someproject: + user: ${WORKSPACE_PUID}:${WORKSPACE_PGID} + build: + context: ${PYTHON_PROJECTS_DIR}/someproject + args: + - PUID=${WORKSPACE_PUID} + - PGID=${WORKSPACE_PGID} + - PYTHON_VERSION=3.9.20 + volumes: + - ${PYTHON_PROJECTS_DIR}/someproject:/app + command: bash --init-file /venv/bin/activate -c " + python manage.py migrate + && python manage.py collectstatic + && uvicorn 'APP_NAME.asgi:application' --host 0.0.0.0 + " \ No newline at end of file diff --git a/dockerfiles/python/Dockerfile.example b/dockerfiles/python/Dockerfile.example new file mode 100644 index 0000000..2aa9d6b --- /dev/null +++ b/dockerfiles/python/Dockerfile.example @@ -0,0 +1,27 @@ +ARG PYTHON_VERSION +FROM python:${PYTHON_VERSION} + +ARG PUID=1000 +ARG PGID=1000 + +RUN groupadd -g ${PGID} pydock && \ + useradd -u ${PUID} -g pydock -m pydock && \ + usermod -p "*" pydock -s /bin/bash + +RUN mkdir /venv && chown ${PUID}:${PGID} /venv + +USER pydock + +# Создаём виртуальное окружение ВНЕ /app +RUN python -m venv /venv +ENV PATH="/venv/bin:$PATH" + +WORKDIR /app + +COPY requirements.txt . + +VOLUME /pip_cache + +RUN . /venv/bin/activate && pip install --cache-dir=/pip_cache -r requirements.txt + +EXPOSE 8000 \ No newline at end of file diff --git a/dockerfiles/python/README.md b/dockerfiles/python/README.md new file mode 100644 index 0000000..c2a45e5 --- /dev/null +++ b/dockerfiles/python/README.md @@ -0,0 +1,2 @@ +Как вы уже поняли, это файл должен лежать в корневой директории проекта, +так как нужно копировать от туда requirements.txt при сборке образа. \ No newline at end of file