-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
123 lines (91 loc) · 3.54 KB
/
Copy pathDockerfile
File metadata and controls
123 lines (91 loc) · 3.54 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
FROM oven/bun:1-debian AS frontend-builder
WORKDIR /frontend
COPY frontend/package.json frontend/bun.lock ./
RUN --mount=type=cache,target=/root/.bun/install/cache \
bun install --frozen-lockfile
COPY frontend/ ./
RUN bun run build
# -----------------------------------------------------------------------------
FROM rust:1.96-slim-bookworm AS chef
RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config libssl-dev \
&& rm -rf /var/lib/apt/lists/*
RUN cargo install cargo-chef --locked
WORKDIR /app
# -----------------------------------------------------------------------------
FROM chef AS planner
COPY Cargo.toml Cargo.lock ./
COPY src/ ./src/
RUN cargo chef prepare --recipe-path recipe.json
# -----------------------------------------------------------------------------
FROM chef AS deps-builder
COPY --from=planner /app/recipe.json recipe.json
RUN --mount=type=cache,target=/root/.cargo/registry \
--mount=type=cache,target=/root/.cargo/git \
--mount=type=cache,target=/app/target \
cargo chef cook --release --recipe-path recipe.json
# -----------------------------------------------------------------------------
FROM deps-builder AS rust-builder
ENV SQLX_OFFLINE=true
COPY Cargo.toml Cargo.lock ./
COPY src/ ./src/
COPY migrations/ ./migrations/
COPY .sqlx/ ./.sqlx/
RUN --mount=type=cache,target=/root/.cargo/registry \
--mount=type=cache,target=/root/.cargo/git \
--mount=type=cache,target=/app/target \
cargo build --release && \
cp /app/target/release/OxideChat /app/oxidechat
RUN apt-get update && apt-get install -y --no-install-recommends binutils \
&& strip /app/oxidechat \
&& rm -rf /var/lib/apt/lists/*
# -----------------------------------------------------------------------------
FROM debian:bookworm-slim AS runtime
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
nginx \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& groupadd -g 1000 app \
&& useradd -u 1000 -g app -s /bin/bash -m app \
&& mkdir -p /var/cache/nginx /var/log/nginx /var/lib/nginx /run /tmp/nginx \
&& mkdir -p /app/uploads/images \
&& chown -R app:app /var/cache/nginx /var/log/nginx /var/lib/nginx /run /tmp/nginx /app/uploads
COPY --from=frontend-builder /usr/local/bin/bun /usr/local/bin/bun
WORKDIR /app
COPY --chown=app:app nginx.conf /etc/nginx/nginx.conf
COPY --from=rust-builder --chown=app:app /app/oxidechat ./oxidechat
COPY --from=frontend-builder --chown=app:app /frontend/.output ./.output
COPY --chown=app:app migrations/ ./migrations/
RUN printf '%s\n' \
'#!/bin/bash' \
'set -e' \
'' \
'# Start Rust API in background (port 3001 to avoid conflict with nginx)' \
'PORT=3001 ./oxidechat &' \
'API_PID=$!' \
'' \
'# Start Nuxt SSR server in background' \
'cd /app/.output && bun server/index.mjs &' \
'NUXT_PID=$!' \
'' \
'# Start nginx in foreground' \
'nginx -g "daemon off;" &' \
'NGINX_PID=$!' \
'' \
'# Wait for any process to exit' \
'wait -n' \
'' \
'# If any process exits, kill all and exit' \
'kill $API_PID $NUXT_PID $NGINX_PID 2>/dev/null' \
'exit 1' \
> /app/start.sh && chmod +x /app/start.sh
USER app
# Image storage configuration:
# IMAGE_STORAGE_TYPE=database (default) | file
# IMAGE_STORAGE_PATH=/app/uploads/images (default for file storage)
VOLUME ["/app/uploads"]
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD curl -f http://localhost:8080/api/v1/health || exit 1
CMD ["/app/start.sh"]