repos
/ analytics-rust master

analytics-rust

mirror archived upstream

Single-binary self-hosted website analytics on Rust axum: collector API, dashboards, world map, and PDF reports.

analyticsaxumdockerrustself-hostedsqliteviteweb-analytics

1.1 KB · 47 lines · Docker Raw History
 1# syntax=docker/dockerfile:1
 2# ----- builder -----
 3FROM rust:alpine AS builder
 4
 5RUN apk add --no-cache musl-dev pkgconfig openssl-dev
 6
 7COPY --from=oven/bun:alpine /usr/local/bin/bun /usr/local/bin/bun
 8
 9WORKDIR /app
10
11COPY Cargo.toml Cargo.lock ./
12COPY src ./src
13COPY migrations ./migrations
14COPY frontend ./frontend
15
16RUN cd frontend && bun install --frozen-lockfile && bun run build && bun run build:maps
17
18RUN --mount=type=cache,target=/usr/local/cargo/registry \
19    --mount=type=cache,target=/app/target \
20    cargo build --release && \
21    cp target/release/analytics /app/analytics
22
23# ----- runtime -----
24FROM alpine:3.23
25
26RUN apk add --no-cache \
27    font-jetbrains-mono ttf-dejavu ttf-liberation fontconfig
28
29WORKDIR /app
30
31COPY --from=builder /app/analytics ./analytics
32COPY --from=builder /app/dist ./dist
33COPY --from=builder /app/static_maps ./static_maps
34COPY templates ./templates
35COPY migrations ./migrations
36
37RUN addgroup -S -g 1000 app && \
38    adduser -S -h /app -s /sbin/nologin -u 1000 -G app app && \
39    mkdir -p /data && chown -R app:app /app /data
40USER app
41
42ENV PORT=8000
43ENV ANALYTICS_DATA_DIR=/data
44EXPOSE 8000
45
46CMD ["./analytics"]