-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathContainerfile
More file actions
96 lines (69 loc) · 3.24 KB
/
Copy pathContainerfile
File metadata and controls
96 lines (69 loc) · 3.24 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
# syntax=docker/dockerfile:1
# ------------------------------------------------------------------------------
# Stage 1: Build
# ------------------------------------------------------------------------------
FROM rust:1.96-alpine AS builder
ENV OPENSSL_STATIC=1
RUN apk add --no-cache musl-dev openssl-dev openssl-libs-static pkgconf cmake make g++
WORKDIR /src
# ------------------------------------------------------------------------------
# Cache Build
# ------------------------------------------------------------------------------
# Cache dependency builds: copy only manifests first, then
# create stub source files so `cargo build` resolves and
# compiles all dependencies without the real source code.
# Workspace manifests
COPY Cargo.toml Cargo.lock ./
COPY apis/Cargo.toml ./apis/Cargo.toml
COPY filters/Cargo.toml ./filters/Cargo.toml
COPY server/Cargo.toml ./server/Cargo.toml
# The server crate has a build.rs that discovers external filter
# crates via cargo metadata for build-time auto-registration.
COPY server/build.rs ./server/build.rs
# Strip workspace members not needed for the binary.
RUN sed -i '/xtask/d; /tests\//d' Cargo.toml
# Create stub source files for all crates.
RUN mkdir -p apis/src filters/src server/src \
&& echo '//! stub' > apis/src/lib.rs \
&& echo '//! stub' > filters/src/lib.rs \
&& echo '//! stub' > server/src/lib.rs \
&& printf '//! stub\nfn main() {}\n' > server/src/main.rs
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/src/target \
cargo build --release -p praxis-ai-proxy
# ------------------------------------------------------------------------------
# Cache Tricks
# ------------------------------------------------------------------------------
# Replace stubs with real source, then rebuild. Only the project
# crates recompile; all external dependencies are cached.
COPY apis/src ./apis/src
COPY filters/src ./filters/src
COPY server/src ./server/src
RUN find apis/src filters/src server/src \
-name '*.rs' -exec touch {} +
# ------------------------------------------------------------------------------
# Build
# ------------------------------------------------------------------------------
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/src/target \
cargo build --release -p praxis-ai-proxy \
&& cp target/release/praxis-ai /usr/local/bin/praxis-ai
# ------------------------------------------------------------------------------
# Stage 2: Runtime
# ------------------------------------------------------------------------------
FROM alpine:3.23
LABEL org.opencontainers.image.source="https://github.com/praxis-proxy/ai" \
org.opencontainers.image.description="Praxis AI proxy server" \
org.opencontainers.image.licenses="MIT"
RUN apk add --no-cache ca-certificates \
&& addgroup -S praxis \
&& adduser -S -G praxis -h /nonexistent -s /sbin/nologin praxis \
&& mkdir -p /etc/praxis
COPY --from=builder --chown=root:root --chmod=0555 \
/usr/local/bin/praxis-ai /usr/local/bin/praxis-ai
USER praxis:praxis
WORKDIR /etc/praxis
EXPOSE 8080 9901
HEALTHCHECK --interval=5s --timeout=3s --start-period=2s \
CMD wget -qO- http://127.0.0.1:9901/healthy || exit 1
ENTRYPOINT ["praxis-ai"]