2020-08-12 02:37:23 +02:00
|
|
|
# To build the image, run `docker build` command from the root of the
|
|
|
|
# repository:
|
|
|
|
#
|
|
|
|
# docker build -f docker/Dockerfile .
|
|
|
|
#
|
|
|
|
# There is an optional PYTHON_VERSION build argument which sets the
|
|
|
|
# version of python to build against. For example:
|
|
|
|
#
|
2022-01-27 17:35:44 +01:00
|
|
|
# docker build -f docker/Dockerfile --build-arg PYTHON_VERSION=3.10 .
|
2020-08-12 02:37:23 +02:00
|
|
|
#
|
|
|
|
# An optional LIBOLM_VERSION build argument which sets the
|
|
|
|
# version of libolm to build against. For example:
|
|
|
|
#
|
2022-01-27 17:28:47 +01:00
|
|
|
# docker build -f docker/Dockerfile --build-arg LIBOLM_VERSION=3.2.10 .
|
2020-08-12 02:37:23 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
## Creating a builder container
|
|
|
|
##
|
|
|
|
|
|
|
|
# We use an initial docker container to build all of the runtime dependencies,
|
|
|
|
# then transfer those dependencies to the container we're going to ship,
|
|
|
|
# before throwing this one away
|
2022-01-27 17:35:44 +01:00
|
|
|
ARG PYTHON_VERSION=3.10
|
2022-08-08 22:28:58 +02:00
|
|
|
FROM python:${PYTHON_VERSION}-alpine as builder
|
2020-08-12 02:37:23 +02:00
|
|
|
|
|
|
|
##
|
|
|
|
## Build libolm for matrix-nio e2e support
|
|
|
|
##
|
|
|
|
|
|
|
|
# Install libolm build dependencies
|
2022-01-27 17:28:47 +01:00
|
|
|
ARG LIBOLM_VERSION=3.2.10
|
2020-08-12 02:37:23 +02:00
|
|
|
RUN apk add --no-cache \
|
|
|
|
make \
|
|
|
|
cmake \
|
|
|
|
gcc \
|
|
|
|
g++ \
|
|
|
|
git \
|
|
|
|
libffi-dev \
|
|
|
|
yaml-dev \
|
|
|
|
python3-dev
|
|
|
|
|
2022-08-08 22:28:58 +02:00
|
|
|
ENV PROJECT_DIR="/opt/matrix_alertbot"
|
2022-08-27 13:44:12 +02:00
|
|
|
ENV LIBOLM_SRC_DIR="/usr/local/src/olm"
|
|
|
|
ENV LIBOLM_INSTALL_DIR="/opt/olm"
|
2022-08-08 22:28:58 +02:00
|
|
|
ENV VIRTUAL_ENV="${PROJECT_DIR}/.venv"
|
2022-08-08 16:43:05 +02:00
|
|
|
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
|
2022-08-08 22:28:58 +02:00
|
|
|
RUN python -m venv "${VIRTUAL_ENV}"
|
2022-08-08 16:43:05 +02:00
|
|
|
|
2022-08-08 22:28:58 +02:00
|
|
|
WORKDIR "${PROJECT_DIR}"
|
2020-08-12 02:37:23 +02:00
|
|
|
# Build libolm
|
|
|
|
#
|
|
|
|
# Also build the libolm python bindings and place them at /python-libs
|
|
|
|
# We will later copy contents from both of these folders to the runtime
|
|
|
|
# container
|
|
|
|
COPY docker/build_and_install_libolm.sh /scripts/
|
2022-08-27 13:44:12 +02:00
|
|
|
RUN /scripts/build_and_install_libolm.sh "${LIBOLM_VERSION}" "${LIBOLM_SRC_DIR}" "${LIBOLM_INSTALL_DIR}"
|
2020-08-12 02:37:23 +02:00
|
|
|
|
|
|
|
# Install python runtime modules. We do this before copying the source code
|
|
|
|
# such that these dependencies can be cached
|
|
|
|
# This speeds up subsequent image builds when the source code is changed
|
2022-08-08 16:43:05 +02:00
|
|
|
RUN mkdir -p ./matrix_alertbot/
|
|
|
|
COPY matrix_alertbot/__init__.py ./matrix_alertbot/
|
|
|
|
COPY README.md matrix-alertbot ./
|
2020-08-12 02:37:23 +02:00
|
|
|
|
|
|
|
# Build the dependencies
|
2022-08-27 13:44:12 +02:00
|
|
|
COPY setup.py setup.cfg ./
|
2022-08-08 16:43:05 +02:00
|
|
|
RUN pip install --no-warn-script-location ".[e2e]"
|
2020-08-12 02:37:23 +02:00
|
|
|
|
|
|
|
# Now copy the source code
|
2022-08-14 15:32:43 +02:00
|
|
|
COPY *.py *.md *.in ./
|
2022-08-08 16:43:05 +02:00
|
|
|
COPY matrix_alertbot/*.py ./matrix_alertbot/
|
|
|
|
COPY matrix_alertbot/resources ./matrix_alertbot/resources
|
2020-08-12 02:37:23 +02:00
|
|
|
|
|
|
|
# And build the final module
|
2022-08-08 16:43:05 +02:00
|
|
|
RUN pip install --no-warn-script-location ".[e2e]"
|
2020-08-12 02:37:23 +02:00
|
|
|
|
2022-08-08 22:28:58 +02:00
|
|
|
COPY tests ./tests
|
|
|
|
|
2020-08-12 02:37:23 +02:00
|
|
|
##
|
|
|
|
## Creating the runtime container
|
|
|
|
##
|
|
|
|
|
|
|
|
# Create the container we'll actually ship. We need to copy libolm and any
|
|
|
|
# python dependencies that we built above to this container
|
2022-08-08 22:28:58 +02:00
|
|
|
FROM python:${PYTHON_VERSION}-alpine
|
2020-08-12 02:37:23 +02:00
|
|
|
|
2022-08-08 22:28:58 +02:00
|
|
|
ENV PROJECT_DIR="/opt/matrix_alertbot"
|
|
|
|
ENV VIRTUAL_ENV="${PROJECT_DIR}/.venv"
|
2022-08-08 16:43:05 +02:00
|
|
|
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
|
|
|
|
|
2022-08-08 22:28:58 +02:00
|
|
|
WORKDIR "${PROJECT_DIR}"
|
|
|
|
|
2022-10-29 14:18:16 +02:00
|
|
|
# Install any native runtime dependencies
|
|
|
|
RUN apk add --no-cache libstdc++
|
|
|
|
|
2020-08-12 02:37:23 +02:00
|
|
|
# Copy python dependencies from the "builder" container
|
2022-08-08 22:28:58 +02:00
|
|
|
COPY --from=builder "${PROJECT_DIR}" "${PROJECT_DIR}"
|
2020-08-12 02:37:23 +02:00
|
|
|
|
|
|
|
# Copy libolm from the "builder" container
|
|
|
|
COPY --from=builder /usr/local/lib/libolm* /usr/local/lib/
|
|
|
|
|
|
|
|
# Specify a volume that holds the config file, SQLite3 database,
|
|
|
|
# and the matrix-nio store
|
|
|
|
VOLUME ["/data"]
|
|
|
|
|
|
|
|
# Start the bot
|
2022-08-08 16:43:05 +02:00
|
|
|
CMD ["matrix-alertbot", "/data/config.yaml"]
|
2022-10-29 14:18:16 +02:00
|
|
|
|
|
|
|
EXPOSE 8080
|