-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Simplication de l'environnement Docker pour le développement (
- Loading branch information
1 parent
7fb1759
commit 90e6988
Showing
11 changed files
with
66 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,31 @@ | ||
version: "3.7" | ||
|
||
services: | ||
postgres: | ||
container_name: bitoubi_postgres | ||
env_file: | ||
- env.docker.local | ||
# The default memory setting (64M) is not enough anymore due to the size of the database we import | ||
db: | ||
# The default memory setting (64M) is not enough anymore due to the size of the database we import | ||
# https://stackoverflow.com/questions/56839975/docker-shm-size-dev-shm-resizing-shared-memory | ||
shm_size: 1g | ||
build: | ||
context: . | ||
dockerfile: ./docker/dev/postgres/Dockerfile | ||
volumes: | ||
- postgres_data:/var/lib/postgresql/data | ||
- ./docker/dev/postgres/psql_init.sh:/docker-entrypoint-initdb.d/postgres-init.sh | ||
restart: always | ||
env_file: | ||
- env.docker.local | ||
ports: | ||
- "${POSTGRESQL_PORT:-5432}:5432" | ||
|
||
bitoubi: | ||
container_name: bitoubi_django | ||
restart: always | ||
app: | ||
build: | ||
context: . | ||
target: dev | ||
dockerfile: ./docker/dev/django/Dockerfile | ||
command: ./docker/dev/django/entrypoint.sh | ||
volumes: | ||
- ./lemarche:/app/lemarche | ||
- ./config:/app/config | ||
environment: | ||
- DEBUG=true | ||
env_file: | ||
- env.docker.local | ||
ports: | ||
- "8880:8880" | ||
depends_on: | ||
- postgres | ||
- db | ||
|
||
volumes: | ||
postgres_data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,66 @@ | ||
# ---------------------------------------------------- | ||
# Base-image | ||
# ---------------------------------------------------- | ||
FROM python:3.10-slim-buster as common-base | ||
# Django directions: https://blog.ploetzli.ch/2020/efficient-multi-stage-build-django-docker/ | ||
# Pip on docker : https://pythonspeed.com/articles/multi-stage-docker-python/ | ||
# https://blog.mikesir87.io/2018/07/leveraging-multi-stage-builds-single-dockerfile-dev-prod/ | ||
# https://pythonspeed.com/articles/base-image-python-docker-images/ | ||
FROM python:3.11.9-slim-bookworm | ||
|
||
# Default environment: Dev | ||
ARG ENV=dev | ||
ENV APP_DIR="/app" | ||
|
||
ENV PYTHONFAULTHANDLER=1 \ | ||
ENV APP_DIR="/app" \ | ||
HOST=0.0.0.0 \ | ||
PORT=8000 \ | ||
PYTHONPATH=. \ | ||
PYTHONFAULTHANDLER=1 \ | ||
PYTHONUNBUFFERED=1 \ | ||
PYTHONDONTWRITEBYTECODE=1 \ | ||
PYTHONHASHSEED=random \ | ||
PIP_NO_CACHE_DIR=off \ | ||
PIP_DISABLE_PIP_VERSION_CHECK=on \ | ||
PIP_DEFAULT_TIMEOUT=100 \ | ||
POETRY_VERSION=1.5.1 \ | ||
POETRY_NO_INTERACTION=1 \ | ||
POETRY_VIRTUALENVS_IN_PROJECT=1 \ | ||
POETRY_VIRTUALENVS_CREATE=1 \ | ||
POETRY_CACHE_DIR=/opt/.cache \ | ||
NODE_VERSION=15 | ||
|
||
ENV HOST=0.0.0.0 \ | ||
PORT=8000 | ||
# Add new user to run the whole thing as non-root. | ||
RUN set -ex \ | ||
&& addgroup app \ | ||
&& adduser --ingroup app --home ${APP_DIR} --disabled-password app; | ||
|
||
WORKDIR /app | ||
WORKDIR $APP_DIR | ||
|
||
COPY install-packages.sh . | ||
RUN ./install-packages.sh | ||
|
||
# ---------------------------------------------------- | ||
# Install dependencies | ||
# ---------------------------------------------------- | ||
FROM common-base AS dependencies | ||
RUN python -m venv /opt/venv | ||
ENV PATH="/opt/venv/bin:$PATH" | ||
|
||
RUN pip install poetry==$POETRY_VERSION | ||
RUN pip install -I uwsgi | ||
|
||
# apt-get install build-essential -y | ||
COPY poetry.lock pyproject.toml /app/ | ||
ENV VIRTUAL_ENV=$APP_DIR/.venv \ | ||
PATH="$APP_DIR/.venv/bin:$PATH" | ||
|
||
RUN poetry config virtualenvs.create false && \ | ||
poetry config virtualenvs.path /opt/venv && \ | ||
poetry install $(test $ENV == "prod" && echo "--no-dev") --no-interaction --no-ansi | ||
# Install Python dependencies | ||
COPY poetry.lock pyproject.toml $APP_DIR | ||
RUN pip install poetry==$POETRY_VERSION && pip install -I uwsgi | ||
RUN poetry install --no-interaction --no-ansi --no-root | ||
|
||
# ---------------------------------------------------- | ||
# Build project | ||
# ---------------------------------------------------- | ||
FROM common-base AS app-run | ||
COPY --from=dependencies /opt/venv /opt/venv | ||
ENV PATH="/opt/venv/bin:$PATH" \ | ||
VIRTUALENV="/opt/venv" \ | ||
PYTHONPATH="$PYTHONPATH:/app/lemarche:/app/config" | ||
COPY ./lemarche ./lemarche | ||
COPY ./config ./config | ||
COPY ./manage.py ./manage.py | ||
COPY ./pyproject.toml ./pyproject.toml | ||
COPY ./docker ./docker | ||
COPY ./scripts ./scripts | ||
|
||
# ---------------------------------------------------- | ||
# Run Dev | ||
# ---------------------------------------------------- | ||
FROM app-run AS dev | ||
ENV DJANGO_SETTINGS_MODULE="config.settings.dev" \ | ||
ENV="dev" \ | ||
DEBUG="True" | ||
|
||
RUN echo '[ ! -z "$TERM" -a -r /etc/motd ] && cat /etc/issue && cat /etc/motd' \ | ||
>> /etc/bash.bashrc \ | ||
; echo "\ | ||
===================================================================\n\ | ||
= Bitoubi Dev Docker container =\n\ | ||
= Le Marché de l'inclusion Dev Docker container =\n\ | ||
===================================================================\n\ | ||
\n\ | ||
(c) plateforme de l'Inclusion\n\ | ||
(c) Plateforme de l'inclusion\n\ | ||
\n\ | ||
Source directory is /app \n\ | ||
\ | ||
Run App with :\n\ | ||
> python ./manage.py runserver \$HOST:\$PORT\n\ | ||
\n\ | ||
"\ | ||
> /etc/motd | ||
|
||
CMD ["bash"] | ||
|
||
# ---------------------------------------------------- | ||
# Run Dev | ||
# ---------------------------------------------------- | ||
FROM app-run AS prod | ||
ENV DJANGO_SETTINGS_MODULE="config.settings.prod" \ | ||
ENV="prod" \ | ||
DEBUG="False" | ||
USER app | ||
|
||
CMD [".docker/dev/django/entrypoint.sh"] | ||
|
||
# # For some _real_ performance, at cost of ease of use: | ||
# FROM python:3.9-alpine as prod | ||
# COPY --from=dependencies /opt/venv /opt/venv | ||
# ENV PATH="/opt/venv/bin:$PATH" | ||
# COPY . . | ||
# RUN apk add python3-dev build-base linux-headers pcre-dev | ||
# RUN pip install uwsgi | ||
CMD ["bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.