-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
114 lines (86 loc) · 2.96 KB
/
Dockerfile
File metadata and controls
114 lines (86 loc) · 2.96 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Multi-stage Dockerfile for FreeFace Rust Services
# This builds both the API server and Face Extraction service
# Build stage
FROM rust:1.82-bookworm as builder
# Install system dependencies for building
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
libclang-dev \
cmake \
build-essential \
protobuf-compiler \
curl \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /usr/src/freeface
# Copy manifests
COPY Cargo.toml Cargo.lock ./
COPY build.rs ./
# Copy proto files
COPY proto ./proto
# Copy source code
COPY src ./src
# Build the applications in release mode
RUN cargo build --release --bin api-server
RUN cargo build --release --bin extractor
# Runtime stage for API Server
FROM debian:bookworm-slim as api-server
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
&& rm -rf /var/lib/apt/lists/*
# Create app user
RUN groupadd -r appuser && useradd -r -g appuser appuser
# Copy the binary
COPY --from=builder /usr/src/freeface/target/release/api-server /usr/local/bin/api-server
# Copy .env file for dotenv
COPY .env /app/.env
# Create models directory
RUN mkdir -p /models && chown -R appuser:appuser /models && \
chown -R appuser:appuser /app
# Switch to app user and set working directory
USER appuser
WORKDIR /app
# Expose HTTP REST API port
EXPOSE 8080
# Health check for API server
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Run the API server
CMD ["api-server"]
# Runtime stage for Face Extraction Service
FROM debian:bookworm-slim as extractor
# Install runtime dependencies including ONNX Runtime
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
wget \
&& rm -rf /var/lib/apt/lists/*
# Install ONNX Runtime
RUN wget -q https://github.com/microsoft/onnxruntime/releases/download/v1.16.0/onnxruntime-linux-x64-1.16.0.tgz \
&& tar -xzf onnxruntime-linux-x64-1.16.0.tgz \
&& mv onnxruntime-linux-x64-1.16.0/lib/* /usr/local/lib/ \
&& mv onnxruntime-linux-x64-1.16.0/include/* /usr/local/include/ \
&& ldconfig \
&& rm -rf onnxruntime-linux-x64-1.16.0*
# Create app user
RUN groupadd -r appuser && useradd -r -g appuser appuser
# Copy the binary
COPY --from=builder /usr/src/freeface/target/release/extractor /usr/local/bin/extractor
# Copy .env file for dotenv
COPY .env /app/.env
# Create models directory and set permissions
RUN mkdir -p /models && chown -R appuser:appuser /models && \
chown -R appuser:appuser /app
# Switch to app user and set working directory
USER appuser
WORKDIR /app
# Expose gRPC port
EXPOSE 50051
# Health check for extractor service (disable for now - gRPC health check needs different approach)
# HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
# CMD grpc_health_probe -addr=localhost:50051 || exit 1
# Run the extractor service
CMD ["extractor"]