-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
54 lines (38 loc) · 1.26 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
### Stage 1
# Using python:3.11-slim as base image
FROM python:3.11-slim as base
# Applications in the environment can handle UTF-8 encoded characters correctly
#Python not to generate any .pyc files
#Disabling python buffering Op
ENV LANG="C.UTF-8" \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
# Install updated packages, Install upgraded Pip versions and installing poetry
RUN apt-get update && apt-get install -y --no-install-recommends gcc && \
pip install --upgrade pip && pip install pipenv poetry
# Set Poetry to create virtual environments inside the project directory
ENV POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1
# Set working directory
WORKDIR /app
# copy pyproject.toml
COPY pyproject.toml .
# copy sendgrid email python file
COPY sendgrid_email.py .
# poetry venv installation
RUN poetry -v install --no-ansi --no-interaction --only main
### Stage 2
# Final stage
FROM base as runtime
# Runtime non root user
RUN useradd --create-home python
# Set a work directory
WORKDIR /home/python
# copy initial work dir
COPY --from=base /app/. /home/python
# adding virtualenv to PATH variable
ENV PATH="/home/python/.venv/bin:$PATH"
# nonroot user
USER python
# executing program
CMD ["poetry", "run", "python3", "sendgrid_email.py"]