-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathDockerfile
65 lines (53 loc) · 2.95 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
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0
FROM --platform=${BUILDPLATFORM} rust:1.83 AS builder
ARG TARGETARCH
ARG TARGETPLATFORM
ARG BUILDPLATFORM
RUN echo Building on ${BUILDPLATFORM} for ${TARGETPLATFORM}
# Check if we are doing cross-compilation, if so we need to add in some more dependencies and run rustup
RUN if [ "${TARGETPLATFORM}" = "${BUILDPLATFORM}" ] ; then \
apt-get update && apt-get install --no-install-recommends -y g++ libc6-dev libprotobuf-dev protobuf-compiler ca-certificates; \
elif [ "${TARGETPLATFORM}" = "linux/arm64" ] ; then \
apt-get update && apt-get install --no-install-recommends -y g++-aarch64-linux-gnu libc6-dev-arm64-cross libprotobuf-dev protobuf-compiler ca-certificates && \
rustup target add aarch64-unknown-linux-gnu && \
rustup toolchain install stable-aarch64-unknown-linux-gnu; \
elif [ "${TARGETPLATFORM}" = "linux/amd64" ] ; then \
apt-get update && apt-get install --no-install-recommends -y g++-x86-64-linux-gnu libc6-amd64-cross libprotobuf-dev protobuf-compiler ca-certificates && \
rustup target add x86_64-unknown-linux-gnu && \
rustup toolchain install stable-x86_64-unknown-linux-gnu; \
else \
echo "${TARGETPLATFORM} is not supported"; \
exit 1; \
fi
WORKDIR /app/
COPY /src/shipping/ /app/
COPY /pb/ /app/proto/
# Compile or crosscompile
RUN if [ "${TARGETPLATFORM}" = "${BUILDPLATFORM}" ] ; then \
cargo build -r --features="dockerproto"; \
elif [ "${TARGETPLATFORM}" = "linux/arm64" ] ; then \
env CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \
CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ \
cargo build -r --features="dockerproto" --target aarch64-unknown-linux-gnu && \
cp /app/target/aarch64-unknown-linux-gnu/release/shipping /app/target/release/shipping; \
elif [ "${TARGETPLATFORM}" = "linux/amd64" ] ; then \
env CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc \
CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc \
CXX_x86_64_unknown_linux_gnu=x86_64-linux-gnu-g++ \
cargo build -r --features="dockerproto" --target x86_64-unknown-linux-gnu && \
cp /app/target/x86_64-unknown-linux-gnu/release/shipping /app/target/release/shipping; \
else \
echo "${TARGETPLATFORM} is not supported"; \
exit 1; \
fi
ENV GRPC_HEALTH_PROBE_VERSION=v0.4.24
RUN wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-${TARGETARCH} && \
chmod +x /bin/grpc_health_probe
FROM debian:bookworm-slim AS release
WORKDIR /app
COPY --from=builder /app/target/release/shipping /app/shipping
COPY --from=builder /bin/grpc_health_probe /bin/grpc_health_probe
EXPOSE ${SHIPPING_PORT}
ENTRYPOINT ["/app/shipping"]