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
3WORKDIR /app/frontend
4
5# Install bun
6RUN curl -fsSL https://bun.sh/install | bash
7ENV PATH="/root/.bun/bin:${PATH}"
8
9# Copy frontend files
10COPY frontend/package.json frontend/bun.lock ./
11RUN bun install
12
13COPY frontend/ ./
14
15# Build frontend with environment variables
16# These can be overridden at build time
17ARG VITE_API_URL=http://localhost:3000
18ARG NODE_ENV=production
19ENV VITE_API_URL=$VITE_API_URL
20ENV NODE_ENV=$NODE_ENV
21
22RUN echo "VITE_API_URL=${VITE_API_URL}" > .env.production
23RUN bun run build
24
25# Rust build stage
26FROM rust:latest as backend-builder
27
28# Install PostgreSQL client libraries and SSL dependencies
29RUN apt-get update && \
30 apt-get install -y pkg-config libssl-dev libpq-dev && \
31 rm -rf /var/lib/apt/lists/*
32
33WORKDIR /usr/src/app
34
35# Copy manifests first (better layer caching)
36COPY Cargo.toml Cargo.lock ./
37
38# Copy source code and SQLx prepared queries
39COPY src/ src/
40COPY migrations/ migrations/
41COPY .sqlx/ .sqlx/
42
43# Build application
44ARG RUST_ENV=release
45RUN cargo build --${RUST_ENV}
46
47# Runtime stage
48FROM debian:bookworm-slim
49
50# Install runtime dependencies
51RUN apt-get update && \
52 apt-get install -y libpq5 ca-certificates openssl libssl3 && \
53 rm -rf /var/lib/apt/lists/*
54
55WORKDIR /app
56
57# Copy the binary and migrations from backend builder
58COPY --from=backend-builder /usr/src/app/target/release/simplelink /app/simplelink
59COPY --from=backend-builder /usr/src/app/migrations /app/migrations
60
61# Copy static files from frontend builder
62COPY --from=frontend-builder /app/frontend/dist /app/static
63
64# Expose the port
65EXPOSE 3000
66
67# Set default network configuration
68ENV SERVER_HOST=0.0.0.0
69ENV SERVER_PORT=3000
70
71# Run the binary
72CMD ["./simplelink"]