🐳 build: add Tini to Docker image, simplify Git version injection
Building the Git version into the code meant that Cargo had to recompile ptth_relay every time I built. This is annoying and it doesn't add anything. I changed it to read the Git version from a text file which is absent by default, and present in the Docker image.main
parent
dc2958ad7a
commit
0e4839e146
14
Dockerfile
14
Dockerfile
|
@ -53,9 +53,6 @@ COPY ./handlebars/ ./handlebars
|
||||||
# Docker doing something funny with mtimes? Maybe?
|
# Docker doing something funny with mtimes? Maybe?
|
||||||
RUN touch crates/ptth_core/src/lib.rs
|
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
|
# build for release
|
||||||
# gate only on ptth_relay tests for now
|
# gate only on ptth_relay tests for now
|
||||||
RUN \
|
RUN \
|
||||||
|
@ -66,12 +63,15 @@ cargo test --release -p ptth_relay
|
||||||
FROM debian@sha256:240f770008bdc538fecc8d3fa7a32a533eac55c14cbc56a9a8a6f7d741b47e33
|
FROM debian@sha256:240f770008bdc538fecc8d3fa7a32a533eac55c14cbc56a9a8a6f7d741b47e33
|
||||||
|
|
||||||
RUN apt-get update \
|
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/target/release/ptth_relay /root/
|
||||||
COPY --from=build /ptth/crates/ptth_relay/src/git_version.txt /root/
|
|
||||||
COPY --from=build /ptth/handlebars /root/handlebars
|
COPY --from=build /ptth/handlebars /root/handlebars
|
||||||
|
|
||||||
|
ARG git_version
|
||||||
|
RUN echo -n "$git_version" > /root/git_version.txt
|
||||||
|
|
||||||
WORKDIR /root
|
WORKDIR /root
|
||||||
ENTRYPOINT ["./ptth_relay"]
|
ENTRYPOINT ["/usr/bin/tini", "--", "./ptth_relay"]
|
||||||
|
|
|
@ -1 +1,14 @@
|
||||||
pub const GIT_VERSION: &str = include_str! ("git_version.txt");
|
pub fn read_git_version () -> Option <String> {
|
||||||
|
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 ()?)
|
||||||
|
}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
(Unknown)
|
|
|
@ -16,7 +16,7 @@ use tracing_subscriber::{
|
||||||
|
|
||||||
use ptth_relay::{
|
use ptth_relay::{
|
||||||
Config,
|
Config,
|
||||||
git_version::GIT_VERSION,
|
git_version::read_git_version,
|
||||||
RelayState,
|
RelayState,
|
||||||
run_relay,
|
run_relay,
|
||||||
};
|
};
|
||||||
|
@ -32,7 +32,10 @@ async fn main () -> Result <(), Box <dyn Error>> {
|
||||||
let config_path = PathBuf::from ("config/ptth_relay.toml");
|
let config_path = PathBuf::from ("config/ptth_relay.toml");
|
||||||
let config = Config::from_file (&config_path).await?;
|
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 ();
|
let (shutdown_rx, forced_shutdown) = ptth_core::graceful_shutdown::init_with_force ();
|
||||||
|
|
||||||
|
|
2
todo.md
2
todo.md
|
@ -1,7 +1,7 @@
|
||||||
Interesting issues will get a unique ID with
|
Interesting issues will get a unique ID with
|
||||||
`dd if=/dev/urandom bs=5 count=1 | base32`
|
`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
|
- Report server version in HTML
|
||||||
- Apply https://github.com/hexops/dockerfile to Dockerfile
|
- Apply https://github.com/hexops/dockerfile to Dockerfile
|
||||||
- [YNQAQKJS](issues/2020-12Dec/auth-route-YNQAQKJS.md) Open new auth route for spiders / scrapers
|
- [YNQAQKJS](issues/2020-12Dec/auth-route-YNQAQKJS.md) Open new auth route for spiders / scrapers
|
||||||
|
|
Loading…
Reference in New Issue