forked from ferriskey/ferriskey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
126 lines (92 loc) · 4.69 KB
/
Copy pathDockerfile
File metadata and controls
126 lines (92 loc) · 4.69 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
FROM rust:1.95.0-bookworm AS chef
WORKDIR /usr/local/src/ferriskey
RUN cargo install cargo-chef --version 0.1.77 --locked && \
cargo install sqlx-cli --version 0.8.6 --no-default-features --features postgres --locked
# ── Planner: analyse the workspace and produce recipe.json ────────────────────
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
# ── Builder: cook deps first (cached), then build real source ─────────────────
FROM chef AS builder
COPY --from=planner /usr/local/src/ferriskey/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build --release
# ── Shared runtime base ───────────────────────────────────────────────────────
FROM debian:bookworm-slim AS runtime
RUN \
apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates=20230311+deb12u1 \
libssl3=3.0.17-1~deb12u2 && \
rm -rf /var/lib/apt/lists/* && \
addgroup \
--system \
--gid 1000 \
ferriskey && \
adduser \
--system \
--no-create-home \
--disabled-login \
--uid 1000 \
--gid 1000 \
ferriskey
USER ferriskey
# ── API image ─────────────────────────────────────────────────────────────────
FROM runtime AS api
COPY --from=builder /usr/local/src/ferriskey/target/release/ferriskey-api /usr/local/bin/
COPY --from=builder /usr/local/src/ferriskey/core/migrations /usr/local/src/ferriskey/migrations
COPY --from=builder /usr/local/cargo/bin/sqlx /usr/local/bin/
EXPOSE 80
ENTRYPOINT ["ferriskey-api"]
# ── Operator image ────────────────────────────────────────────────────────────
FROM runtime AS operator
COPY --from=builder /usr/local/src/ferriskey/target/release/ferriskey-operator /usr/local/bin/
EXPOSE 80
ENTRYPOINT ["ferriskey-operator"]
# ── Frontend build ────────────────────────────────────────────────────────────
FROM node:20.14.0-alpine AS webapp-build
WORKDIR /usr/local/src/ferriskey
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN \
corepack enable && \
corepack prepare pnpm@9.15.0 --activate && \
apk --no-cache add dumb-init=1.2.5-r3
COPY front/package.json front/pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
COPY front/ .
RUN VITE_API_URL="" pnpm run build
# ── Frontend runtime ──────────────────────────────────────────────────────────
FROM nginxinc/nginx-unprivileged:1.31.1-alpine3.23-slim AS webapp
# The unprivileged image ships root-owned index.html/50x.html in the web root and
# runs as the non-root "nginx" user. The runtime entrypoint wipes and repopulates
# that directory, so it must be owned by the runtime user — otherwise the rm fails
# with "Permission denied" and (under `set -e`) nginx never starts.
USER root
RUN rm -rf /usr/share/nginx/html/* && chown -R nginx:nginx /usr/share/nginx/html
USER nginx
COPY --from=webapp-build /usr/local/src/ferriskey/dist /usr/local/src/ferriskey
COPY front/nginx.conf /etc/nginx/conf.d/default.conf
COPY --chmod=0755 front/docker-entrypoint.sh /docker-entrypoint.d/docker-entrypoint.sh
# ── Standalone image (API + Frontend, single container) ───────────────────────
FROM debian:bookworm-slim AS standalone
# hadolint ignore=DL3008
RUN \
apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates=20230311+deb12u1 \
libssl3=3.0.17-1~deb12u2 \
nginx \
supervisor && \
rm -rf /var/lib/apt/lists/* && \
rm -f /etc/nginx/sites-enabled/default
COPY --from=builder /usr/local/src/ferriskey/target/release/ferriskey-api /usr/local/bin/
COPY --from=builder /usr/local/src/ferriskey/core/migrations /usr/local/src/ferriskey/migrations
COPY --from=builder /usr/local/cargo/bin/sqlx /usr/local/bin/
COPY --from=webapp-build /usr/local/src/ferriskey/dist /usr/share/nginx/html
COPY front/nginx-standalone.conf /etc/nginx/conf.d/default.conf
COPY docker/supervisord.conf /etc/supervisor/conf.d/ferriskey.conf
COPY --chmod=0755 docker/standalone-entrypoint.sh /standalone-entrypoint.sh
EXPOSE 80
ENTRYPOINT ["/standalone-entrypoint.sh"]