-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
79 lines (53 loc) · 2.26 KB
/
Copy pathDockerfile
File metadata and controls
79 lines (53 loc) · 2.26 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
# nichy-web Docker image
#
# Consumes the prebuilt nichy-rust:main toolchain image (see Dockerfile.rust),
# compiles nichy, and packages nichy-web with std libraries for multiple targets.
#
# Prerequisite (one time, or to refresh rustc):
# docker build -f Dockerfile.rust -t nichy-rust:main .
#
# Build:
# docker build -t nichy-web .
#
# Run:
# docker run -p 3873:3873 nichy-web
ARG RUST_IMAGE=nichy-rust:main
FROM node:22-bookworm-slim AS web-builder
WORKDIR /web
COPY web/package.json web/package-lock.json ./
RUN npm ci --no-audit --no-fund
COPY web/ ./
RUN npm run build
FROM ${RUST_IMAGE} AS nichy-builder
ENV STAGE2=/rust/build/x86_64-unknown-linux-gnu/stage2
COPY . /nichy
WORKDIR /nichy
COPY --from=web-builder /web/dist /nichy/web/dist
RUN ln -s /rust /nichy/rust
ENV RUST_ROOT=/rust
ENV RUSTC=/nichy/docker-rustc
RUN printf '#!/bin/sh\nexport LD_LIBRARY_PATH="%s/lib:${LD_LIBRARY_PATH:-}"\nexec "%s/bin/rustc" "$@"\n' \
"$STAGE2" "$STAGE2" > /nichy/docker-rustc && chmod +x /nichy/docker-rustc
RUN mkdir -p /nichy/.cargo && printf '[target.x86_64-unknown-linux-gnu]\nrustflags = [\n "-C", "link-arg=-Wl,-rpath,%s/lib",\n "-C", "link-arg=-Wl,-rpath,%s/lib/rustlib/x86_64-unknown-linux-gnu/lib",\n]\n' \
"$STAGE2" "$STAGE2" > /nichy/.cargo/config.toml
ENV LD_LIBRARY_PATH="/rust/build/x86_64-unknown-linux-gnu/stage2/lib"
ENV PATH="/rust/build/x86_64-unknown-linux-gnu/stage0/bin:${PATH}"
RUN cargo build --release -p nichy-cli -p nichy-web
FROM debian:bookworm-slim AS runtime
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
RUN useradd --system --no-create-home --uid 65532 nichy
WORKDIR /app
COPY --from=nichy-builder /rust/build/x86_64-unknown-linux-gnu/stage2 /sysroot
COPY --from=nichy-builder /nichy/target/release/nichy-bin /app/nichy-bin
COPY --from=nichy-builder /nichy/target/release/nichy-web /app/nichy-web
RUN mkdir -p /var/lib/nichy && chown nichy:nichy /var/lib/nichy
ENV NICHY_SYSROOT=/sysroot
ENV NICHY_BIN=/app/nichy-bin
ENV LD_LIBRARY_PATH="/sysroot/lib:/sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib"
RUN printf 'listen = ["0.0.0.0:3873"]\ndb_path = "/var/lib/nichy/nichy-web.db"\n' \
> /app/nichy-web.toml
USER nichy
EXPOSE 3873
CMD ["/app/nichy-web"]