Skip to content

Commit

Permalink
Use a virtualenv in the development Docker image
Browse files Browse the repository at this point in the history
Avoids using the system environment.
  • Loading branch information
jbaptperez committed Dec 17, 2024
1 parent 68c5c56 commit 2161c61
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 12 additions & 6 deletions docker/dev/timesketch/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*

Expand Down Expand Up @@ -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", "/"]
Expand Down
4 changes: 3 additions & 1 deletion docker/dev/timesketch/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit 2161c61

Please sign in to comment.