-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathDockerfile
More file actions
71 lines (51 loc) · 1.86 KB
/
Dockerfile
File metadata and controls
71 lines (51 loc) · 1.86 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
# Cross-compile Dockerfile supporting both x86_64-unknown-linux-musl and
# aarch64-unknown-linux-musl targets using zig to link against musl libc. Note
# that this is to be used from an x86_64 host.
# --- build image
FROM rust:1.90 AS builder
RUN rustup target add \
aarch64-unknown-linux-musl \
x86_64-unknown-linux-musl
RUN update-ca-certificates
ENV ZIGVERSION=0.15.2
RUN ARCH=$(uname -m) && \
if [ "$ARCH" = "aarch64" ]; then ZIGARCH="aarch64"; else ZIGARCH="x86_64"; fi && \
wget https://ziglang.org/download/$ZIGVERSION/zig-$ZIGARCH-linux-$ZIGVERSION.tar.xz && \
tar -C /usr/local --strip-components=1 -xf zig-$ZIGARCH-linux-$ZIGVERSION.tar.xz && \
mv /usr/local/zig /usr/local/bin && \
rm zig-$ZIGARCH-linux-$ZIGVERSION.tar.xz
RUN cargo install --locked cargo-zigbuild
WORKDIR /app
COPY . .
RUN cargo zigbuild \
--release \
--target aarch64-unknown-linux-musl \
--target x86_64-unknown-linux-musl \
--bin wastebin \
--bin wastebin-ctl
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "10001" \
"app"
# --- x86_64-unknown-linux-musl final image
FROM scratch AS amd64
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
WORKDIR /app
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/wastebin ./
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/wastebin-ctl ./
USER app:app
CMD ["/app/wastebin"]
# --- aarch64-unknown-linux-musl final image
FROM scratch AS arm64
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
WORKDIR /app
COPY --from=builder /app/target/aarch64-unknown-linux-musl/release/wastebin ./
COPY --from=builder /app/target/aarch64-unknown-linux-musl/release/wastebin-ctl ./
USER app:app
CMD ["/app/wastebin"]