Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (55 loc) · 2.12 KB
/
Copy pathDockerfile
File metadata and controls
70 lines (55 loc) · 2.12 KB
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
# Build stage
FROM python:3.11-slim AS builder
WORKDIR /build
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
git \
&& rm -rf /var/lib/apt/lists/*
# Copy project files (including .git for version detection)
COPY . .
# Filtered build contexts look dirty to SCM even at a release tag.
ARG XRCG_VERSION
RUN pip install --no-cache-dir build wheel && \
if [ -n "${XRCG_VERSION}" ]; then \
export SETUPTOOLS_SCM_PRETEND_VERSION="${XRCG_VERSION}"; \
fi && \
python -m build --sdist --wheel --outdir dist
# Runtime stage
FROM python:3.11-slim
WORKDIR /app
# Install runtime dependencies only
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
&& rm -rf /var/lib/apt/lists/*
# Copy built wheels from builder
COPY --from=builder /build/dist /tmp/dist
# Install xrcg and verify explicitly versioned builds before publishing.
ARG XRCG_VERSION
RUN pip install --no-cache-dir /tmp/dist/*.whl && \
if [ -n "${XRCG_VERSION}" ]; then \
python -c "import importlib.metadata as m, subprocess, sys; \
expected = sys.argv[1]; \
actual = m.version('xrcg'); \
cli = subprocess.check_output(['xrcg', '--version'], text=True).strip(); \
print(f'package={actual}; CLI={cli}; expected={expected}'); \
sys.exit(0 if actual == expected and cli == f'xrcg version {expected}' else 'Release version mismatch')" "${XRCG_VERSION}"; \
fi && \
rm -rf /tmp/dist
# Create a non-root user for security
RUN useradd -m -u 1001 xrcg && \
chown -R xrcg:xrcg /app
# Create working directory for user projects
RUN mkdir -p /work && \
chown -R xrcg:xrcg /work
USER xrcg
# Set working directory for mounted volumes
WORKDIR /work
# Set the entrypoint
ENTRYPOINT ["xrcg"]
CMD ["--help"]
# Labels for container metadata
LABEL org.opencontainers.image.title="xRegistry Code Generation" \
org.opencontainers.image.description="A command-line tool for xRegistry with code generation for messaging and eventing applications" \
org.opencontainers.image.vendor="CNCF" \
org.opencontainers.image.source="https://github.com/xregistry/codegen"