-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDockerfile
More file actions
108 lines (86 loc) · 3.51 KB
/
Dockerfile
File metadata and controls
108 lines (86 loc) · 3.51 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
104
105
106
107
108
# Multi-stage Dockerfile for Queen Message Queue
#
# This Dockerfile builds the complete Queen Message Queue system:
# - C++ server with full C++17 support
# - Vue.js frontend dashboard
# - Optimized runtime image (~250MB final size)
#
# Build: docker build -t queen-mq .
# Run: docker run -p 6632:6632 -e PG_HOST=your-db queen-mq
#
# For full stack with PostgreSQL, use docker-compose.yml
#
# Build optimizations:
# - Layered COPY: Makefile+deps cached separately from source code
# - Precompiled headers: spdlog + json.hpp parsed once, not 30+ times
# - ccache: compiler cache persisted across builds via BuildKit mount
# - Auto parallelism: uses $(nproc) instead of hardcoded -j value
#
# Requires BuildKit: DOCKER_BUILDKIT=1 docker build -t queen-mq .
#
# Stage 1: Build Frontend
FROM node:22-alpine AS frontend-builder
WORKDIR /app/webapp
# Copy frontend package files
COPY app/package*.json ./
# Install dependencies
RUN npm ci
# Copy frontend source
COPY app/ ./
# Build frontend
RUN npm run build
# Stage 2: Build C++ Server
FROM ubuntu:24.04 AS cpp-builder
ENV DEBIAN_FRONTEND=noninteractive
RUN sed -i -e 's|security.ubuntu.com|mirrors.edge.kernel.org|g' -e 's|archive.ubuntu.com|mirrors.edge.kernel.org|g' /etc/apt/sources.list.d/ubuntu.sources || true \
&& apt-get update && apt-get install -y \
build-essential libpq-dev libssl-dev zlib1g-dev \
curl unzip ca-certificates cmake ccache \
&& rm -rf /var/lib/apt/lists/*
# Enable ccache - wraps g++/gcc transparently for compilation caching
ENV PATH="/usr/lib/ccache:${PATH}"
WORKDIR /usr/build/server
# Layer 1: Copy only the Makefile (changes rarely - only when dep URLs change)
# This layer caches the dependency download so source code changes don't re-download
COPY server/Makefile ./Makefile
# Download and build dependencies (cached unless Makefile changes)
RUN make deps
# Layer 2: Copy source code (changes frequently, only triggers recompile)
COPY server/src/ ./src/
COPY server/include/ ./include/
COPY lib/ /usr/build/lib/
# Build with ccache persistent cache and auto-detected parallelism
RUN --mount=type=cache,target=/root/.ccache \
make -j$(nproc) build-only
# Verify
RUN test -f bin/queen-server && echo "Build successful"
# Stage 3: Runtime Image
FROM ubuntu:24.04
# Install runtime dependencies + PostgreSQL 18 client tools (pg_dump, pg_restore)
# The PGDG repo is required because Ubuntu 24.04 only ships up to PG 16.
RUN sed -i -e 's|security.ubuntu.com|mirrors.edge.kernel.org|g' -e 's|archive.ubuntu.com|mirrors.edge.kernel.org|g' /etc/apt/sources.list.d/ubuntu.sources || true \
&& apt-get update && apt-get install -y \
libssl3 \
zlib1g \
ca-certificates \
curl \
gnupg \
lsb-release \
&& curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc \
| gpg --dearmor -o /usr/share/keyrings/pgdg.gpg \
&& echo "deb [signed-by=/usr/share/keyrings/pgdg.gpg] https://apt.postgresql.org/pub/repos/apt \
$(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& apt-get update \
&& apt-get install -y postgresql-client-18 \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy C++ server binary from builder
COPY --from=cpp-builder /usr/build/server/bin/queen-server ./bin/queen-server
# Copy schema and procedures for database initialization (from libqueen)
COPY --from=cpp-builder /usr/build/lib/schema ./schema
# Copy frontend build from builder
COPY --from=frontend-builder /app/webapp/dist ./webapp/dist
# Expose the server port
EXPOSE 6632
# Run the C++ server
CMD ["./bin/queen-server"]