A lexicon-driven AppView for ATProto.
2.0 kB
61 lines
1FROM node:22-alpine AS frontend
2
3WORKDIR /app/web
4COPY web/package.json web/package-lock.json ./
5RUN npm ci
6COPY web/ .
7ENV NEXT_PUBLIC_BASE_PATH=/__HAPPYVIEW_BP__
8RUN npm run build
9
10FROM rust:1.96.1-bookworm AS builder
11
12WORKDIR /app
13
14# Build dependencies first (cached until Cargo.toml/Cargo.lock change)
15COPY Cargo.toml Cargo.lock ./
16RUN mkdir -p src/bin && echo "fn main() {}" > src/main.rs && touch src/lib.rs && echo "fn main() {}" > src/bin/migrate_lua_sql.rs
17ENV SQLX_OFFLINE=true
18RUN cargo build --release && rm -rf src target/release/.fingerprint/happyview-*
19
20# Build application code
21COPY src/ src/
22COPY migrations/ migrations/
23ARG HAPPYVIEW_VERSION
24ENV HAPPYVIEW_VERSION=$HAPPYVIEW_VERSION
25RUN cargo build --release
26
27FROM debian:bookworm-slim
28
29RUN apt-get update && apt-get install -y --no-install-recommends \
30 ca-certificates \
31 && rm -rf /var/lib/apt/lists/*
32
33# Run the service as a non-root system user; the binary needs no root privileges
34# at runtime and binds an unprivileged port (3000).
35RUN groupadd --system --gid 10001 app \
36 && useradd --system --uid 10001 --gid app --home-dir /app --no-create-home \
37 --shell /usr/sbin/nologin app
38
39WORKDIR /app
40
41COPY --from=builder /app/target/release/happyview /usr/local/bin/happyview
42RUN chmod +x /usr/local/bin/happyview
43COPY migrations/ /app/migrations
44# The static dir is writable at runtime: the entrypoint rewrites the base-path
45# sentinel in place and removes the marker.
46COPY --from=frontend --chown=app:app /app/web/out /srv/static
47COPY entrypoint.sh /entrypoint.sh
48RUN chmod +x /entrypoint.sh && touch /srv/static/.base-path-pending
49
50# Data dir for the default SQLite backend (DATABASE_URL=sqlite://data/...).
51# A named volume mounted here inherits this ownership on first creation; a bind
52# mount must be chown'd to uid 10001 by the operator.
53RUN mkdir -p /app/data && chown app:app /app/data
54
55ENV STATIC_DIR=/srv/static
56
57USER app
58
59EXPOSE 3000
60
61ENTRYPOINT ["/entrypoint.sh"]