diff --git a/Dockerfile b/Dockerfile index 0e13bd0..48b1753 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,9 +53,6 @@ COPY ./handlebars/ ./handlebars # Docker doing something funny with mtimes? Maybe? RUN touch crates/ptth_core/src/lib.rs -ARG git_version -RUN echo -n "$git_version" > crates/ptth_relay/src/git_version.txt - # build for release # gate only on ptth_relay tests for now RUN \ @@ -66,12 +63,15 @@ cargo test --release -p ptth_relay FROM debian@sha256:240f770008bdc538fecc8d3fa7a32a533eac55c14cbc56a9a8a6f7d741b47e33 RUN apt-get update \ -&& apt-get install -y libssl1.1 ca-certificates \ -&& apt-get upgrade -y +&& apt-get upgrade -y \ +&& apt-get install -y libssl1.1 ca-certificates tini \ +&& mkdir -p /root COPY --from=build /ptth/target/release/ptth_relay /root/ -COPY --from=build /ptth/crates/ptth_relay/src/git_version.txt /root/ COPY --from=build /ptth/handlebars /root/handlebars +ARG git_version +RUN echo -n "$git_version" > /root/git_version.txt + WORKDIR /root -ENTRYPOINT ["./ptth_relay"] +ENTRYPOINT ["/usr/bin/tini", "--", "./ptth_relay"] diff --git a/crates/ptth_relay/src/git_version.rs b/crates/ptth_relay/src/git_version.rs index 12a4fd8..7a1dc70 100644 --- a/crates/ptth_relay/src/git_version.rs +++ b/crates/ptth_relay/src/git_version.rs @@ -1 +1,14 @@ -pub const GIT_VERSION: &str = include_str! ("git_version.txt"); +pub fn read_git_version () -> Option { + use std::{ + io::Read, + fs::File, + }; + + let mut buf = vec! [0u8; 512]; + + let mut f = File::open ("git_version.txt").ok ()?; + let bytes_read = f.read (&mut buf).ok ()?; + buf.truncate (bytes_read); + + Some (String::from_utf8 (buf).ok ()?) +} diff --git a/crates/ptth_relay/src/git_version.txt b/crates/ptth_relay/src/git_version.txt deleted file mode 100644 index d5d3349..0000000 --- a/crates/ptth_relay/src/git_version.txt +++ /dev/null @@ -1 +0,0 @@ -(Unknown) \ No newline at end of file diff --git a/crates/ptth_relay/src/main.rs b/crates/ptth_relay/src/main.rs index c8d1bce..bd3c9c6 100644 --- a/crates/ptth_relay/src/main.rs +++ b/crates/ptth_relay/src/main.rs @@ -16,7 +16,7 @@ use tracing_subscriber::{ use ptth_relay::{ Config, - git_version::GIT_VERSION, + git_version::read_git_version, RelayState, run_relay, }; @@ -32,7 +32,10 @@ async fn main () -> Result <(), Box > { let config_path = PathBuf::from ("config/ptth_relay.toml"); let config = Config::from_file (&config_path).await?; - info! ("ptth_relay Git version: {:?}", GIT_VERSION); + match read_git_version () { + Some (x) => info! ("ptth_relay Git version: {:?}", x), + None => info! ("ptth_relay not built from Git"), + } let (shutdown_rx, forced_shutdown) = ptth_core::graceful_shutdown::init_with_force (); diff --git a/todo.md b/todo.md index 4d1598c..f96bb92 100644 --- a/todo.md +++ b/todo.md @@ -1,7 +1,7 @@ Interesting issues will get a unique ID with `dd if=/dev/urandom bs=5 count=1 | base32` -- Diagram dependencies +- Move Git version out of source code and into a plain file in the Docker image - Report server version in HTML - Apply https://github.com/hexops/dockerfile to Dockerfile - [YNQAQKJS](issues/2020-12Dec/auth-route-YNQAQKJS.md) Open new auth route for spiders / scrapers