diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1611ea0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +media/*.mp4 +target/* +cert/* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..733f7d6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,44 @@ +FROM rust:latest as builder + +# Make a fake Rust app to keep a cached layer of compiled crates +RUN USER=root cargo new app +WORKDIR /usr/src/app +COPY Cargo.toml Cargo.lock ./ + +RUN mkdir -p moq-transport/src moq-quinn/src moq-warp/src moq-pub/src +COPY moq-transport/Cargo.toml moq-transport/Cargo.toml +COPY moq-quinn/Cargo.toml moq-quinn/Cargo.toml +COPY moq-pub/Cargo.toml moq-pub/Cargo.toml +COPY moq-warp/Cargo.toml moq-warp/Cargo.toml +RUN touch moq-transport/src/lib.rs +RUN touch moq-warp/src/lib.rs +RUN touch moq-pub/src/lib.rs +RUN touch moq-quinn/src/lib.rs + +RUN sed -i '/default-run.*/d' moq-quinn/Cargo.toml + +# Will build all dependent crates in release mode +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/usr/src/app/target \ + cargo build --release + +# Copy the rest +COPY . . + +# Build (install) the actual binaries +RUN cargo install --path moq-quinn + +# Runtime image +FROM rust:latest + +# Run as "app" user +RUN useradd -ms /bin/bash app + +USER app +WORKDIR /app + +# Get compiled binaries from builder's cargo install directory +COPY --from=builder /usr/local/cargo/bin/moq-quinn /app/moq-quinn + +ADD entrypoint.sh . +# No CMD or ENTRYPOINT, see fly.toml with `cmd` override. diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..6562f70 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +mkdir cert +# Nothing to see here... +echo "$MOQ_CRT" | base64 -d > cert/moq-demo.crt +echo "$MOQ_KEY" | base64 -d > cert/moq-demo.key + +RUST_LOG=info ./moq-quinn --cert cert/moq-demo.crt --key cert/moq-demo.key diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..cf62599 --- /dev/null +++ b/fly.toml @@ -0,0 +1,19 @@ +app = "englishm-moq-relay" +kill_signal = "SIGINT" +kill_timeout = 5 + +[env] + PORT = "4443" + +[experimental] + cmd = "./entrypoint.sh" + +[[services]] + internal_port = 4443 + protocol = "udp" + [services.concurrency] + hard_limit = 25 + soft_limit = 20 + + [[services.ports]] + port = "4443"