-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (47 loc) · 1.87 KB
/
Dockerfile
File metadata and controls
68 lines (47 loc) · 1.87 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Multi-stage Dockerfile for SnapFileThing
# This Dockerfile builds a Rust backend and a Node.js frontend, optimizing for size and performance
# Stage 1: Frontend build
FROM node:18-alpine AS frontend-builder
# Set the working directory for the frontend build
WORKDIR /app/frontend
# Copy dependency files
COPY frontend/package*.json ./
# Install all dependencies (including dev for the build)
RUN npm ci
# Copy source code
COPY frontend/ ./
# Build the frontend
RUN npm run build
# Stage 2: Backend build
FROM rust:1.88-alpine AS builder
# Set the working directory for the backend build
WORKDIR /app
# Install build dependencies
RUN apk add --no-cache musl-dev curl
ENV CARGO_INCREMENTAL=1
# Copy dependency files first for better caching
COPY backend/Cargo.toml backend/Cargo.lock ./
# Create a dummy main.rs to build dependencies
RUN mkdir src && echo "fn main() {}" > src/main.rs
# Build dependencies (this layer will be cached if Cargo.toml doesn't change)
RUN cargo build --release && rm -rf src target/release/deps/snapfilething*
# Copy source code
COPY ./backend/src ./src
# Build the application with optimizations
RUN cargo build --release --locked \
&& strip target/release/snapfilething
# Runtime stage - ultra lightweight
FROM alpine:3.19 AS runtime
WORKDIR /app/backend
# Install only essential runtime dependencies
RUN apk add --no-cache ca-certificates libgcc
# Create uploads directory with proper permissions
RUN mkdir -p /uploads && chmod 755 /uploads
# Copy the frontend build from the frontend-builder stage
COPY --from=frontend-builder /app/frontend/dist /app/backend/../frontend/dist
# Copy the binary from builder stage
COPY --from=builder /app/target/release/snapfilething /app/backend/snapfilething
RUN chmod +x /app/backend/snapfilething
# Set uploads dir to the directory mounted in docker-compose
ENV UPLOAD_DIR=/uploads
ENTRYPOINT ["/app/backend/snapfilething"]