include tests in dockerfile

This commit is contained in:
HgO 2022-08-08 22:28:58 +02:00
parent e2bdeee237
commit 9b21fcb6e3
2 changed files with 21 additions and 15 deletions

View file

@ -8,9 +8,13 @@ env3/
.env/ .env/
.venv/ .venv/
# Git
.git
# Python # Python
__pycache__/ __pycache__/
*.egg-info/ *.egg-info/
.mypy_cache
build/ build/
dist/ dist/

View file

@ -23,7 +23,7 @@
# then transfer those dependencies to the container we're going to ship, # then transfer those dependencies to the container we're going to ship,
# before throwing this one away # before throwing this one away
ARG PYTHON_VERSION=3.10 ARG PYTHON_VERSION=3.10
FROM docker.io/python:${PYTHON_VERSION}-alpine as builder FROM python:${PYTHON_VERSION}-alpine as builder
## ##
## Build libolm for matrix-nio e2e support ## Build libolm for matrix-nio e2e support
@ -41,22 +41,20 @@ RUN apk add --no-cache \
yaml-dev \ yaml-dev \
python3-dev python3-dev
ENV VIRTUAL_ENV="/opt/matrix_alertbot" ENV PROJECT_DIR="/opt/matrix_alertbot"
ENV LIBOLM_SRC_DIR="/opt/olm"
ENV VIRTUAL_ENV="${PROJECT_DIR}/.venv"
ENV PATH="$VIRTUAL_ENV/bin:$PATH" ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN python -m venv $VIRTUAL_ENV RUN python -m venv "${VIRTUAL_ENV}"
WORKDIR "${VIRTUAL_ENV}" WORKDIR "${PROJECT_DIR}"
# Build libolm # Build libolm
# #
# Also build the libolm python bindings and place them at /python-libs # 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 # We will later copy contents from both of these folders to the runtime
# container # container
COPY docker/build_and_install_libolm.sh /scripts/ COPY docker/build_and_install_libolm.sh /scripts/
RUN /scripts/build_and_install_libolm.sh "${LIBOLM_VERSION}" "${VIRTUAL_ENV}" RUN /scripts/build_and_install_libolm.sh "${LIBOLM_VERSION}" "${LIBOLM_SRC_DIR}}"
# Install Postgres dependencies
RUN apk add --no-cache \
musl-dev
# Install python runtime modules. We do this before copying the source code # Install python runtime modules. We do this before copying the source code
# such that these dependencies can be cached # such that these dependencies can be cached
@ -70,33 +68,37 @@ COPY setup.py ./setup.py
RUN pip install --no-warn-script-location ".[e2e]" RUN pip install --no-warn-script-location ".[e2e]"
# Now copy the source code # Now copy the source code
COPY *.py *.md *.in ./ COPY *.py *.md *.in requirements.txt ./
COPY matrix_alertbot/*.py ./matrix_alertbot/ COPY matrix_alertbot/*.py ./matrix_alertbot/
COPY matrix_alertbot/resources ./matrix_alertbot/resources COPY matrix_alertbot/resources ./matrix_alertbot/resources
# And build the final module # And build the final module
RUN pip install --no-warn-script-location ".[e2e]" RUN pip install --no-warn-script-location ".[e2e]"
COPY tests ./tests
## ##
## Creating the runtime container ## Creating the runtime container
## ##
# Create the container we'll actually ship. We need to copy libolm and any # Create the container we'll actually ship. We need to copy libolm and any
# python dependencies that we built above to this container # python dependencies that we built above to this container
FROM docker.io/python:${PYTHON_VERSION}-alpine FROM python:${PYTHON_VERSION}-alpine
ENV VIRTUAL_ENV="/opt/matrix_alertbot" ENV PROJECT_DIR="/opt/matrix_alertbot"
ENV VIRTUAL_ENV="${PROJECT_DIR}/.venv"
ENV PATH="$VIRTUAL_ENV/bin:$PATH" ENV PATH="$VIRTUAL_ENV/bin:$PATH"
WORKDIR "${PROJECT_DIR}"
# Copy python dependencies from the "builder" container # Copy python dependencies from the "builder" container
COPY --from=builder /opt/matrix_alertbot /opt/matrix_alertbot COPY --from=builder "${PROJECT_DIR}" "${PROJECT_DIR}"
# Copy libolm from the "builder" container # Copy libolm from the "builder" container
COPY --from=builder /usr/local/lib/libolm* /usr/local/lib/ COPY --from=builder /usr/local/lib/libolm* /usr/local/lib/
# Install any native runtime dependencies # Install any native runtime dependencies
RUN apk add --no-cache \ RUN apk add --no-cache libstdc++
libstdc++
# Specify a volume that holds the config file, SQLite3 database, # Specify a volume that holds the config file, SQLite3 database,
# and the matrix-nio store # and the matrix-nio store