2024-03-01 13:47:11 +03:00
|
|
|
##### Important information for maintaining this Dockerfile ########################################
|
|
|
|
# Read the docs/topics/development/docker.md file for more information about this Dockerfile.
|
|
|
|
####################################################################################################
|
|
|
|
|
2024-09-16 11:42:45 +03:00
|
|
|
FROM python:3.11-slim-bookworm AS olympia
|
2014-10-01 15:44:44 +04:00
|
|
|
|
2024-06-25 13:08:39 +03:00
|
|
|
# Set shell to bash with logs and errors for build
|
|
|
|
SHELL ["/bin/bash", "-xue", "-c"]
|
|
|
|
|
2024-05-06 15:07:55 +03:00
|
|
|
ENV OLYMPIA_UID=9500
|
2024-05-06 13:50:34 +03:00
|
|
|
RUN <<EOF
|
2024-05-06 15:07:55 +03:00
|
|
|
groupadd -g ${OLYMPIA_UID} olympia
|
|
|
|
useradd -u ${OLYMPIA_UID} -g ${OLYMPIA_UID} -s /sbin/nologin -d /data/olympia olympia
|
2024-05-06 13:50:34 +03:00
|
|
|
EOF
|
|
|
|
|
|
|
|
# give olympia access to the HOME directory
|
2024-09-16 11:42:45 +03:00
|
|
|
ENV HOME=/data/olympia
|
2024-05-06 13:50:34 +03:00
|
|
|
WORKDIR ${HOME}
|
|
|
|
RUN chown -R olympia:olympia ${HOME}
|
|
|
|
|
2024-09-16 11:42:45 +03:00
|
|
|
FROM olympia AS base
|
2020-11-06 14:20:43 +03:00
|
|
|
# Add keys and repos for node and mysql
|
2024-05-06 13:50:34 +03:00
|
|
|
# TODO: replace this with a bind mount on the RUN command
|
|
|
|
COPY docker/*.gpg.asc /etc/apt/trusted.gpg.d/
|
2020-11-06 14:20:43 +03:00
|
|
|
COPY docker/*.list /etc/apt/sources.list.d/
|
2017-07-28 23:51:18 +03:00
|
|
|
|
2024-05-06 13:50:34 +03:00
|
|
|
RUN <<EOF
|
|
|
|
# Add support for https apt repos and gpg signed repos
|
|
|
|
apt-get update
|
|
|
|
apt-get install -y apt-transport-https gnupg2
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
EOF
|
2017-05-10 23:39:09 +03:00
|
|
|
|
2024-05-06 13:50:34 +03:00
|
|
|
RUN --mount=type=bind,source=docker/debian_packages.txt,target=/debian_packages.txt \
|
2024-06-25 13:08:39 +03:00
|
|
|
<<EOF
|
|
|
|
# Allow scripts to detect we are running in our own container
|
2024-05-06 13:50:34 +03:00
|
|
|
touch /addons-server-docker-container
|
|
|
|
# install packages.
|
|
|
|
apt-get update
|
2024-06-25 13:08:39 +03:00
|
|
|
grep -v '^#' /debian_packages.txt | xargs apt-get -y install
|
2024-05-06 13:50:34 +03:00
|
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
EOF
|
2020-04-08 12:54:04 +03:00
|
|
|
|
2016-12-13 20:22:32 +03:00
|
|
|
# Compile required locale
|
|
|
|
RUN localedef -i en_US -f UTF-8 en_US.UTF-8
|
2024-09-16 11:42:45 +03:00
|
|
|
ENV LANG=en_US.UTF-8
|
|
|
|
ENV LC_ALL=en_US.UTF-8
|
2016-12-13 20:22:32 +03:00
|
|
|
|
2024-05-06 13:50:34 +03:00
|
|
|
RUN <<EOF
|
|
|
|
# Create directory for dependencies
|
|
|
|
mkdir /deps
|
|
|
|
chown -R olympia:olympia /deps
|
2023-03-23 17:46:56 +03:00
|
|
|
|
2024-05-06 13:50:34 +03:00
|
|
|
|
|
|
|
# For backwards-compatibility purposes, set up links to uwsgi. Note that
|
2024-06-25 13:08:39 +03:00
|
|
|
# the target does not exist yet at this point, but it will later.
|
2024-05-06 13:50:34 +03:00
|
|
|
ln -s /deps/bin/uwsgi /usr/bin/uwsgi
|
|
|
|
ln -s /usr/bin/uwsgi /usr/sbin/uwsgi
|
2023-03-23 17:46:56 +03:00
|
|
|
|
2024-05-06 13:50:34 +03:00
|
|
|
# link to the package*.json at ${HOME} so npm can install in /deps
|
|
|
|
ln -s ${HOME}/package.json /deps/package.json
|
|
|
|
ln -s ${HOME}/package-lock.json /deps/package-lock.json
|
2024-11-12 18:32:27 +03:00
|
|
|
|
|
|
|
# Create the storage directory and the test file to verify nginx routing
|
|
|
|
mkdir -p ${HOME}/storage
|
|
|
|
chown -R olympia:olympia ${HOME}/storage
|
2024-05-06 13:50:34 +03:00
|
|
|
EOF
|
2023-03-23 17:46:56 +03:00
|
|
|
|
|
|
|
USER olympia:olympia
|
|
|
|
|
|
|
|
ENV PIP_USER=true
|
2016-05-17 15:07:33 +03:00
|
|
|
ENV PIP_BUILD=/deps/build/
|
|
|
|
ENV PIP_CACHE_DIR=/deps/cache/
|
|
|
|
ENV PIP_SRC=/deps/src/
|
2019-10-22 12:24:05 +03:00
|
|
|
ENV PYTHONUSERBASE=/deps
|
2024-09-16 11:42:45 +03:00
|
|
|
ENV PATH=$PYTHONUSERBASE/bin:$PATH
|
2016-05-19 12:26:46 +03:00
|
|
|
ENV NPM_CONFIG_PREFIX=/deps/
|
2024-03-01 13:47:11 +03:00
|
|
|
ENV NPM_CACHE_DIR=/deps/cache/npm
|
|
|
|
ENV NPM_DEBUG=true
|
2024-06-21 16:19:29 +03:00
|
|
|
# Set python path to the project root and src to resolve olympia modules correctly
|
|
|
|
ENV PYTHONPATH=${HOME}:${HOME}/src
|
2024-03-01 13:47:11 +03:00
|
|
|
|
2024-09-16 11:42:45 +03:00
|
|
|
ENV PIP_COMMAND="python3 -m pip"
|
|
|
|
ENV NPM_ARGS="--prefix ${NPM_CONFIG_PREFIX} --cache ${NPM_CACHE_DIR} --loglevel verbose"
|
|
|
|
|
2024-05-06 13:50:34 +03:00
|
|
|
# All we need in "base" is pip to be installed
|
|
|
|
#this let's other layers install packages using the correct version.
|
2024-03-01 13:47:11 +03:00
|
|
|
RUN \
|
|
|
|
# Files required to install pip dependencies
|
2024-05-06 13:50:34 +03:00
|
|
|
--mount=type=bind,source=./requirements/pip.txt,target=${HOME}/requirements/pip.txt \
|
|
|
|
--mount=type=cache,target=${PIP_CACHE_DIR},uid=${OLYMPIA_UID},gid=${OLYMPIA_UID} \
|
2024-09-16 11:42:45 +03:00
|
|
|
<<EOF
|
|
|
|
# Work arounds "Multiple .dist-info directories" issue.
|
|
|
|
rm -rf /deps/build/*
|
|
|
|
${PIP_COMMAND} install --progress-bar=off --no-deps --exists-action=w -r requirements/pip.txt
|
|
|
|
EOF
|
2024-05-06 13:50:34 +03:00
|
|
|
|
2024-10-18 18:39:49 +03:00
|
|
|
# Expose the DOCKER_TARGET variable to all subsequent stages
|
|
|
|
# This value is used to determine if we are building for production or development
|
|
|
|
ARG DOCKER_TARGET
|
|
|
|
ENV DOCKER_TARGET=${DOCKER_TARGET}
|
|
|
|
|
2024-05-06 13:50:34 +03:00
|
|
|
# Define production dependencies as a single layer
|
|
|
|
# let's the rest of the stages inherit prod dependencies
|
|
|
|
# and makes copying the /deps dir to the final layer easy.
|
2024-09-16 11:42:45 +03:00
|
|
|
FROM base AS pip_production
|
2024-05-06 13:50:34 +03:00
|
|
|
|
|
|
|
RUN \
|
|
|
|
# Files required to install pip dependencies
|
|
|
|
--mount=type=bind,source=./requirements/prod.txt,target=${HOME}/requirements/prod.txt \
|
2024-03-01 13:47:11 +03:00
|
|
|
# Files required to install npm dependencies
|
|
|
|
--mount=type=bind,source=package.json,target=${HOME}/package.json \
|
|
|
|
--mount=type=bind,source=package-lock.json,target=${HOME}/package-lock.json \
|
|
|
|
# Mounts for caching dependencies
|
2024-05-06 15:07:55 +03:00
|
|
|
--mount=type=cache,target=${PIP_CACHE_DIR},uid=${OLYMPIA_UID},gid=${OLYMPIA_UID} \
|
|
|
|
--mount=type=cache,target=${NPM_CACHE_DIR},uid=${OLYMPIA_UID},gid=${OLYMPIA_UID} \
|
2024-09-16 11:42:45 +03:00
|
|
|
<<EOF
|
|
|
|
${PIP_COMMAND} install --progress-bar=off --no-deps --exists-action=w -r requirements/prod.txt
|
|
|
|
npm ci ${NPM_ARGS} --include=prod
|
|
|
|
EOF
|
2023-03-23 17:46:56 +03:00
|
|
|
|
2024-09-16 11:42:45 +03:00
|
|
|
FROM base AS pip_development
|
2024-05-20 13:34:34 +03:00
|
|
|
|
|
|
|
RUN \
|
|
|
|
# Files required to install pip dependencies
|
2024-09-16 11:42:45 +03:00
|
|
|
--mount=type=bind,source=./requirements/prod.txt,target=${HOME}/requirements/prod.txt \
|
2024-05-20 13:34:34 +03:00
|
|
|
--mount=type=bind,source=./requirements/dev.txt,target=${HOME}/requirements/dev.txt \
|
|
|
|
# Files required to install npm dependencies
|
|
|
|
--mount=type=bind,source=package.json,target=${HOME}/package.json \
|
|
|
|
--mount=type=bind,source=package-lock.json,target=${HOME}/package-lock.json \
|
|
|
|
# Mounts for caching dependencies
|
|
|
|
--mount=type=cache,target=${PIP_CACHE_DIR},uid=${OLYMPIA_UID},gid=${OLYMPIA_UID} \
|
|
|
|
--mount=type=cache,target=${NPM_CACHE_DIR},uid=${OLYMPIA_UID},gid=${OLYMPIA_UID} \
|
2024-09-16 11:42:45 +03:00
|
|
|
<<EOF
|
|
|
|
${PIP_COMMAND} install --progress-bar=off --no-deps --exists-action=w -r requirements/prod.txt
|
|
|
|
${PIP_COMMAND} install --progress-bar=off --no-deps --exists-action=w -r requirements/dev.txt
|
|
|
|
npm install ${NPM_ARGS} --no-save
|
|
|
|
EOF
|
2024-05-20 13:34:34 +03:00
|
|
|
|
2024-09-16 11:42:45 +03:00
|
|
|
FROM base AS locales
|
2024-03-01 13:47:11 +03:00
|
|
|
ARG LOCALE_DIR=${HOME}/locale
|
|
|
|
# Compile locales
|
|
|
|
# Copy the locale files from the host so it is writable by the olympia user
|
|
|
|
COPY --chown=olympia:olympia locale ${LOCALE_DIR}
|
|
|
|
# Copy the executable individually to improve the cache validity
|
2024-04-29 14:45:47 +03:00
|
|
|
RUN \
|
2024-09-10 19:56:33 +03:00
|
|
|
--mount=type=bind,source=requirements/locale.txt,target=${HOME}/requirements/locale.txt \
|
2024-04-29 14:45:47 +03:00
|
|
|
--mount=type=bind,source=Makefile-docker,target=${HOME}/Makefile-docker \
|
|
|
|
--mount=type=bind,source=locale/compile-mo.sh,target=${HOME}/compile-mo.sh \
|
|
|
|
make -f Makefile-docker compile_locales
|
2024-03-01 13:47:11 +03:00
|
|
|
|
2024-05-06 13:50:34 +03:00
|
|
|
# More efficient caching by mounting the exact files we need
|
2024-10-09 16:05:31 +03:00
|
|
|
# and copying only the static/ & locale/ directory.
|
2024-09-16 11:42:45 +03:00
|
|
|
FROM pip_production AS assets
|
2024-05-06 13:50:34 +03:00
|
|
|
|
2024-10-09 16:05:31 +03:00
|
|
|
# In order to create js i18n files with all of our strings, we need to include
|
|
|
|
# the compiled locale files
|
|
|
|
COPY --from=locales --chown=olympia:olympia ${HOME}/locale/ ${HOME}/locale/
|
2024-05-06 13:50:34 +03:00
|
|
|
# TODO: only copy the files we need for compiling assets
|
|
|
|
COPY --chown=olympia:olympia static/ ${HOME}/static/
|
2023-03-23 17:46:56 +03:00
|
|
|
|
2024-03-01 13:47:11 +03:00
|
|
|
# Finalize the build
|
|
|
|
# TODO: We should move update_assets to the `builder` stage once we can efficiently
|
|
|
|
# Run that command without having to copy the whole source code
|
|
|
|
# This will shave nearly 1 minute off the best case build time
|
2024-05-06 13:50:34 +03:00
|
|
|
RUN \
|
|
|
|
--mount=type=bind,src=src,target=${HOME}/src \
|
|
|
|
--mount=type=bind,src=Makefile-docker,target=${HOME}/Makefile-docker \
|
|
|
|
--mount=type=bind,src=manage.py,target=${HOME}/manage.py \
|
2024-06-25 13:08:39 +03:00
|
|
|
<<EOF
|
|
|
|
echo "from olympia.lib.settings_base import *" > settings_local.py
|
|
|
|
DJANGO_SETTINGS_MODULE="settings_local" make -f Makefile-docker update_assets
|
|
|
|
EOF
|
2024-05-06 13:50:34 +03:00
|
|
|
|
2024-09-16 11:42:45 +03:00
|
|
|
FROM base AS sources
|
2024-05-06 13:50:34 +03:00
|
|
|
|
2024-08-21 11:33:31 +03:00
|
|
|
ARG DOCKER_BUILD DOCKER_COMMIT DOCKER_VERSION
|
|
|
|
|
|
|
|
ENV DOCKER_BUILD=${DOCKER_BUILD}
|
|
|
|
ENV DOCKER_COMMIT=${DOCKER_COMMIT}
|
|
|
|
ENV DOCKER_VERSION=${DOCKER_VERSION}
|
|
|
|
|
2024-05-06 13:50:34 +03:00
|
|
|
# Add our custom mime types (required for for ts/json/md files)
|
|
|
|
COPY docker/etc/mime.types /etc/mime.types
|
|
|
|
# Copy the rest of the source files from the host
|
|
|
|
COPY --chown=olympia:olympia . ${HOME}
|
2024-09-30 15:48:43 +03:00
|
|
|
# Copy assets from assets
|
|
|
|
COPY --from=assets --chown=olympia:olympia ${HOME}/site-static ${HOME}/site-static
|
|
|
|
COPY --from=assets --chown=olympia:olympia ${HOME}/static-build ${HOME}/static-build
|
2024-05-06 13:50:34 +03:00
|
|
|
|
2024-06-25 13:08:39 +03:00
|
|
|
# Set shell back to sh until we can prove we can use bash at runtime
|
|
|
|
SHELL ["/bin/sh", "-c"]
|
|
|
|
|
2024-09-16 11:42:45 +03:00
|
|
|
FROM sources AS development
|
2024-06-05 15:48:42 +03:00
|
|
|
|
|
|
|
# Copy dependencies from `pip_development`
|
|
|
|
COPY --from=pip_development --chown=olympia:olympia /deps /deps
|
|
|
|
|
2024-09-16 11:42:45 +03:00
|
|
|
FROM sources AS production
|
2024-05-06 13:50:34 +03:00
|
|
|
|
2024-09-27 18:04:13 +03:00
|
|
|
# Copy compiled locales from builder
|
|
|
|
COPY --from=locales --chown=olympia:olympia ${HOME}/locale ${HOME}/locale
|
2024-05-06 13:50:34 +03:00
|
|
|
# Copy dependencies from `pip_production`
|
|
|
|
COPY --from=pip_production --chown=olympia:olympia /deps /deps
|
|
|
|
|
2024-06-05 15:48:42 +03:00
|
|
|
|