From fcf14eff3e8b3b5a7378cd693142d1fc9ab01579 Mon Sep 17 00:00:00 2001 From: jean-baptiste-perez-bib Date: Thu, 28 Nov 2024 22:57:10 +0100 Subject: [PATCH] Use a virtualenv in the development Docker image Avoids using the system environment. --- docker/dev/timesketch/Dockerfile | 18 ++++++++++++------ docker/dev/timesketch/docker-entrypoint.sh | 4 +++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/docker/dev/timesketch/Dockerfile b/docker/dev/timesketch/Dockerfile index a58223d75a..04dc7075f8 100644 --- a/docker/dev/timesketch/Dockerfile +++ b/docker/dev/timesketch/Dockerfile @@ -19,6 +19,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ python3-wheel \ python3-setuptools \ python3-psycopg2 \ + python3-venv \ tzdata \ && rm -rf /var/lib/apt/lists/* @@ -64,13 +65,18 @@ RUN if [ -n "${PYTHON_PIP_CONF}" ]; then \ # Install Yarn for frontend development RUN npm install --global yarn -# Install dependencies for Timesketch -COPY ./requirements.txt /timesketch-requirements.txt -RUN pip3 install -r /timesketch-requirements.txt +# Install dependencies for Timesketch in a virtual environment +COPY ["./requirements.txt", "/timesketch-requirements.txt"] +COPY ["./test_requirements.txt", "/timesketch-test-requirements.txt"] +RUN python3 -m venv --upgrade-deps --system-site-packages ~/.virtualenvs/timesketch \ + && . ~/.virtualenvs/timesketch/bin/activate \ + && pip install --no-cache-dir \ + -r /timesketch-requirements.txt \ + -r /timesketch-test-requirements.txt \ + psycopg2-binary -# Install test dependencies for Timesketch -COPY ./test_requirements.txt /timesketch-test-requirements.txt -RUN pip3 install -r /timesketch-requirements.txt -r /timesketch-test-requirements.txt +# Update the PATH to include the virtual environment +ENV PATH="/root/.virtualenvs/timesketch/bin:${PATH}" # Copy the entrypoint script into the container COPY ["./docker/dev/timesketch/docker-entrypoint.sh", "/"] diff --git a/docker/dev/timesketch/docker-entrypoint.sh b/docker/dev/timesketch/docker-entrypoint.sh index 2792682cea..2af3122aec 100644 --- a/docker/dev/timesketch/docker-entrypoint.sh +++ b/docker/dev/timesketch/docker-entrypoint.sh @@ -17,12 +17,14 @@ function kill_other_processes() { exit 0 } +. "${HOME}/.virtualenvs/app/bin/activate" + # Run the container the default way if [[ "$1" = 'timesketch' ]]; then CONF_DIR="/etc/timesketch" # Install Timesketch in editable mode from volume - pip3 install -e /usr/local/src/timesketch/ + pip install -e /usr/local/src/timesketch/ # Add web user tsctl create-user --password "${TIMESKETCH_PASSWORD}" "${TIMESKETCH_USER}"