-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
50 lines (36 loc) · 1.3 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Build dependencies only when needed
FROM python:3.11-slim-bullseye AS builder
ARG BUILD_ENVIRONMENT=dev
# Install apt packages
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
# dependencies for building python packages
build-essential
# Create python dependencies wheels
COPY requirements /tmp/requirements
RUN pip wheel --wheel-dir /usr/src/app/wheels -r /tmp/requirements/${BUILD_ENVIRONMENT}.txt
FROM python:3.11-slim-bullseye AS runner
ENV PYTHONBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
RUN useradd -U fraand
# Install apt packages
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
# clear apt-get cache & remove unnecessary files
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Copy python dependencies wheels from builder
COPY --from=builder /usr/src/app/wheels /wheels/
# Use wheels to install python dependencies
RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \
&& rm -rf /wheels/
# Copy application code
WORKDIR /app
COPY --chown=fraand:fraand . .
RUN chmod -R +x scripts
USER fraand
EXPOSE 8000
# Run checks and configuration
ENTRYPOINT [ "./scripts/entrypoint.sh" ]
# Start server
CMD [ "./scripts/start.sh" ]