2020-12-12 01:53:20 +00:00
|
|
|
# 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
|
2020-11-02 18:02:01 +00:00
|
|
|
|
2020-12-12 05:18:29 +00:00
|
|
|
# rust:1.48-slim-buster
|
|
|
|
FROM rust@sha256:cb6b98346ef41a2062d4d8f099127d880f2ef7c1515d00215fc9ea713b99167b as build
|
2020-11-02 18:02:01 +00:00
|
|
|
|
2020-12-12 01:53:20 +00:00
|
|
|
#RUN apk add libseccomp-dev
|
|
|
|
|
|
|
|
WORKDIR /
|
|
|
|
ENV USER root
|
|
|
|
|
|
|
|
# create empty shell projects
|
|
|
|
RUN cargo new --bin ptth
|
|
|
|
|
|
|
|
WORKDIR /ptth
|
2020-11-02 18:02:01 +00:00
|
|
|
|
2020-12-12 01:53:20 +00:00
|
|
|
RUN \
|
|
|
|
cargo new --lib crates/always_equal && \
|
|
|
|
cargo new --lib crates/ptth_core && \
|
|
|
|
cargo new --bin crates/ptth_relay && \
|
2020-12-21 16:46:02 +00:00
|
|
|
cargo new --bin crates/ptth_server && \
|
|
|
|
cargo new --bin crates/ptth_file_server_bin && \
|
|
|
|
cargo new --bin tools/ptth_tail
|
2020-11-02 18:02:01 +00:00
|
|
|
|
2020-12-12 01:53:20 +00:00
|
|
|
# copy over your manifests
|
2020-12-21 16:46:02 +00:00
|
|
|
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_server/Cargo.toml ./crates/ptth_server/
|
|
|
|
# COPY ./crates/ptth_file_server_bin/Cargo.toml ./crates/ptth_file_server_bin/
|
|
|
|
# COPY ./tools/ptth_tail/Cargo.toml ./tools/ptth_tail/
|
2020-11-02 18:02:01 +00:00
|
|
|
|
2020-12-12 01:53:20 +00:00
|
|
|
# this build step will cache your dependencies
|
|
|
|
RUN cargo build --release -p ptth_relay
|
2020-11-02 18:02:01 +00:00
|
|
|
|
2020-12-12 01:53:20 +00:00
|
|
|
RUN \
|
|
|
|
rm \
|
|
|
|
src/*.rs \
|
|
|
|
crates/always_equal/src/*.rs \
|
|
|
|
crates/ptth_core/src/*.rs \
|
2020-12-21 16:46:02 +00:00
|
|
|
crates/ptth_relay/src/*.rs
|
2020-11-02 18:02:01 +00:00
|
|
|
|
2020-12-12 01:53:20 +00:00
|
|
|
# Copy source tree
|
|
|
|
# Yes, I tried a few variations on the syntax. Dockerfiles are just rough.
|
2020-11-02 18:02:01 +00:00
|
|
|
|
2020-12-21 16:46:02 +00:00
|
|
|
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
|
2020-11-02 18:02:01 +00:00
|
|
|
|
2020-12-12 01:53:20 +00:00
|
|
|
# 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 \
|
|
|
|
cargo build --release -p ptth_relay && \
|
|
|
|
cargo test --release -p ptth_relay
|
|
|
|
|
2020-12-12 05:18:29 +00:00
|
|
|
# debian:buster-slim
|
|
|
|
FROM debian@sha256:240f770008bdc538fecc8d3fa7a32a533eac55c14cbc56a9a8a6f7d741b47e33
|
2020-11-02 18:02:01 +00:00
|
|
|
|
|
|
|
RUN apt-get update \
|
2020-12-13 02:05:22 +00:00
|
|
|
&& apt-get upgrade -y \
|
2020-12-13 02:25:18 +00:00
|
|
|
&& apt-get install -y libssl1.1 ca-certificates tini
|
2020-11-02 18:02:01 +00:00
|
|
|
|
2020-12-13 02:25:18 +00:00
|
|
|
RUN addgroup --gid 10001 nonroot && adduser --system --uid 10000 --gid 10001 nonroot
|
|
|
|
|
|
|
|
USER nonroot
|
|
|
|
WORKDIR /home/nonroot
|
|
|
|
|
|
|
|
COPY --from=build /ptth/target/release/ptth_relay ./
|
|
|
|
COPY --from=build /ptth/handlebars ./handlebars
|
2020-11-02 18:02:01 +00:00
|
|
|
|
2020-12-13 02:05:22 +00:00
|
|
|
ARG git_version
|
2020-12-13 02:25:18 +00:00
|
|
|
RUN echo -n "$git_version" > ./git_version.txt
|
2020-12-13 02:05:22 +00:00
|
|
|
|
|
|
|
ENTRYPOINT ["/usr/bin/tini", "--", "./ptth_relay"]
|