Skip to content

Commit

Permalink
💚(docker) adapt dockerfile with people updates
Browse files Browse the repository at this point in the history
Adapt the dockerfile to include the new
people updates, plus adapt to impress project.
  • Loading branch information
AntoLC committed Apr 4, 2024
1 parent fa58c19 commit 0048d61
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 38 deletions.
82 changes: 70 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,63 @@
# Django impress

# ---- 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
RUN python -m pip install --upgrade pip

# Upgrade system packages to install security updates
# python3-pip python3-cffi python3-brotli \
RUN apt-get update && \
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/*

### ---- 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 ----
FROM base as back-builder

Expand All @@ -26,8 +69,9 @@ COPY ./src/backend /builder
RUN mkdir /install && \
pip install --prefix=/install .


# ---- mails ----
FROM node:18 as mail-builder
FROM node:20 as mail-builder

COPY ./src/mail /mail/app

Expand All @@ -36,13 +80,15 @@ WORKDIR /mail/app
RUN yarn install --frozen-lockfile && \
yarn build


# ---- static 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 && \
apt-get install -y \
libpangocairo-1.0-0 \
rdfind && \
rm -rf /var/lib/apt/lists/*

Expand All @@ -55,7 +101,7 @@ COPY ./src/backend /app/
WORKDIR /app

# collectstatic
RUN DJANGO_CONFIGURATION=Build \
RUN DJANGO_CONFIGURATION=Build DJANGO_JWT_PRIVATE_SIGNING_KEY=Dummy \
python manage.py collectstatic --noinput

# Replace duplicated file by a symlink to decrease the overall size of the
Expand All @@ -67,6 +113,18 @@ FROM base as core

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 ./docker/files/usr/local/bin/entrypoint /usr/local/bin/entrypoint

Expand All @@ -89,7 +147,7 @@ WORKDIR /app
ENTRYPOINT [ "/usr/local/bin/entrypoint" ]

# ---- Development image ----
FROM core as development
FROM core as backend-development

# Switch back to the root user to install development dependencies
USER root:root
Expand All @@ -114,10 +172,10 @@ ENV DB_HOST=postgresql \
DB_PORT=5432

# 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 ----
FROM core as production
FROM core as backend-production

ARG IMPRESS_STATIC_ROOT=/data/static

Expand Down
15 changes: 7 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ services:
app-dev:
build:
context: .
target: development
target: backend-development
args:
DOCKER_USER: ${DOCKER_USER:-1000}
user: ${DOCKER_USER:-1000}
image: impress:development
image: impress:backend-development
environment:
- PYLINTHOME=/app/.pylint.d
- DJANGO_CONFIGURATION=Development
Expand All @@ -43,7 +43,7 @@ services:

celery-dev:
user: ${DOCKER_USER:-1000}
image: impress:development
image: impress:backend-development
command: ["celery", "-A", "impress.celery_app", "worker", "-l", "DEBUG"]
environment:
- DJANGO_CONFIGURATION=Development
Expand All @@ -60,11 +60,11 @@ services:
app:
build:
context: .
target: production
target: backend-production
args:
DOCKER_USER: ${DOCKER_USER:-1000}
user: ${DOCKER_USER:-1000}
image: impress:production
image: impress:backend-production
environment:
- DJANGO_CONFIGURATION=Demo
env_file:
Expand All @@ -78,7 +78,7 @@ services:

celery:
user: ${DOCKER_USER:-1000}
image: impress:production
image: impress:backend-production
command: ["celery", "-A", "impress.celery_app", "worker", "-l", "INFO"]
environment:
- DJANGO_CONFIGURATION=Demo
Expand All @@ -91,11 +91,9 @@ services:
nginx:
image: nginx:1.25
ports:
- "8082:8082"
- "8083:8083"
volumes:
- ./docker/files/etc/nginx/conf.d:/etc/nginx/conf.d:ro
- ./data/media:/data/media:ro
depends_on:
- app
- keycloak
Expand Down Expand Up @@ -138,6 +136,7 @@ services:

kc_postgresql:
image: postgres:14.3
platform: linux/amd64
ports:
- "5433:5432"
env_file:
Expand Down
18 changes: 0 additions & 18 deletions docker/files/etc/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -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 {
listen 8083;
Expand Down

0 comments on commit 0048d61

Please sign in to comment.