Skip to content

Commit 94e3cad

Browse files
committed
Use a virtualenv in the development Docker image
Avoids using the system environment.
1 parent 107c1be commit 94e3cad

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

docker/dev/timesketch/Dockerfile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1919
python3-wheel \
2020
python3-setuptools \
2121
python3-psycopg2 \
22+
python3-venv \
2223
tzdata \
2324
&& rm -rf /var/lib/apt/lists/*
2425

@@ -64,13 +65,18 @@ RUN if [ -n "${PYTHON_PIP_CONF}" ]; then \
6465
# Install Yarn for frontend development
6566
RUN npm install --global yarn
6667

67-
# Install dependencies for Timesketch
68-
COPY ./requirements.txt /timesketch-requirements.txt
69-
RUN pip3 install -r /timesketch-requirements.txt
68+
# Install dependencies for Timesketch in a virtual environment
69+
COPY ["./requirements.txt", "/timesketch-requirements.txt"]
70+
COPY ["./test_requirements.txt", "/timesketch-test-requirements.txt"]
71+
RUN python3 -m venv --upgrade-deps --system-site-packages ~/.virtualenvs/timesketch \
72+
&& . ~/.virtualenvs/timesketch/bin/activate \
73+
&& pip install --no-cache-dir \
74+
-r /timesketch-requirements.txt \
75+
-r /timesketch-test-requirements.txt \
76+
psycopg2-binary
7077

71-
# Install test dependencies for Timesketch
72-
COPY ./test_requirements.txt /timesketch-test-requirements.txt
73-
RUN pip3 install -r /timesketch-requirements.txt -r /timesketch-test-requirements.txt
78+
# Update the PATH to include the virtual environment
79+
ENV PATH="/root/.virtualenvs/timesketch/bin:${PATH}"
7480

7581
# Copy the entrypoint script into the container
7682
COPY ["./docker/dev/timesketch/docker-entrypoint.sh", "/"]

docker/dev/timesketch/docker-entrypoint.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ function kill_other_processes() {
1717
exit 0
1818
}
1919

20+
. "${HOME}/.virtualenvs/app/bin/activate"
21+
2022
# Run the container the default way
2123
if [[ "$1" = 'timesketch' ]]; then
2224
CONF_DIR="/etc/timesketch"
2325

2426
# Install Timesketch in editable mode from volume
25-
pip3 install -e /usr/local/src/timesketch/
27+
pip install -e /usr/local/src/timesketch/
2628

2729
# Add web user
2830
tsctl create-user --password "${TIMESKETCH_PASSWORD}" "${TIMESKETCH_USER}"

0 commit comments

Comments
 (0)