-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
74 lines (53 loc) · 1.61 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# syntax=docker/dockerfile:1
# Base image
ARG PYTHON_VERSION=3.12.0
FROM python:${PYTHON_VERSION}-alpine AS base
# Set environment variables for Poetry
ENV POETRY_VERSION=1.8
# Install Poetry and dependencies in a build stage
FROM base AS build
# Set working directory
RUN apk add --update --no-cache \
build-base postgresql-dev musl-dev
WORKDIR /usr/src/app
# Copy the pyproject.toml and poetry.lock files to the container
COPY pyproject.toml poetry.lock* ./
# Create a virtual environment and install Poetry
RUN python3 -m venv .venv\
&&pip install -U pip setuptools \
&&pip install poetry==${POETRY_VERSION} \
&&poetry install --without dev --no-root\
&&poetry add psycopg2
# Final stage
FROM base AS final
# Prevents Python from writing pyc files
ENV PYTHONDONTWRITEBYTECODE=1
# Keeps Python from buffering stdout and stderr
ENV PYTHONUNBUFFERED=1
ENV APP_DEVELOPMENT=False
ENV VIRTUAL_ENV=/usr/src/app/.venv \
PATH="/usr/src/app/.venv/bin:$PATH"
RUN apk add --update --no-cache postgresql-client
# Set working directory
WORKDIR /usr/src/app
#copy the dependency
COPY --from=build /usr/src/app/.venv .venv
# Copy the application code to the container
COPY . /usr/src/app
# See https://docs.docker.com/go/dockerfile-user-best-practices/
ARG UID=10001
# Add a non-privileged user
#RUN adduser \
# --disabled-password \
# --gecos "" \
# --home "/nonexistent" \
# --shell "/sbin/nologin" \
# --no-create-home \
# --uid "${UID}" \
# appuser
# Switch to the non-privileged user
#USER appuser
# Expose the port the app runs on
EXPOSE 8000
# Run the application
CMD ["python", "run.py"]