-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
78 lines (56 loc) · 2.19 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
75
76
77
78
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION=python:3.12
#####################################################################################
# Python Base
# hadolint ignore=DL3006
FROM ${PYTHON_VERSION}-alpine AS base
ARG TARGETARCH
# Python specific settings
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_DISABLE_PIP_VERSION_CHECK=on \
VIRTUAL_ENV="/venv"
# Poetry environment variables
ENV POETRY_HOME="/opt/poetry" \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_CREATE=false \
POETRY_VERSION=1.8.2
RUN apk update && \
apk add --no-cache curl bash
# Set the path
ENV PATH="${POETRY_HOME}/bin:${VIRTUAL_ENV}/bin:${PATH}"
RUN python -m venv ${VIRTUAL_ENV}
ENV APP_DIR=/app/
WORKDIR ${APP_DIR}
ENV PYTHONPATH="${APP_DIR}:${PYTHONPATH}"
ENV APP_USER=webapp
RUN addgroup -g 1000 -S "${APP_USER}" \
&& adduser -u 1000 -G "${APP_USER}" -S "${APP_USER}" \
&& chown -R "${APP_USER}":"${APP_USER}" "${APP_DIR}"
#####################################################################################
# Install Poetry and dependencies in a build stage
FROM base AS builder
LABEL org.opencontainers.image.source=https://github.com/rewindio/github-to-slack-notifier \
org.opencontainers.image.authors="[email protected]" \
org.opencontainers.image.stage="builder"
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN --mount=type=cache,target=/root/.cache \
curl -sSL https://install.python-poetry.org | python -
# Set up the working directory
WORKDIR /app
# Copy only the dependency files to take advantage of caching
COPY pyproject.toml poetry.lock ./
RUN --mount=type=cache,target=/root/.cache \
poetry install --no-root --only main
#####################################################################################
# Stage production
FROM base AS production
LABEL org.opencontainers.image.source=https://github.com/rewindio/github-to-slack-notifier \
org.opencontainers.image.authors="[email protected]" \
org.opencontainers.image.stage="production"
COPY --from=builder ${POETRY_HOME} ${POETRY_HOME}
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
WORKDIR ${APP_DIR}
COPY pyproject.toml poetry.lock ./
COPY . .
ENTRYPOINT [ "python3", "/app/src/main.py" ]