Skip to content

Commit a4f9089

Browse files
committed
[PPHA-182] Use poetry over directly using pip
1 parent c83fbe0 commit a4f9089

File tree

4 files changed

+327
-29
lines changed

4 files changed

+327
-29
lines changed

Dockerfile

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,42 @@ RUN npm run compile
1010

1111
FROM python:3.13.5-alpine3.21 AS builder
1212

13+
WORKDIR /app
14+
1315
ENV PYTHONDONTWRITEBYTECODE=1 \
1416
PYTHONUNBUFFERED=1 \
15-
PIP_NO_CACHE_DIR=1 \
16-
PIP_DISABLE_PIP_VERSION_CHECK=1
17-
18-
RUN apk add --no-cache \
19-
build-base \
20-
postgresql-dev \
21-
gcc \
22-
musl-dev \
23-
linux-headers
24-
25-
RUN python -m venv /opt/venv
26-
ENV PATH="/opt/venv/bin:$PATH"
17+
POETRY_NO_INTERACTION=1 \
18+
POETRY_VIRTUALENVS_IN_PROJECT=1 \
19+
POETRY_VIRTUALENVS_CREATE=1 \
20+
POETRY_CACHE_DIR=/tmp/poetry_cache
2721

28-
COPY requirements.txt .
29-
COPY lung_cancer_screening ./lung_cancer_screening
30-
RUN pip install --no-cache-dir -r requirements.txt
22+
COPY pyproject.toml poetry.lock ./
23+
RUN pip install poetry
24+
RUN poetry install --no-root && rm -rf $POETRY_CACHE_DIR
3125

3226

3327
FROM python:3.13.5-alpine3.21
3428

3529
ENV PYTHONDONTWRITEBYTECODE=1 \
3630
PYTHONUNBUFFERED=1 \
37-
PATH="/opt/venv/bin:$PATH"
31+
VIRTUAL_ENV=/app/.venv \
32+
PATH="/app/.venv/bin:$PATH" \
33+
USER=app
3834

3935
RUN apk add --no-cache \
4036
postgresql-libs \
4137
curl
4238

43-
RUN addgroup -g 1000 app && adduser -D -s /bin/sh -u 1000 -G app app
44-
45-
COPY --from=builder /opt/venv /opt/venv
46-
47-
RUN mkdir -p /app && chown -R app:app /app
39+
RUN addgroup --gid 1000 --system ${USER} \
40+
&& adduser --uid 1000 --system ${USER} --ingroup ${USER}
4841

42+
USER ${USER}
4943
WORKDIR /app
5044

51-
COPY --chown=app:app . .
52-
53-
COPY --from=asset_builder --chown=app:app /app/lung_cancer_screening/assets/compiled /app/lung_cancer_screening/assets/compiled
54-
55-
USER app
45+
COPY --from=builder --chown=${USER}:${USER} ${VIRTUAL_ENV} ${VIRTUAL_ENV}
46+
COPY --chown=${USER}:${USER} ./lung_cancer_screening /app/lung_cancer_screening
47+
COPY --from=asset_builder --chown=${USER}:${USER} /app/lung_cancer_screening/assets/compiled /app/lung_cancer_screening/assets/compiled
48+
COPY --chown=${USER}:${USER} manage.py ./
5649

5750
EXPOSE 8000
5851

0 commit comments

Comments
 (0)