-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDockerfile
More file actions
103 lines (82 loc) · 3.5 KB
/
Dockerfile
File metadata and controls
103 lines (82 loc) · 3.5 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Multi-stage Dockerfile for Ultimate CA Manager
# Optimized for production with security and minimal size
# Paths aligned with DEB/RPM packages: /opt/ucm/{backend,frontend,data}
# Stage 1: Builder - Install dependencies and build environment
FROM python:3.13-slim-bookworm AS builder
# Install build dependencies (fallback for packages without prebuilt wheels)
# Note: pyjks is installed separately with --no-deps to skip `twofish`
# (sdist-only C ext, only used for BKS UBER format which UCM does not export).
# This means build-essential is no longer strictly required, but kept as a
# safety net for future deps that may need to compile.
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libssl-dev \
libffi-dev \
libkrb5-dev \
&& rm -rf /var/lib/apt/lists/*
# Create virtual environment (same path as DEB/RPM)
RUN python -m venv /opt/ucm/venv
ENV PATH="/opt/ucm/venv/bin:$PATH"
# Copy only requirements first for better caching
COPY backend/requirements.txt /tmp/requirements.txt
# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
pip install --no-cache-dir -r /tmp/requirements.txt && \
pip install --no-cache-dir --no-deps pyjks==20.0.0
# Stage 2: Runtime - Minimal production image
FROM python:3.13-slim-bookworm
LABEL maintainer="NeySlim <https://github.com/NeySlim>" \
description="Ultimate CA Manager - Certificate Authority Management System" \
org.opencontainers.image.source="https://github.com/NeySlim/ultimate-ca-manager"
# Install only runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
ca-certificates \
openssl \
softhsm2 \
libkrb5-3 \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user for security
RUN useradd -r -u 1000 -s /bin/false -d /opt/ucm ucm && \
usermod -aG softhsm ucm
# Prepare SoftHSM token directory
RUN mkdir -p /var/lib/softhsm/tokens && \
chown root:softhsm /var/lib/softhsm/tokens && \
chmod 1770 /var/lib/softhsm/tokens
# Copy virtual environment from builder
COPY --from=builder /opt/ucm/venv /opt/ucm/venv
# Set working directory (same as DEB/RPM)
WORKDIR /opt/ucm
# Copy application files with proper ownership (same layout as packages)
COPY --chown=ucm:ucm VERSION /opt/ucm/VERSION
COPY --chown=ucm:ucm backend/ /opt/ucm/backend/
COPY --chown=ucm:ucm frontend/ /opt/ucm/frontend/
COPY --chown=ucm:ucm wsgi.py /opt/ucm/wsgi.py
COPY --chown=ucm:ucm .env.docker.example /opt/ucm/.env.example
# Create data + log directories
RUN mkdir -p /opt/ucm/data/{ca,certs,private,crl,scep,backups,sessions,logs,temp} && \
mkdir -p /var/log/ucm && \
mkdir -p /etc/ucm && \
chown -R ucm:ucm /opt/ucm /var/log/ucm /etc/ucm
# Set environment variables
ENV PATH="/opt/ucm/venv/bin:$PATH" \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
UCM_DOCKER=1 \
UCM_BASE_PATH=/opt/ucm \
DATA_DIR=/opt/ucm/data
# Expose HTTPS port (and optional HTTP protocol port for CDP/OCSP)
EXPOSE 8443
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f -k https://127.0.0.1:8443/health || exit 1
# Copy entrypoint before switching user
COPY --chown=ucm:ucm docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Switch to non-root user
USER ucm
# Set entrypoint
ENTRYPOINT ["/entrypoint.sh"]
# Default command - Gunicorn from /opt/ucm/backend (same as packages)
CMD ["sh", "-c", "cd /opt/ucm/backend && gunicorn -c gunicorn_config.py wsgi:app"]