ptth/crates/ptth_quic/Dockerfile

89 lines
2.8 KiB
Docker
Raw Permalink Normal View History

# https://whitfin.io/speeding-up-rust-docker-builds/
# TODO: https://stackoverflow.com/questions/57389547/how-to-define-the-context-for-a-docker-build-as-a-specific-commit-on-one-of-the
2022-12-15 23:02:08 +00:00
# docker pull rust:1.66-slim-buster
FROM rust@sha256:98c9b1fca0c9a6183369daf9efadb57c634340ae877bb027aeadf72afdd086a3 as build
WORKDIR /
ENV USER root
# create empty shell projects
RUN cargo new --bin ptth
WORKDIR /ptth
RUN \
cargo new --lib crates/always_equal && \
cargo new --lib crates/ptth_core && \
cargo new --bin crates/ptth_relay && \
cargo new --bin crates/ptth_server && \
cargo new --bin crates/ptth_file_server_bin && \
cargo new --bin tools/ptth_tail && \
cargo new --bin crates/debug_proxy && \
cargo new --bin crates/ptth_quic && \
cargo new --lib crates/udp_over_tcp
# copy over your manifests
COPY ./Cargo.lock ./
COPY ./Cargo.toml ./
COPY ./crates/always_equal/Cargo.toml ./crates/always_equal/
COPY ./crates/ptth_core/Cargo.toml ./crates/ptth_core/
COPY ./crates/ptth_relay/Cargo.toml ./crates/ptth_relay/
COPY ./crates/ptth_quic/Cargo.toml ./crates/ptth_quic/
COPY ./crates/udp_over_tcp/Cargo.toml ./crates/udp_over_tcp/
# this build step will cache your dependencies
RUN cargo build --release -p ptth_quic
RUN \
rm \
src/*.rs \
crates/always_equal/src/*.rs \
crates/ptth_core/src/*.rs \
crates/ptth_relay/src/*.rs \
2022-12-16 22:13:24 +00:00
crates/ptth_quic/src/*.rs \
crates/udp_over_tcp/src/*.rs
# Copy source tree
# Yes, I tried a few variations on the syntax. Dockerfiles are just rough.
COPY ./src/ ./src
COPY ./crates/always_equal ./crates/always_equal
COPY ./crates/ptth_core ./crates/ptth_core
COPY ./crates/ptth_relay ./crates/ptth_relay
COPY ./handlebars/ ./handlebars
COPY ./crates/ptth_quic ./crates/ptth_quic
2022-12-16 22:13:24 +00:00
COPY ./crates/udp_over_tcp ./crates/udp_over_tcp
# Bug in cargo's incremental build logic, triggered by
# Docker doing something funny with mtimes? Maybe?
RUN touch crates/ptth_core/src/lib.rs
# build for release
# gate only on ptth_relay tests for now
RUN \
2022-12-20 20:54:51 +00:00
find . && \
cargo build --release -p ptth_quic --bin ptth_quic_relay_server && \
cargo test --release -p ptth_quic --bin ptth_quic_relay_server
# debian:buster-slim
FROM debian@sha256:13f0764262a064b2dd9f8a828bbaab29bdb1a1a0ac6adc8610a0a5f37e514955
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y libssl1.1 ca-certificates tini
RUN addgroup --gid 10001 ptth_user && adduser --system --uid 10000 --gid 10001 ptth_user
USER ptth_user
WORKDIR /home/ptth_user
COPY --from=build /ptth/target/release/ptth_quic_relay_server ./
ARG git_version
2021-07-18 00:21:43 +00:00
RUN \
echo -n "$git_version" > ./git_version.txt && \
ln -s ptth_quic_relay_server app
CMD ["/usr/bin/tini", "--", "./ptth_quic_relay_server"]