-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from media-streaming-mesh/http-update
change from http::uri to tonic::transport::uri
- Loading branch information
Showing
5 changed files
with
133 additions
and
48 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ members = ["."] | |
|
||
[package] | ||
name = "msm_rtsp_stub" | ||
version = "0.0.1-dev" | ||
authors = ["Giles Heron <[email protected]>"] | ||
version = "0.0.2-dev" | ||
authors = ["Giles Heron <[email protected]>"] | ||
description = "RTSP Sidecar Stub Proxy written in Rust" | ||
homepage = "https://github.com/media-streaming-mesh/msm-rtsp-stub" | ||
repository = "https://github.com/media-streaming-mesh/msm-rtsp-stub" | ||
|
@@ -23,18 +23,17 @@ async-stream = "0.3.3" | |
bytes = "1.3.0" | ||
clap = { version = "4.2.7", features = ["derive"] } | ||
futures = "0.3.21" | ||
http = "0.2.6" | ||
h2 = "0.4" | ||
h2 = "0.4.4" | ||
log = "0.4.16" | ||
once_cell = "1.10.0" | ||
prost = "0.12.1" | ||
simple_logger = "5.0.0" | ||
tokio = { version = "1.28.1", features = ["macros", "rt", "signal"] } | ||
tokio-util = "0.7.8" | ||
prost = "0.12.4" | ||
simple_logger = "4.1.0" | ||
tokio = { version = "1.37.0", features = ["macros", "rt", "signal"] } | ||
tokio-util = "0.7.10" | ||
tonic = "0.11.0" | ||
void = "1.0.2" | ||
envmnt = "*" | ||
|
||
[build-dependencies] | ||
tonic-build = { version = "0.11.0", default_features = false, features = ["transport", "prost"] } | ||
prost-build = "0.12.0" | ||
prost-build = "0.12.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,141 @@ | ||
# syntax=docker/dockerfile:experimental | ||
#################################################################################################### | ||
## Builder | ||
#################################################################################################### | ||
FROM --platform=$BUILDPLATFORM rust:latest AS builder | ||
FROM --platform=linux/amd64 lukemathwalker/cargo-chef:latest-rust-latest AS amd64-chef | ||
FROM --platform=linux/arm64 lukemathwalker/cargo-chef:latest-rust-latest AS arm64-chef | ||
|
||
RUN update-ca-certificates | ||
# Base image for the build stage - this is a multi-stage build that uses cross-compilation (thanks to --platform switch) | ||
FROM --platform=$BUILDPLATFORM lukemathwalker/cargo-chef:latest-rust-latest AS chef | ||
WORKDIR /msm-rtsp-stub | ||
|
||
RUN apt clean | ||
RUN apt update | ||
# Planner stage | ||
FROM chef AS planner | ||
COPY . . | ||
RUN cargo chef prepare --recipe-path recipe.json | ||
|
||
# Builder stage | ||
FROM chef AS builder | ||
COPY --from=planner /msm-rtsp-stub/recipe.json recipe.json | ||
|
||
RUN apt-get -y install protobuf-compiler build-essential | ||
ARG BUILDARCH | ||
ARG TARGETPLATFORM | ||
ARG TARGETARCH | ||
|
||
RUN rustup update | ||
# Copy runtime dependencies for specific target platform/architecture | ||
# ARM specific folders | ||
WORKDIR /all-files/linux/arm64/lib/aarch64-linux-gnu | ||
|
||
ARG BUILDARCH TARGETARCH | ||
# AMD64 specific folders | ||
WORKDIR /all-files/linux/amd64/lib/x86_64-linux-gnu | ||
WORKDIR /all-files/linux/amd64/lib64 | ||
|
||
RUN if [ "$TARGETARCH" = "arm64" ]; then rustup target add aarch64-unknown-linux-gnu; fi; | ||
RUN if [ "$TARGETARCH" = "amd64" ]; then rustup target add x86_64-unknown-linux-gnu; fi; | ||
# Common folders | ||
WORKDIR /all-files/${TARGETPLATFORM}/etc/ssl/certs | ||
WORKDIR /all-files/${TARGETPLATFORM}/msm-rtsp-stub | ||
|
||
RUN if [ "$BUILDARCH" = "arm64" ]; then rustup toolchain add stable-aarch64-unknown-linux-gnu; fi; | ||
RUN if [ "$BUILDARCH" = "amd64" ]; then rustup toolchain add stable-x86_64-unknown-linux-gnu; fi; | ||
# ARM64 | ||
COPY --from=arm64-chef \ | ||
/lib/aarch64-linux-gnu/libssl.so.3 \ | ||
/lib/aarch64-linux-gnu/libcrypto.so.3 \ | ||
/lib/aarch64-linux-gnu/libgcc_s.so.1 \ | ||
/lib/aarch64-linux-gnu/libm.so.6 \ | ||
/lib/aarch64-linux-gnu/libc.so.6 \ | ||
/all-files/linux/arm64/lib/aarch64-linux-gnu/ | ||
|
||
COPY --from=arm64-chef \ | ||
/lib/ld-linux-aarch64.so.1 \ | ||
/all-files/linux/arm64/lib | ||
|
||
# AMD64 | ||
COPY --from=amd64-chef \ | ||
/lib/x86_64-linux-gnu/libssl.so.3 \ | ||
/lib/x86_64-linux-gnu/libcrypto.so.3 \ | ||
/lib/x86_64-linux-gnu/libgcc_s.so.1 \ | ||
/lib/x86_64-linux-gnu/libm.so.6 \ | ||
/lib/x86_64-linux-gnu/libc.so.6 \ | ||
/all-files/linux/amd64/lib/x86_64-linux-gnu/ | ||
|
||
COPY --from=amd64-chef \ | ||
/lib64/ld-linux-x86-64.so.2 \ | ||
/all-files/linux/amd64/lib64/ | ||
|
||
# Common files - certs | ||
COPY --from=amd64-chef \ | ||
/etc/ssl/certs/ca-certificates.crt \ | ||
/all-files/linux/amd64/etc/ssl/certs/ | ||
COPY --from=arm64-chef \ | ||
/etc/ssl/certs/ca-certificates.crt \ | ||
/all-files/linux/arm64/etc/ssl/certs/ | ||
|
||
WORKDIR /msm-rtsp-stub | ||
|
||
# install base dependencies - incuding protobuf compiler | ||
RUN update-ca-certificates | ||
RUN apt clean | ||
RUN apt update | ||
RUN apt-get -y install protobuf-compiler | ||
|
||
# Install dependencies for cross-compilation | ||
RUN if [ "$BUILDARCH" != "$TARGETARCH" ]; then \ | ||
if [ "$TARGETARCH" = "arm64" ]; then apt-get -y install crossbuild-essential-arm64; fi; \ | ||
if [ "$TARGETARCH" = "amd64" ]; then apt-get -y install crossbuild-essential-amd64; fi; \ | ||
if [ "$TARGETARCH" = "arm64" ]; then \ | ||
dpkg --add-architecture arm64 \ | ||
&& apt-get update \ | ||
&& apt-get install -y \ | ||
g++-aarch64-linux-gnu \ | ||
libc6-dev-arm64-cross \ | ||
libssl-dev:arm64 \ | ||
&& rustup target add aarch64-unknown-linux-gnu \ | ||
&& rustup toolchain install stable-aarch64-unknown-linux-gnu \ | ||
&& rm -rf /var/lib/apt/lists/*; \ | ||
elif [ "$TARGETARCH" = "amd64" ]; then \ | ||
dpkg --add-architecture amd64 \ | ||
&& apt-get update \ | ||
&& apt-get install -y \ | ||
g++-x86-64-linux-gnu \ | ||
libc6-dev-amd64-cross \ | ||
libssl-dev:amd64 \ | ||
&& rustup target add x86_64-unknown-linux-gnu \ | ||
&& rustup toolchain install stable-x86_64-unknown-linux-gnu \ | ||
&& rm -rf /var/lib/apt/lists/*; \ | ||
fi \ | ||
fi | ||
|
||
WORKDIR /msm-rtsp-stub | ||
# Build dependencies - this is the caching Docker layer! | ||
RUN case ${TARGETARCH} in \ | ||
arm64) PKG_CONFIG_SYSROOT_DIR=/ CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc cargo chef cook --target=aarch64-unknown-linux-gnu --release --recipe-path recipe.json ;; \ | ||
amd64) PKG_CONFIG_SYSROOT_DIR=/ CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc cargo chef cook --target=x86_64-unknown-linux-gnu --release --recipe-path recipe.json ;; \ | ||
*) exit 1 ;; \ | ||
esac | ||
|
||
# Copy the source code | ||
COPY . /msm-rtsp-stub | ||
|
||
# Build application - this is the caching Docker layer! | ||
RUN case ${TARGETARCH} in \ | ||
arm64) PKG_CONFIG_SYSROOT_DIR=/ CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc cargo build --target=aarch64-unknown-linux-gnu --release ;; \ | ||
amd64) PKG_CONFIG_SYSROOT_DIR=/ CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc cargo build --target=x86_64-unknown-linux-gnu --release ;; \ | ||
*) exit 1 ;; \ | ||
esac | ||
|
||
# Copy all the dependencies to a separate folder | ||
RUN set -ex; \ | ||
# Determine target (source folder for the binary and env files) | ||
if [ "$TARGETARCH" = "arm64" ]; then target='target/aarch64-unknown-linux-gnu/release'; fi; \ | ||
if [ "$TARGETARCH" = "amd64" ]; then target='target/x86_64-unknown-linux-gnu/release'; fi; \ | ||
# Copy files from the target folder to app folder | ||
cp $target/msm_rtsp_stub /all-files/${TARGETPLATFORM}/msm-rtsp-stub | ||
|
||
COPY ./ . | ||
# # Create a single layer image | ||
FROM scratch AS runtime | ||
|
||
RUN --mount=type=cache,target=/usr/local/cargo/registry \ | ||
--mount=type=cache,target=/msm-rtsp-stub/target \ | ||
touch .env; \ | ||
if [ "$TARGETARCH" = "arm64" ]; then export TARGET=aarch64-unknown-linux-gnu; else export TARGET=x86_64-unknown-linux-gnu; fi; \ | ||
echo TARGET=$TARGET > .env; \ | ||
cargo build --target $TARGET && cp target/$TARGET/debug/msm_rtsp_stub . | ||
# Make build arguments available in the runtime stage | ||
ARG TARGETPLATFORM | ||
ARG TARGETARCH | ||
|
||
#################################################################################################### | ||
## Final image | ||
#################################################################################################### | ||
FROM ubuntu | ||
WORKDIR /app | ||
|
||
WORKDIR / | ||
# Copy the binary as a single layer | ||
COPY --from=builder /all-files/${TARGETPLATFORM}/msm-rtsp-stub / | ||
|
||
# Copy our build | ||
COPY --from=builder /msm-rtsp-stub/msm_rtsp_stub . | ||
# Expose the port that the application listens on. | ||
EXPOSE 8554 | ||
|
||
# Run the application | ||
ENTRYPOINT ["/msm_rtsp_stub"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters