💚(docker) adapt dockerfile with people updates

Adapt the dockerfile to include the new
people updates, plus adapt to impress project.
This commit is contained in:
Anthony LC
2024-04-04 14:06:03 +02:00
committed by Anthony LC
parent ca0571cb21
commit 007a9ae4f4
3 changed files with 77 additions and 38 deletions

View File

@@ -1,20 +1,63 @@
# Django impress # Django impress
# ---- base image to inherit from ---- # ---- base image to inherit from ----
FROM python:3.10-slim-bookworm as base FROM python:3.10-slim-bullseye as base
# Upgrade pip to its latest release to speed up dependencies installation # Upgrade pip to its latest release to speed up dependencies installation
RUN python -m pip install --upgrade pip RUN python -m pip install --upgrade pip
# Upgrade system packages to install security updates # Upgrade system packages to install security updates
# python3-pip python3-cffi python3-brotli \
RUN apt-get update && \ RUN apt-get update && \
apt-get -y upgrade && \ apt-get -y upgrade && \
apt-get -y install \
gettext \
libpango-1.0-0 libpangoft2-1.0-0 pango1.0-tools && \
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
### ---- Front-end dependencies image ----
FROM node:20 as frontend-deps
WORKDIR /deps
COPY ./src/frontend/package.json ./package.json
COPY ./src/frontend/yarn.lock ./yarn.lock
COPY ./src/frontend/apps/impress/package.json ./apps/impress/package.json
COPY ./src/frontend/packages/i18n/package.json ./packages/i18n/package.json
COPY ./src/frontend/packages/eslint-config-impress/package.json ./packages/eslint-config-impress/package.json
RUN yarn --frozen-lockfile
### ---- Front-end builder image ----
FROM node:20 as frontend-builder
WORKDIR /builder
COPY --from=frontend-deps /deps/node_modules ./node_modules
COPY ./src/frontend .
WORKDIR /builder/apps/impress
RUN yarn build
# ---- Front-end image ----
FROM nginxinc/nginx-unprivileged:1.25 as frontend-production
# Un-privileged user running the application
ARG DOCKER_USER
USER ${DOCKER_USER}
COPY --from=frontend-builder \
/builder/apps/impress/out \
/usr/share/nginx/html
COPY ./src/frontend/apps/impress/conf/default.conf /etc/nginx/conf.d
# Copy entrypoint
COPY ./docker/files/usr/local/bin/entrypoint /usr/local/bin/entrypoint
ENTRYPOINT [ "/usr/local/bin/entrypoint" ]
CMD ["nginx", "-g", "daemon off;"]
# ---- Back-end builder image ---- # ---- Back-end builder image ----
FROM base as back-builder FROM base as back-builder
@@ -26,8 +69,9 @@ COPY ./src/backend /builder
RUN mkdir /install && \ RUN mkdir /install && \
pip install --prefix=/install . pip install --prefix=/install .
# ---- mails ---- # ---- mails ----
FROM node:18 as mail-builder FROM node:20 as mail-builder
COPY ./src/mail /mail/app COPY ./src/mail /mail/app
@@ -36,13 +80,15 @@ WORKDIR /mail/app
RUN yarn install --frozen-lockfile && \ RUN yarn install --frozen-lockfile && \
yarn build yarn build
# ---- static link collector ---- # ---- static link collector ----
FROM base as link-collector FROM base as link-collector
ARG IMPRESS_STATIC_ROOT=/data/static ARG PEOPLE_STATIC_ROOT=/data/static
# Install rdfind # Install libpangocairo & rdfind
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y \ apt-get install -y \
libpangocairo-1.0-0 \
rdfind && \ rdfind && \
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
@@ -55,7 +101,7 @@ COPY ./src/backend /app/
WORKDIR /app WORKDIR /app
# collectstatic # collectstatic
RUN DJANGO_CONFIGURATION=Build \ RUN DJANGO_CONFIGURATION=Build DJANGO_JWT_PRIVATE_SIGNING_KEY=Dummy \
python manage.py collectstatic --noinput python manage.py collectstatic --noinput
# Replace duplicated file by a symlink to decrease the overall size of the # Replace duplicated file by a symlink to decrease the overall size of the
@@ -67,6 +113,18 @@ FROM base as core
ENV PYTHONUNBUFFERED=1 ENV PYTHONUNBUFFERED=1
# Install required system libs
RUN apt-get update && \
apt-get install -y \
gettext \
libcairo2 \
libffi-dev \
libgdk-pixbuf2.0-0 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
shared-mime-info && \
rm -rf /var/lib/apt/lists/*
# Copy entrypoint # Copy entrypoint
COPY ./docker/files/usr/local/bin/entrypoint /usr/local/bin/entrypoint COPY ./docker/files/usr/local/bin/entrypoint /usr/local/bin/entrypoint
@@ -89,7 +147,7 @@ WORKDIR /app
ENTRYPOINT [ "/usr/local/bin/entrypoint" ] ENTRYPOINT [ "/usr/local/bin/entrypoint" ]
# ---- Development image ---- # ---- Development image ----
FROM core as development FROM core as backend-development
# Switch back to the root user to install development dependencies # Switch back to the root user to install development dependencies
USER root:root USER root:root
@@ -114,10 +172,10 @@ ENV DB_HOST=postgresql \
DB_PORT=5432 DB_PORT=5432
# Run django development server # Run django development server
CMD python manage.py runserver 0.0.0.0:8000 CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
# ---- Production image ---- # ---- Production image ----
FROM core as production FROM core as backend-production
ARG IMPRESS_STATIC_ROOT=/data/static ARG IMPRESS_STATIC_ROOT=/data/static

View File

@@ -19,11 +19,11 @@ services:
app-dev: app-dev:
build: build:
context: . context: .
target: development target: backend-development
args: args:
DOCKER_USER: ${DOCKER_USER:-1000} DOCKER_USER: ${DOCKER_USER:-1000}
user: ${DOCKER_USER:-1000} user: ${DOCKER_USER:-1000}
image: impress:development image: impress:backend-development
environment: environment:
- PYLINTHOME=/app/.pylint.d - PYLINTHOME=/app/.pylint.d
- DJANGO_CONFIGURATION=Development - DJANGO_CONFIGURATION=Development
@@ -43,7 +43,7 @@ services:
celery-dev: celery-dev:
user: ${DOCKER_USER:-1000} user: ${DOCKER_USER:-1000}
image: impress:development image: impress:backend-development
command: ["celery", "-A", "impress.celery_app", "worker", "-l", "DEBUG"] command: ["celery", "-A", "impress.celery_app", "worker", "-l", "DEBUG"]
environment: environment:
- DJANGO_CONFIGURATION=Development - DJANGO_CONFIGURATION=Development
@@ -60,11 +60,11 @@ services:
app: app:
build: build:
context: . context: .
target: production target: backend-production
args: args:
DOCKER_USER: ${DOCKER_USER:-1000} DOCKER_USER: ${DOCKER_USER:-1000}
user: ${DOCKER_USER:-1000} user: ${DOCKER_USER:-1000}
image: impress:production image: impress:backend-production
environment: environment:
- DJANGO_CONFIGURATION=Demo - DJANGO_CONFIGURATION=Demo
env_file: env_file:
@@ -78,7 +78,7 @@ services:
celery: celery:
user: ${DOCKER_USER:-1000} user: ${DOCKER_USER:-1000}
image: impress:production image: impress:backend-production
command: ["celery", "-A", "impress.celery_app", "worker", "-l", "INFO"] command: ["celery", "-A", "impress.celery_app", "worker", "-l", "INFO"]
environment: environment:
- DJANGO_CONFIGURATION=Demo - DJANGO_CONFIGURATION=Demo
@@ -91,11 +91,9 @@ services:
nginx: nginx:
image: nginx:1.25 image: nginx:1.25
ports: ports:
- "8082:8082"
- "8083:8083" - "8083:8083"
volumes: volumes:
- ./docker/files/etc/nginx/conf.d:/etc/nginx/conf.d:ro - ./docker/files/etc/nginx/conf.d:/etc/nginx/conf.d:ro
- ./data/media:/data/media:ro
depends_on: depends_on:
- app - app
- keycloak - keycloak
@@ -138,6 +136,7 @@ services:
kc_postgresql: kc_postgresql:
image: postgres:14.3 image: postgres:14.3
platform: linux/amd64
ports: ports:
- "5433:5432" - "5433:5432"
env_file: env_file:

View File

@@ -1,21 +1,3 @@
server {
listen 8082;
server_name localhost;
charset utf-8;
location /media {
alias /data/media;
}
location / {
proxy_pass http://app:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server { server {
listen 8083; listen 8083;