-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
75 lines (59 loc) · 1.74 KB
/
Dockerfile
File metadata and controls
75 lines (59 loc) · 1.74 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
# Multi-stage Dockerfile for Virtual HSM
# Stage 1: Build
FROM ubuntu:22.04 AS builder
# Avoid interactive prompts
ENV DEBIAN_FRONTEND=noninteractive
# Install build dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libssl-dev \
zlib1g-dev \
uuid-dev \
libsodium-dev \
libfido2-dev \
libjson-c-dev \
git \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /build
# Copy source code
COPY . .
# Build the project
RUN make clean && \
make all -j$(nproc) && \
make test
# Stage 2: Runtime
FROM ubuntu:22.04
# Install runtime dependencies only
RUN apt-get update && apt-get install -y \
libssl3 \
zlib1g \
uuid-runtime \
libsodium23 \
libfido2-1 \
libjson-c5 \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user for security
RUN groupadd -r vhsm && useradd -r -g vhsm -s /bin/bash -d /app vhsm
# Set working directory
WORKDIR /app
# Copy built binaries and libraries from builder
COPY --from=builder /build/lib/ /app/lib/
COPY --from=builder /build/bin/ /app/bin/
COPY --from=builder /build/include/ /app/include/
# Set library path
ENV LD_LIBRARY_PATH=/app/lib:$LD_LIBRARY_PATH
# Create directories for storage and certificates
RUN mkdir -p /app/storage /app/certs /app/logs && \
chown -R vhsm:vhsm /app
# Switch to non-root user
USER vhsm
# Expose ports
EXPOSE 8443
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f https://localhost:8443/api/health -k || exit 1
# Default command - TLS server
CMD ["/app/bin/vhsm-server-tls", "-p", "8443", "-s", "/app/storage", "--generate-cert"]