Skip to content

Commit fe8bc92

Browse files
committed
Use a virtualenv in the development Docker image
Avoids using the system environment.
1 parent 451a380 commit fe8bc92

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

contrib/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

@@ -69,13 +70,18 @@ RUN if [ -n "${PYTHON_PIP_CONF}" ]; then \
6970
# Install Yarn for frontend development
7071
RUN npm install --global yarn
7172

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

76-
# Install test dependencies for Timesketch
77-
COPY ./test_requirements.txt /timesketch-test-requirements.txt
78-
RUN pip3 install -r /timesketch-requirements.txt -r /timesketch-test-requirements.txt
83+
# Update the PATH to include the virtual environment
84+
ENV PATH="/root/.virtualenvs/timesketch/bin:${PATH}"
7985

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

contrib/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)