-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
96 lines (71 loc) · 2.42 KB
/
Dockerfile
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
FROM rust:bookworm AS chef
# We only pay the installation cost once,
# it will be cached from the second build onwards
RUN cargo install cargo-chef
WORKDIR app
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
ARG FEATURES=""
# Install dependencies
RUN apt-get update && apt-get install -y \
libpython3-dev \
pkg-config \
protobuf-compiler \
&& rm -rf /var/lib/apt/lists/*
COPY rust-toolchain.toml .
COPY --from=planner /app/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json --no-default-features --features="$FEATURES"
FROM builder AS builder-cli
# Build application
COPY . .
RUN cargo build --release --bin sapiens_cli --no-default-features --features="$FEATURES"
FROM builder AS builder-bot
# Build application
COPY . .
RUN cargo build --release --bin sapiens_bot --no-default-features --features="$FEATURES"
FROM builder AS builder-exp
# Build application
COPY . .
RUN cargo build --release --bin sapiens_exp --no-default-features --features="$FEATURES"
# We do not need the Rust toolchain to run the binary!
FROM debian:bookworm-slim AS base-runtime
WORKDIR app
ARG USERNAME=not_me
ARG USER_UID=1000
ARG USER_GID=$USER_UID
# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
# Install dependencies
RUN apt-get update && apt-get install -y \
libpython3.11 \
python3-pip \
python3-venv \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
USER $USERNAME
RUN python3 -m venv /home/$USERNAME/.venv
ENV PATH="/home/$USERNAME/.venv/bin:$PATH"
RUN pip3 install --no-cache-dir arxiv requests numpy sympy bs4 feedparser urllib3 lxml pyyaml wikipedia
FROM base-runtime AS sapiens_cli
ARG USER_UID=1000
ARG USER_GID=$USER_UID
COPY --from=builder-cli /app/target/release/sapiens_cli /usr/local/bin/sapiens
USER $USER_UID:$USER_GID
ENTRYPOINT ["/usr/local/bin/sapiens"]
FROM base-runtime AS sapiens_bot
ARG USER_UID=1000
ARG USER_GID=$USER_UID
COPY --from=builder-bot /app/target/release/sapiens_bot /usr/local/bin/sapiens
USER $USER_UID:$USER_GID
ENTRYPOINT ["/usr/local/bin/sapiens"]
FROM base-runtime AS sapiens_exp
ARG USER_UID=1000
ARG USER_GID=$USER_UID
COPY --from=builder-exp /app/target/release/sapiens_exp /usr/local/bin/sapiens
VOLUME /app/experiments
USER $USER_UID:$USER_GID
ENTRYPOINT ["/usr/local/bin/sapiens"]