-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
65 lines (48 loc) · 1.48 KB
/
Dockerfile
File metadata and controls
65 lines (48 loc) · 1.48 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
# syntax=docker/dockerfile:1.6
FROM rust:1.89-slim AS base
ENV RUSTFLAGS="-C link-arg=-s"
RUN apt-get update -y && apt-get install -y \
build-essential \
musl-tools \
pkg-config \
upx \
&& rm -rf /var/lib/apt/lists/*
RUN rustup target add aarch64-unknown-linux-musl
RUN \
# --mount=type=cache,target=/usr/local/cargo/registry \
cargo install cargo-chef --locked
ENV \
RUSTC_WRAPPER="" \
CARGO_INCREMENTAL=0
FROM base AS deps
WORKDIR /app
COPY Cargo.toml Cargo.lock ./
RUN mkdir -p src && echo "fn main() {}" > src/main.rs
RUN cargo chef prepare --recipe-path recipe.json && \
# --mount=type=cache,target=/usr/local/cargo/registry \
# --mount=type=cache,target=/usr/local/cargo/git \
# --mount=type=cache,target=/app/target \
cargo chef cook \
--release \
--target aarch64-unknown-linux-musl \
--recipe-path recipe.json
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/target target
COPY --from=deps /usr/local/cargo /usr/local/cargo
COPY Cargo.toml Cargo.lock ./
COPY src ./src
RUN \
# --mount=type=cache,target=/usr/local/cargo/registry \
# --mount=type=cache,target=/usr/local/cargo/git \
# --mount=type=cache,target=/app/target \
cargo build \
--bin app \
--release \
--target aarch64-unknown-linux-musl \
--offline
RUN strip --strip-unneeded target/aarch64-unknown-linux-musl/release/app && \
upx --ultra-brute --lzma target/aarch64-unknown-linux-musl/release/app
FROM scratch
COPY --from=builder /app/target/aarch64-unknown-linux-musl/release/app /app
CMD ["/app"]