-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (41 loc) · 1.13 KB
/
Copy pathDockerfile
File metadata and controls
57 lines (41 loc) · 1.13 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
# Stage 1: Build
FROM rust:alpine AS builder
# Install build dependencies
RUN apk add --no-cache musl-dev postgresql-dev
# Create app directory
WORKDIR /app
# Copy manifests
COPY Cargo.toml Cargo.lock ./
# Create a dummy main.rs to build dependencies
RUN mkdir src && \
echo "fn main() {}" > src/main.rs && \
cargo build --release && \
rm -rf src
# Copy source code and static assets
COPY src ./src
COPY static ./static
# Build the actual application
RUN touch src/main.rs && \
cargo build --release
# Stage 2: Runtime
FROM alpine:3.19
# Install runtime dependencies
RUN apk add --no-cache libgcc libpq wget
# Create non-root user
RUN addgroup -g 1000 zid && \
adduser -D -u 1000 -G zid zid
# Set working directory
WORKDIR /app
# Copy binary from builder
COPY --from=builder /app/target/release/zid /app/zid
# Change ownership
RUN chown -R zid:zid /app
# Switch to non-root user
USER zid
# Expose port
EXPOSE 5555
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:5555/health || exit 1
# Run the application
CMD ["/app/zid"]