-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile
87 lines (70 loc) · 2.16 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
# Copyright AGNTCY Contributors (https://github.com/agntcy)
# SPDX-License-Identifier: Apache-2.0
# Build container
FROM --platform=${BUILDPLATFORM} rust:1.83-slim-bookworm AS rust
SHELL ["/bin/bash", "-c"]
ARG TARGETARCH
RUN DEBIAN_FRONTEND=noninteractive \
apt-get update && \
apt-get install --no-install-recommends -y \
curl \
file \
make \
unzip \
git \
pkg-config \
clang-14 \
llvm-14
# Install taskfile
RUN sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin
# Copy source code
COPY . /app
WORKDIR /app/data-plane
RUN <<EOF
case ${TARGETARCH} in
"amd64")
PACKAGES="gcc-x86-64-linux-gnu g++-x86-64-linux-gnu"
RUSTARCH="x86_64-unknown-linux-gnu"
;;
"arm64")
PACKAGES="gcc-aarch64-linux-gnu g++-aarch64-linux-gnu"
RUSTARCH="aarch64-unknown-linux-gnu"
;;
*)
echo "Unsupported platform: ${TARGETPLATFORM}"
exit 1
;;
esac
apt-get update && apt-get install -y ${PACKAGES}
# Fetch rust packages
task -v data-plane:fetch TARGET=${RUSTARCH}
EOF
# Build debug application
RUN <<EOF
case ${TARGETARCH} in
"amd64")
RUSTARCH=x86_64
;;
"arm64")
RUSTARCH=aarch64
;;
*)
echo "Unsupported platform: ${TARGETPLATFORM}"
exit 1
;;
esac
# Build application
task -v data-plane:build:strip TARGET=${RUSTARCH}-unknown-linux-gnu PROFILE=release
mv target/${RUSTARCH}-unknown-linux-gnu target/${TARGETARCH}-unknown-linux-gnu
EOF
# runtime images - debug executable, debug symbols and, most importantly, a shell :)
FROM debian:bookworm-slim AS debug
ARG TARGETARCH
# copy the build artifacts from the build stage
COPY --from=rust /app/data-plane/target/${TARGETARCH}-unknown-linux-gnu/release/gateway /gateway
COPY --from=rust /app/data-plane/target/${TARGETARCH}-unknown-linux-gnu/release/gateway.dbg /gateway.dbg
# runtime images - release executable
FROM gcr.io/distroless/cc-debian12:nonroot AS release
ARG TARGETARCH
# copy the artifacts from the build stage
COPY --from=rust /app/data-plane/target/${TARGETARCH}-unknown-linux-gnu/release/gateway /gateway