File size: 1,211 Bytes
4320690
 
94c29e9
4320690
94c29e9
 
 
 
4320690
 
 
 
 
780e76c
 
4320690
780e76c
 
4320690
780e76c
 
4320690
780e76c
 
4320690
 
 
 
 
 
 
 
94c29e9
 
 
 
 
 
 
 
4320690
 
94c29e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4320690
 
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
# Multi-stage build to reduce final image size and handle permissions properly
FROM rust:1.90-alpine AS builder

# Install build dependencies
RUN apk add --no-cache \
    musl-dev \
    pkgconfig \
    openssl-dev \
    openssl-libs-static

# Set working directory
WORKDIR /app

# Copy manifest files first
COPY Cargo.toml Cargo.lock ./

# Create src directory structure
RUN mkdir -p src

# Copy the actual source files (including api_server.rs)
COPY src ./src

# Build the application
RUN cargo build --release --bin api_server

# Final runtime stage
FROM alpine:3.20

# Install runtime dependencies
RUN apk add --no-cache \
    ca-certificates \
    openssl-libs-static

# Create app user
RUN addgroup -g 1001 -S appgroup && \
    adduser -S appuser -u 1001 -G appgroup

# Set working directory
WORKDIR /app

# Copy the binary from builder stage
COPY --from=builder /app/target/release/api_server .

# Change ownership to app user
RUN chown -R appuser:appgroup /app

# Switch to non-root user
USER appuser

# Expose the default port
EXPOSE 7860

# Set environment variables
ENV RUST_LOG=info
ENV API_HOST=0.0.0.0
ENV API_PORT=7860

# Run the application directly from binary
CMD ["./api_server", "--no-proxy"]