Skip to content

Commit

Permalink
chore: Optimize Dockerfile and update run script (#99)
Browse files Browse the repository at this point in the history
# Pull Request

## Description

This PR optimises the Docker build process and updates the run script
for improved execution:

- Implements a multi-stage Docker build to reduce image size
- Uses `poetry export` to generate a `requirements.txt` file
- Installs dependencies directly from `requirements.txt` instead of
using Poetry in the final image
- Updates the `run.sh` script to change directories, display environment
variables, and execute the analyser module directly with Python instead
of using Poetry

These changes aim to streamline the build process, reduce the final
image size, and simplify the execution of the analyser.

fixes #100
  • Loading branch information
JackPlowman authored Sep 30, 2024
1 parent 0d517ce commit 6c0350a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
17 changes: 10 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#checkov:skip=CKV_DOCKER_2
#checkov:skip=CKV_DOCKER_3
FROM python:3.12-alpine
FROM python:3.12-alpine AS builder

WORKDIR /

COPY pyproject.toml poetry.lock ./
RUN pip install --no-cache-dir poetry==1.8.3 && poetry export --output=requirements.txt

FROM python:3.12-alpine AS analyser

WORKDIR /

Expand All @@ -9,13 +16,9 @@ RUN mkdir -p /statistics && \
apk add --no-cache git=2.45.2-r0

COPY --chmod=755 run.sh run.sh

COPY analyser analyser
COPY pyproject.toml poetry.lock ./

RUN pip install --no-cache-dir poetry==1.8.3 \
&& poetry install --no-dev

ENV PYTHONPATH=/
COPY --from=builder requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

ENTRYPOINT [ "/run.sh" ]
7 changes: 5 additions & 2 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/bin/sh
set -e +x

cd ..
cd ..
# Echo cwd
echo "Current working directory: $(pwd)"

# Show files
ls -la

printenv

# Run the analyser
poetry run python -m analyser
python -m analyser

0 comments on commit 6c0350a

Please sign in to comment.