-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
53 lines (34 loc) · 1.27 KB
/
Dockerfile
File metadata and controls
53 lines (34 loc) · 1.27 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
FROM rust:alpine3.21 AS builder
ARG TARGETPLATFORM="linux/amd64"
ARG VERSION
RUN apk add --no-cache musl-dev gcc make cmake g++
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
echo "x86_64-unknown-linux-musl" > /tmp/target; \
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
apk add --no-cache aarch64-linux-musl-gcc; \
echo "aarch64-unknown-linux-musl" > /tmp/target; \
else \
echo "unsupported platform" && exit 1; \
fi
RUN rustup default nightly-2025-02-03 && \
rustup target add "$(cat /tmp/target)"
COPY .cargo/ ./.cargo/
RUN cargo install -f --no-default-features --features "set-version" cargo-edit
WORKDIR /app
RUN cargo new --bin servitor
WORKDIR /app/servitor
COPY Cargo.toml Cargo.lock ./
RUN cargo build --release --locked --target --target "$(cat /tmp/target)"
RUN if [ ! -z "$VERSION" ]; then \
cargo set-version "${VERSION}"; \
fi
RUN rm src/*.rs
COPY src src/
RUN cargo build --release --locked --target-dir /target --target "$(cat /tmp/target)" && \
mv "/target/$(cat /tmp/target)/release/servitor" /target/servitor
FROM alpine:3.21
WORKDIR /app
RUN addgroup -S servitor && adduser -S servitor -G servitor
COPY --from=builder /target/servitor /app/servitor
USER servitor
ENTRYPOINT ["/app/servitor"]