forked from morganzero/cloudflare-companion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
72 lines (54 loc) · 1.87 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
# Global args
ARG PYTHON_VERSION=3.11
ARG APP_PATH=/app
ARG VIRTUAL_ENV_PATH=.venv
# Builder stage
FROM ghcr.io/astral-sh/uv:python${PYTHON_VERSION}-bookworm-slim AS builder
# Re-declare the ARG to use it in this stage
ARG APP_PATH
ARG VIRTUAL_ENV_PATH
# hadolint ignore=DL3008
RUN <<EOF
apt-get update
apt-get install --no-install-recommends -y git
EOF
# Set the working directory:
WORKDIR ${APP_PATH}
# Change ownership of the application directory to the non-root user
RUN chown -R nobody ${APP_PATH}
# Set uv environment variables
ENV UV_COMPILE_BYTECODE=1
ENV UV_LINK_MODE=copy
# Install the application dependencies and build .venv:
# for rootless configurations like podman, add 'z' or relabel=shared
# to circumvent the SELinux context
#
# See https://github.com/hadolint/language-docker/issues/95 for hadolint support
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock,ro \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml,ro \
uv sync --frozen --no-install-project --no-dev
# Copy the application source code:
COPY src .
# Final stage
FROM python:${PYTHON_VERSION}-slim as target
# Redeclare args
ARG APP_PATH
ARG VIRTUAL_ENV_PATH
# Image args
ARG REGISTRY="ghcr.io"
ARG REPOSITORY="inean/dns-synchub"
# Set labels for the image
LABEL url="https://github.com/${REPOSITORY}/"
LABEL image="${REGISTRY}/${REPOSITORY}"
LABEL maintainer="Carlos Martín (github.com/inean)"
# Set the working directory:
WORKDIR ${APP_PATH}
# Place executables in the environment at the front of the path
ENV PATH="${APP_PATH}/${VIRTUAL_ENV_PATH}/bin:$PATH"
# Copy dependencies and source code from the builder stage
COPY --from=builder ${APP_PATH} ${APP_PATH}
# Run the application:
ENTRYPOINT ["python", "-m", "dns_synchub"]
# Use CMD to pass arguments to the application
CMD ["--version"]