From a491521ef720f5d88d1440ee877745b1e39b72e6 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 15 Jun 2023 19:59:53 +0200 Subject: [PATCH] feat(relay): add Dockerfile (#1661) This adds a basic Dockerfile for the relay so users and devs can easily start it. --- rust/.dockerignore | 1 + rust/relay.Dockerfile | 23 +++++++++++++++++++++++ rust/relay/README.md | 5 +++++ 3 files changed, 29 insertions(+) create mode 100644 rust/.dockerignore create mode 100644 rust/relay.Dockerfile diff --git a/rust/.dockerignore b/rust/.dockerignore new file mode 100644 index 000000000..2f7896d1d --- /dev/null +++ b/rust/.dockerignore @@ -0,0 +1 @@ +target/ diff --git a/rust/relay.Dockerfile b/rust/relay.Dockerfile new file mode 100644 index 000000000..fddb43a31 --- /dev/null +++ b/rust/relay.Dockerfile @@ -0,0 +1,23 @@ +# syntax=docker/dockerfile:1.5-labs +FROM rust:1.70-slim as builder + +WORKDIR /workspace +ADD . . +RUN --mount=type=cache,target=./target \ + --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/usr/local/rustup \ + rustup target add x86_64-unknown-linux-musl && \ + cargo build --release --bin relay --target x86_64-unknown-linux-musl + +RUN --mount=type=cache,target=./target \ + mv ./target/x86_64-unknown-linux-musl/release/relay /usr/local/bin/relay + +FROM scratch +COPY --from=builder /usr/local/bin/relay /usr/local/bin/relay +ENV RUST_BACKTRACE=1 + +EXPOSE 3478/udp +EXPOSE 49152-65535/udp + +# This purposely does not include an `init` process. Use `docker run --init` for proper signal handling. +ENTRYPOINT ["relay"] diff --git a/rust/relay/README.md b/rust/relay/README.md index 8caf6d83d..6120b5235 100644 --- a/rust/relay/README.md +++ b/rust/relay/README.md @@ -22,6 +22,11 @@ You can build the server using: `cargo build --release --bin relay` For a detailed help text and available configuration options, run `cargo run --bin relay -- --help`. +## Docker + +There is a docker image one directory up from this README: [Dockerfile](../relay.Dockerfile). +The Rust binary itself does not include any signal handling, thus you need to run the container with `--init` if you want to be able to CTRL+C the running container. + ## Design The relay is designed in a sans-IO fashion, meaning the core components do not cause side effects but operate as pure, synchronous state machines.