🚧 🐳 Experimenting with a new Dockerfile

main
_ 2020-12-01 14:47:55 +00:00
parent e8c020fbc6
commit 4cbb4b72ca
2 changed files with 68 additions and 3 deletions

View File

@ -17,11 +17,8 @@ tokio = { version = "0.2.22", features = ["full"] }
tracing = "0.1.21" tracing = "0.1.21"
tracing-subscriber = "0.2.15" tracing-subscriber = "0.2.15"
always_equal = { path = "crates/always_equal" }
ptth_core = { path = "crates/ptth_core" }
ptth_relay = { path = "crates/ptth_relay" } ptth_relay = { path = "crates/ptth_relay" }
ptth_server = { path = "crates/ptth_server" } ptth_server = { path = "crates/ptth_server" }
ptth_file_server = { path = "crates/ptth_file_server_bin" }
[workspace] [workspace]

68
new-Dockerfile Normal file
View File

@ -0,0 +1,68 @@
# Mix of https://whitfin.io/speeding-up-rust-docker-builds/
# and a "minimal Rust Docker image!" GH repo which was just
# "lol use Alpine duh"
FROM rust:1.47-slim-buster as build
#RUN apk add libseccomp-dev
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_file_server_bin && \
cargo new --bin crates/ptth_relay && \
cargo new --bin crates/ptth_server
# copy over your manifests
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml
COPY ./crates/always_equal/Cargo.toml ./crates/always_equal/Cargo.toml
COPY ./crates/ptth_core/Cargo.toml ./crates/ptth_core/Cargo.toml
COPY ./crates/ptth_relay/Cargo.toml ./crates/ptth_relay/Cargo.toml
COPY ./crates/ptth_file_server_bin/Cargo.toml ./crates/ptth_file_server_bin/Cargo.toml
COPY ./crates/ptth_server/Cargo.toml ./crates/ptth_server/Cargo.toml
# this build step will cache your dependencies
RUN cargo build --release -p ptth_relay
RUN \
rm \
src/*.rs \
crates/always_equal/src/*.rs \
crates/ptth_core/src/*.rs \
crates/ptth_file_server_bin/src/*.rs \
crates/ptth_relay/src/*.rs \
crates/ptth_server/src/*.rs
# copy source tree
COPY ./src ./src
COPY ./crates ./crates
COPY ./handlebars ./handlebars
# 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
RUN cargo build --release -p ptth_relay
FROM debian:buster-slim
RUN apt-get update \
&& apt-get install -y libssl1.1 ca-certificates \
&& apt-get upgrade -y
COPY --from=build /ptth/target/release/ptth_relay /root/ptth_relay
COPY --from=build /ptth/crates/ptth_relay/src/git_version.rs /root/git_version.rs
COPY --from=build /ptth/handlebars /root/handlebars
WORKDIR /root
ENTRYPOINT ["./ptth_relay"]