Skip to content

Commit a577588

Browse files
authored
Non-root dockerfile (#61)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Streamlined the build process and runtime environment setup in the Docker configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent cfd909b commit a577588

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

Dockerfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
FROM python:3.12 as builder
2-
3-
WORKDIR /app
1+
FROM python:3.12 AS builder
42

3+
WORKDIR /builder
54
# python
65
ENV PYTHONUNBUFFERED=1 \
76
# prevents python creating .pyc files
@@ -17,7 +16,11 @@ RUN pip wheel --no-cache-dir --no-deps --wheel-dir ./wheels -r requirements.txt
1716

1817
FROM python:3.12-slim AS app
1918

20-
WORKDIR /app
19+
RUN adduser --system --group --home /home/nonroot nonroot
20+
ENV PATH="/home/nonroot/.local/bin:${PATH}"
21+
USER nonroot:nonroot
22+
23+
WORKDIR /home/nonroot/app
2124

2225
# python
2326
ENV PYTHONUNBUFFERED=1 \
@@ -28,11 +31,10 @@ ENV PYTHONUNBUFFERED=1 \
2831
PIP_NO_CACHE_DIR=off \
2932
PIP_DISABLE_PIP_VERSION_CHECK=on
3033

31-
COPY --from=builder /app/wheels ./wheels
32-
COPY --from=builder /app/requirements.txt ./
34+
COPY --from=builder /builder/wheels ./wheels
35+
COPY --from=builder /builder/requirements.txt ./
3336

3437
RUN pip install --no-cache-dir ./wheels/*
35-
ENV PATH="/home/abc/.local/bin:${PATH}"
3638

3739
COPY ./src ./src
3840

docker-compose.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
build:
55
context: .
66
ports:
7-
- "80:80"
7+
- "80"
88
environment:
99
SERVER_BASE_PATH: /assets
1010
healthcheck:
@@ -14,4 +14,6 @@ services:
1414
timeout: 5s
1515
retries: 5
1616
volumes:
17-
- ./assets:/assets
17+
- assets:/assets
18+
volumes:
19+
assets:

0 commit comments

Comments
 (0)