2023-10-16 23:07:25 +00:00
# syntax=docker/dockerfile:1.5-labs
FROM rust:1.72.0 as builder
# Run with access to the target cache to speed up builds
WORKDIR /workspace
ADD . .
2023-10-26 05:28:40 +00:00
# Build the relay as a statically-linked binary. Unfortunately, we must specify the `--target` explicitly. See https://msfjarvis.dev/posts/building-static-rust-binaries-for-linux/.
2023-10-16 23:07:25 +00:00
RUN --mount= type = cache,target= ./target \
--mount= type = cache,target= /usr/local/cargo/registry \
2023-10-26 05:28:40 +00:00
RUSTFLAGS = '-C target-feature=+crt-static' cargo build --release --package relay --target $( rustc -vV | grep host | awk '{print $2}' )
2023-10-16 23:07:25 +00:00
RUN --mount= type = cache,target= ./target \
2023-10-26 05:28:40 +00:00
mv ./target/$( rustc -vV | grep host | awk '{print $2}' ) /release/relay /usr/local/bin/relay
2023-10-16 23:07:25 +00:00
FROM alpine:3
COPY --from= builder /usr/local/bin/relay /usr/bin/relay
RUN --mount= type = cache,target= /var/cache/apk apk add iproute2-tc
ENV RUST_BACKTRACE = 1
CMD [ "/usr/bin/relay" ]