-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (37 loc) · 1.45 KB
/
Copy pathDockerfile
File metadata and controls
47 lines (37 loc) · 1.45 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
FROM rust:1.97.0 AS chef
RUN cargo install cargo-chef --locked
WORKDIR /app
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
ARG TARGETARCH
RUN apt-get update \
&& apt-get install -y --no-install-recommends musl-tools clang libclang-dev protobuf-compiler \
&& rm -rf /var/lib/apt/lists/*
COPY --from=planner /app/recipe.json recipe.json
# Cook dependencies in their own layer. As long as recipe.json is unchanged
# (i.e. no dependency changes), this layer is reused and only application code
# is recompiled below.
RUN case "$TARGETARCH" in \
amd64) TRIPLE="x86_64-unknown-linux-musl" ;; \
arm64) TRIPLE="aarch64-unknown-linux-musl" ;; \
*) echo "Unsupported TARGETARCH: $TARGETARCH" >&2; exit 1 ;; \
esac \
&& echo "$TRIPLE" > /triple \
&& rustup target add "$TRIPLE" \
&& CC=musl-gcc \
RUSTFLAGS="-C linker=musl-gcc" \
cargo chef cook --release --target "$TRIPLE" --recipe-path recipe.json
COPY . .
RUN TRIPLE="$(cat /triple)" \
&& CC=musl-gcc \
RUSTFLAGS="-C linker=musl-gcc" \
cargo build --release --target "$TRIPLE" \
&& cp "target/$TRIPLE/release/diesel-guard" /diesel-guard
FROM alpine:3
RUN addgroup -g 1000 diesel && adduser -u 1000 -G diesel -s /bin/sh -D diesel
COPY --from=builder /diesel-guard /usr/local/bin/diesel-guard
RUN chown diesel:diesel /usr/local/bin/diesel-guard
USER diesel
ENTRYPOINT ["/usr/local/bin/diesel-guard"]