Skip to content

Instantly share code, notes, and snippets.

@ahmadrosid
Created January 15, 2024 04:22
Show Gist options
  • Save ahmadrosid/49086c5e64c98a80bd4e4e63f4c6fb64 to your computer and use it in GitHub Desktop.
Save ahmadrosid/49086c5e64c98a80bd4e4e63f4c6fb64 to your computer and use it in GitHub Desktop.
Mayan edms 4.5.8 dockerfile
# syntax=docker/dockerfile:1.2
# vim:set ft=dockerfile:
####
# base_image - Bare bones image with the base packages needed to run
# Mayan EDMS.
####
FROM debian:12.2-slim as base_image
LABEL io.artifacthub.package.keywords="Python,Django,document management,OCR,PDF"
LABEL io.artifacthub.package.readme-url="https://gitlab.com/mayan-edms/mayan-edms/-/raw/master/README.md"
LABEL maintainer="Roberto Rosario roberto.rosario@mayan-edms.com"
LABEL org.opencontainers.image.authors="Roberto Rosario roberto.rosario@mayan-edms.com, https://forum.mayan-edms.com"
LABEL org.opencontainers.image.base.name="debian:12.2-slim"
LABEL org.opencontainers.image.description="Free Open Source Electronic Document Management System"
LABEL org.opencontainers.image.documentation="https://docs.mayan-edms.com/chapters/docker/index.html"
LABEL org.opencontainers.image.licenses="Apache-2.0"
LABEL org.opencontainers.image.source="https://gitlab.com/mayan-edms/mayan-edms/-/blob/master/mayan/apps/platform/templates/platform/docker/dockerfile.tmpl"
LABEL org.opencontainers.image.url="https://hub.docker.com/r/mayanedms/mayanedms"
LABEL org.opencontainers.image.vendor="Roberto Rosario"
LABEL org.opencontainers.image.title="Mayan EDMS"
COPY config.env /config.env
ENV LC_ALL=C.UTF-8 \
PYTHONUNBUFFERED=1 \
PROJECT_INSTALL_DIR=/opt/mayan-edms/
ENV MAYAN_MEDIA_ROOT=/var/lib/mayan \
MAYAN_STATIC_ROOT=${PROJECT_INSTALL_DIR}static
# Debian package caching.
ARG APT_PROXY
RUN --mount=type=cache,target=/var/cache/apt \
set -x \
&& if [ "${APT_PROXY}" ]; \
then echo "Acquire::http { Proxy \"http://${APT_PROXY}\"; };" > /etc/apt/apt.conf.d/01proxy \
; fi \
# Install base OS packages to run Mayan EDMS.
&& DEBIAN_FRONTEND=noninteractive \
apt-get update \
&& apt-get install --no-install-recommends --yes \
ca-certificates \
file \
fonts-arphic-uming \
fonts-arphic-ukai \
fonts-unfonts-core \
fuse \
ghostscript \
git \
gnupg1 \
graphviz \
libarchive-zip-perl \
libfile-mimeinfo-perl \
libimage-exiftool-perl \
libmariadb3 \
libpq5 \
libreoffice-calc-nogui \
libreoffice-draw-nogui \
libreoffice-impress-nogui \
libreoffice-math-nogui \
libreoffice-writer-nogui \
poppler-utils \
python3-distutils \
sane-utils \
sudo \
supervisor \
tesseract-ocr \
# Remove make and build dependencies.
&& apt-get remove --purge --yes \
make \
libproxy-tools \
libreoffice-avmedia-backend-vlc \
libvlc-bin \
libvlc5 \
libvlccore9 \
adwaita-icon-theme \
gsettings-desktop-schemas \
libgstreamer-plugins-base1.0-0 \
&& apt-get autoremove --purge --yes \
# Add mayan user.
&& adduser mayan --disabled-password --no-create-home --gecos "" \
# Pillow can't find zlib or libjpeg on aarch64 (ODROID C2).
&& if [ "$(uname --machine)" = "aarch64" ]; then \
ln --symbolic /usr/lib/aarch64-linux-gnu/libz.so /usr/lib/ \
&& ln --symbolic /usr/lib/aarch64-linux-gnu/libjpeg.so /usr/lib/ \
; fi \
# Pillow can't find zlib or libjpeg on armv7l (ODROID HC1).
&& if [ "$(uname --machine)" = "armv7l" ]; then \
ln --symbolic /usr/lib/arm-linux-gnueabihf/libz.so /usr/lib/ \
&& ln --symbolic /usr/lib/arm-linux-gnueabihf/libjpeg.so /usr/lib/ \
; fi \
&& sed --in-place 's/#user_allow_other/user_allow_other/g' /etc/fuse.conf
####
# builder_image - This image builds the Python package and is discarded afterwards
# only the build artifact is carried over to the next image.
####
# Reuse image.
FROM base_image as builder_image
# Python libraries caching.
ARG PIP_INDEX_URL
ARG PIP_TRUSTED_HOST
WORKDIR /src
# Copy the source files needed to build the Python package.
COPY --chown=mayan:mayan requirements /src/requirements
COPY --chown=mayan:mayan \
HISTORY.rst \
LICENSE \
MANIFEST.in \
README.md \
README.rst \
setup.py \
/src/
COPY --chown=mayan:mayan mayan /src/mayan
# Install development packages needed to build the Python packages.
RUN --mount=type=cache,target=/var/cache/apt \
DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends --yes \
default-libmysqlclient-dev \
g++ \
gcc \
libffi-dev \
libjpeg-dev \
libldap2-dev \
libpng-dev \
libpq-dev \
libsasl2-dev \
libssl-dev \
libtiff-dev \
make \
python3-dev \
python3-venv \
zlib1g-dev \
&& mkdir --parents "${PROJECT_INSTALL_DIR}" \
&& chown --recursive mayan:mayan "${PROJECT_INSTALL_DIR}" \
&& chown --recursive mayan:mayan /src
USER mayan
RUN set -a \
&& . /config.env \
&& set +a \
&& python3 -m venv "${PROJECT_INSTALL_DIR}" \
&& . "${PROJECT_INSTALL_DIR}bin/activate" \
&& pip install --no-cache-dir \
pip==${PYTHON_PIP_VERSION} \
amqp==${PYTHON_AMQP_VERSION} \
mysqlclient==${PYTHON_MYSQL_VERSION} \
psycopg2==${PYTHON_PSYCOPG2_VERSION} \
redis==${PYTHON_REDIS_VERSION} \
# psutil is needed by ARM builds otherwise gevent and gunicorn fail to start.
&& UNAME=`uname --machine` && if [ "${UNAME#*arm}" != ${UNAME} ]; then \
pip install --no-cache-dir \
psutil==${PYTHON_PSUTIL_VERSION} \
; fi \
# Install the Python packages needed to build Mayan EDMS.
&& pip install --no-cache-dir --requirement /src/requirements/build.txt \
# Build Mayan EDMS.
&& python3 setup.py sdist \
&& pip wheel --no-deps --no-index --wheel-dir dist dist/mayan-edms-*.tar.gz \
# Install the built Mayan EDMS package.
&& pip install --no-cache-dir dist/mayan_edms-*.whl \
# Install the static content.
&& ${PROJECT_INSTALL_DIR}bin/mayan-edms.py dependencies_install \
&& ${PROJECT_INSTALL_DIR}bin/mayan-edms.py appearance_prepare_static --link --noinput
COPY --chown=mayan:mayan requirements/testing-base.txt "${PROJECT_INSTALL_DIR}"
####
# Final image - base_image + builder_image artifact (Mayan install directory).
####
FROM base_image
COPY --from=builder_image --chown=mayan:mayan "${PROJECT_INSTALL_DIR}" "${PROJECT_INSTALL_DIR}"
USER root
COPY docker/rootfs /
VOLUME ["/var/lib/mayan"]
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
EXPOSE 8000
CMD ["run_all"]
RUN set -a \
&& . /config.env \
&& set +a \
&& ${PROJECT_INSTALL_DIR}bin/mayan-edms.py platform_template docker_entrypoint > /usr/local/bin/entrypoint.sh \
&& chown mayan:mayan /usr/local/bin/entrypoint.sh \
&& chmod +x /usr/local/bin/entrypoint.sh \
&& ${PROJECT_INSTALL_DIR}bin/mayan-edms.py platform_template docker_supervisord > ${SUPERVISOR_CONFIGURATION_DIRECTORY}${SUPERVISOR_CONFIGURATION_FILENAME} \
&& apt-get clean autoclean \
&& apt-get autoremove --purge --yes \
&& rm --force --recursive /var/lib/apt/lists/* \
&& rm --force /var/cache/apt/archives/*.deb \
# Remove temporary files owned by root from the platform_template step.
&& rm --force /tmp/* \
# Keep displaying log messages to stdout
&& find /var/log -type f | while read f; do echo -ne '' > $f; done \
# Delete Debian package proxy used for the base image.
&& rm --force /etc/apt/apt.conf.d/01proxy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment