A very performant and light (2mb in memory) link shortener and tracker. Written in Rust and React and uses Postgres/SQLite.
1# Frontend build stage
2FROM oven/bun:latest AS frontend-builder
3
4WORKDIR /usr/src/frontend
5
6# Copy frontend files
7COPY frontend/package.json ./
8RUN bun install
9
10COPY frontend/ ./
11
12# Build frontend with production configuration
13ARG API_URL=http://localhost:8080
14ENV VITE_API_URL=${API_URL}
15RUN bun run build
16
17# Rust build stage
18FROM rust:latest AS backend-builder
19
20# Install PostgreSQL client libraries and SSL dependencies
21RUN apt-get update && \
22 apt-get install -y pkg-config libssl-dev libpq-dev && \
23 rm -rf /var/lib/apt/lists/*
24
25WORKDIR /usr/src/app
26
27# Copy manifests first (better layer caching)
28COPY Cargo.toml Cargo.lock ./
29
30# Copy source code and SQLx prepared queries
31COPY src/ src/
32COPY migrations/ migrations/
33COPY .sqlx/ .sqlx/
34
35# Create static directory and copy frontend build
36COPY --from=frontend-builder /usr/src/frontend/dist/ static/
37
38# Build the application
39RUN cargo build --release
40
41# Runtime stage
42FROM debian:bookworm-slim
43
44# Install runtime dependencies
45RUN apt-get update && \
46 apt-get install -y libpq5 ca-certificates openssl libssl3 && \
47 rm -rf /var/lib/apt/lists/*
48
49WORKDIR /app
50
51# Copy the binary from builder
52COPY --from=backend-builder /usr/src/app/target/release/simplelink /app/simplelink
53
54# Copy migrations folder for SQLx
55COPY --from=backend-builder /usr/src/app/migrations /app/migrations
56
57# Copy static files
58COPY --from=backend-builder /usr/src/app/static /app/static
59
60# Expose the port
61EXPOSE 8080
62
63# Set default network configuration
64ENV SERVER_HOST=0.0.0.0
65ENV SERVER_PORT=8080
66
67# Run the binary
68CMD ["./simplelink"]