-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
112 lines (100 loc) · 3.88 KB
/
Copy pathDockerfile
File metadata and controls
112 lines (100 loc) · 3.88 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
109
110
111
112
# Build stage for Rust backend
FROM rust:latest as backend-builder
WORKDIR /usr/src/app
# Install XeLaTeX and required fonts
RUN apt-get update && apt-get install -y \
texlive-xetex \
texlive-fonts-recommended \
texlive-fonts-extra \
texlive-latex-extra \
texlive-lang-chinese \
texlive-lang-japanese \
texlive-lang-other \
fonts-noto-cjk fonts-noto-cjk-extra \
fonts-noto-core fonts-noto-extra \
fonts-linuxlibertine \
libgraphite2-dev \
libharfbuzz-dev \
&& rm -rf /var/lib/apt/lists/*
# Set C++ standard to C++17 for dependencies that compile C++ code
ENV CXXFLAGS="-std=c++17"
# Optional: set to release-fast for faster Docker builds (less optimized binary)
ARG CARGO_BUILD_PROFILE=release
# Copy only manifest and lockfile, then build with stub sources so this layer
# caches compiled dependencies. When only app code changes, only the final
# cargo build re-runs and recompiles the app (deps come from cache).
COPY Cargo.toml Cargo.lock ./
RUN mkdir -p src test && \
echo 'fn main() {}' > src/main.rs && \
echo 'fn main() {}' > test/test.rs
# Build dependencies (and stub binaries). Use BuildKit cache mounts so
# registry, git, and target are reused across builds (much faster rebuilds).
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/src/app/target \
cargo build --release --profile ${CARGO_BUILD_PROFILE}
# Overwrite stubs with real source (only dirs needed for cargo build; excludes frontend, docs, scripts, etc.).
COPY src ./src
COPY test ./test
COPY migrations ./migrations
COPY .cargo ./.cargo
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/src/app/target \
cargo build --release --profile ${CARGO_BUILD_PROFILE} && \
cp /usr/src/app/target/${CARGO_BUILD_PROFILE}/lensisku /usr/src/app/lensisku-out
# Build stage for Vue.js frontend
FROM node:24-alpine as frontend-builder
WORKDIR /usr/src/app
# Copy package.json, lockfile, and pnpm 10 allowBuilds (esbuild, vue-demi postinstall)
COPY frontend/package.json ./
COPY frontend/pnpm-lock.yaml ./
COPY frontend/pnpm-workspace.yaml ./
# Install pnpm using standalone installer (avoids npm registry network issues)
# Try corepack first, fallback to standalone installer if needed
RUN apk add curl && \
(corepack enable && corepack prepare pnpm@latest --activate || \
curl -fsSL https://get.pnpm.io/install.sh | sh -)
ENV PATH="/root/.local/share/pnpm:$PATH"
# Install dependencies
RUN pnpm install --frozen-lockfile
# Copy the rest of the frontend code
COPY frontend .
# Build the frontend
RUN pnpm run build
# Final stage
FROM debian:bookworm-slim
WORKDIR /usr/src/app
# Install necessary dependencies
RUN apt-get update && apt-get install -y \
texlive-xetex \
texlive-fonts-recommended \
texlive-fonts-extra \
texlive-latex-extra \
texlive-lang-chinese \
texlive-lang-japanese \
texlive-lang-other \
fonts-noto-cjk fonts-noto-cjk-extra \
fonts-noto-core fonts-noto-extra \
fonts-linuxlibertine \
libgraphite2-dev \
libharfbuzz-dev \
&& rm -rf /var/lib/apt/lists/*
# Copy the built artifacts from the previous stages
COPY --from=backend-builder /usr/src/app/lensisku-out .
COPY --from=frontend-builder /usr/src/app/dist /var/www/html
# Scripts (e.g. import_valsi_sounds) and tools to run them
COPY scripts ./scripts
# libopus0: dynamic lib for Opus encoding (valsi TTS → audio/ogg); linked at build, loaded at runtime
RUN apt-get update && apt-get install -y --no-install-recommends \
nginx \
python3 \
python3-psycopg2 \
libopus0 \
&& rm -rf /var/lib/apt/lists/*
# Copy Nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf
# Expose the port the app runs on
EXPOSE 80
# Start Nginx and the backend server
CMD service nginx start && ./lensisku