-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
53 lines (37 loc) · 1.07 KB
/
Copy pathDockerfile
File metadata and controls
53 lines (37 loc) · 1.07 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
# Use Rust official image for building
FROM rust:1.70 as builder
WORKDIR /usr/src/rust_compress_api
# Copy manifests
COPY Cargo.toml Cargo.lock ./
# Create a dummy src/lib.rs file to build dependencies
RUN mkdir src && \
echo "fn main() {}" > src/main.rs
# Build dependencies only (for caching)
RUN cargo build --release
RUN rm -f target/release/rust_compress_api*
# Copy source code
COPY src ./src
# Build the application
RUN cargo build --release
# Use Debian slim image for runtime
FROM debian:bullseye-slim
# Install ca-certificates for HTTPS requests
RUN apt-get update && apt-get install -y \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Create app user
RUN useradd -ms /bin/bash app
# Set working directory
WORKDIR /app
# Copy binary from builder stage
COPY --from=builder /usr/src/rust_compress_api/target/release/rust_compress_api ./rust_compress_api
# Copy .env file
COPY .env .env
# Change ownership of files to app user
RUN chown -R app:app /app
# Switch to app user
USER app
# Expose port
EXPOSE 3000
# Run the application
CMD ["./rust_compress_api"]