-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
50 lines (31 loc) · 1.16 KB
/
Copy pathDockerfile
File metadata and controls
50 lines (31 loc) · 1.16 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
# === Stage 1: Build tokei with Rust on Alpine 3.22 ===
FROM rust:alpine AS tokei-builder
RUN apk add --no-cache musl-dev
RUN cargo install tokei
# === Stage 2: Build Crystal app on Alpine ===
FROM crystallang/crystal:1-alpine AS crystal-builder
RUN apk add --no-cache git sqlite-dev
WORKDIR /app
COPY shard.yml shard.lock ./
RUN shards install --production
COPY . .
RUN crystal build --release src/main.cr -o /app/tokei-api
# === Final Stage: Minimal runtime ===
FROM alpine:latest
RUN apk add --no-cache git sqlite-libs libgcc libgc++ pcre2 \
rsvg-convert fontconfig freetype ttf-dejavu
WORKDIR /app
# Copy compiled Crystal binary
COPY --from=crystal-builder /app/tokei-api /app/tokei-api
# Copy static files (public directory)
COPY --from=crystal-builder /app/public /app/public
# Copy tokei binary built with newer Rust/Alpine
COPY --from=tokei-builder /usr/local/cargo/bin/tokei /usr/local/bin/tokei
# Create an unprivileged runtime user and writable temp directory
RUN addgroup -S tokei-api \
&& adduser -S -G tokei-api tokei-api \
&& mkdir -p /tmp/tokei-api \
&& chown -R tokei-api:tokei-api /tmp/tokei-api
USER tokei-api
EXPOSE 3000
CMD ["/app/tokei-api"]