💄 update: add dev mode and server Git version to server list
parent
0e4839e146
commit
532f99f770
15
Dockerfile
15
Dockerfile
|
@ -64,14 +64,17 @@ FROM debian@sha256:240f770008bdc538fecc8d3fa7a32a533eac55c14cbc56a9a8a6f7d741b47
|
||||||
|
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
&& apt-get upgrade -y \
|
&& apt-get upgrade -y \
|
||||||
&& apt-get install -y libssl1.1 ca-certificates tini \
|
&& apt-get install -y libssl1.1 ca-certificates tini
|
||||||
&& mkdir -p /root
|
|
||||||
|
|
||||||
COPY --from=build /ptth/target/release/ptth_relay /root/
|
RUN addgroup --gid 10001 nonroot && adduser --system --uid 10000 --gid 10001 nonroot
|
||||||
COPY --from=build /ptth/handlebars /root/handlebars
|
|
||||||
|
USER nonroot
|
||||||
|
WORKDIR /home/nonroot
|
||||||
|
|
||||||
|
COPY --from=build /ptth/target/release/ptth_relay ./
|
||||||
|
COPY --from=build /ptth/handlebars ./handlebars
|
||||||
|
|
||||||
ARG git_version
|
ARG git_version
|
||||||
RUN echo -n "$git_version" > /root/git_version.txt
|
RUN echo -n "$git_version" > ./git_version.txt
|
||||||
|
|
||||||
WORKDIR /root
|
|
||||||
ENTRYPOINT ["/usr/bin/tini", "--", "./ptth_relay"]
|
ENTRYPOINT ["/usr/bin/tini", "--", "./ptth_relay"]
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
pub fn read_git_version () -> Option <String> {
|
pub async fn read_git_version () -> Option <String> {
|
||||||
use std::{
|
use tokio::{
|
||||||
io::Read,
|
|
||||||
fs::File,
|
fs::File,
|
||||||
|
io::AsyncReadExt,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut buf = vec! [0u8; 512];
|
let mut buf = vec! [0u8; 512];
|
||||||
|
|
||||||
let mut f = File::open ("git_version.txt").ok ()?;
|
let mut f = File::open ("git_version.txt").await.ok ()?;
|
||||||
let bytes_read = f.read (&mut buf).ok ()?;
|
let bytes_read = f.read (&mut buf).await.ok ()?;
|
||||||
buf.truncate (bytes_read);
|
buf.truncate (bytes_read);
|
||||||
|
|
||||||
Some (String::from_utf8 (buf).ok ()?)
|
Some (String::from_utf8 (buf).ok ()?)
|
||||||
|
|
|
@ -336,15 +336,19 @@ struct ServerEntry <'a> {
|
||||||
|
|
||||||
#[derive (Serialize)]
|
#[derive (Serialize)]
|
||||||
struct ServerListPage <'a> {
|
struct ServerListPage <'a> {
|
||||||
|
dev_mode: bool,
|
||||||
|
git_version: Option <String>,
|
||||||
servers: Vec <ServerEntry <'a>>,
|
servers: Vec <ServerEntry <'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_server_list_internal (state: &Arc <RelayState>)
|
async fn handle_server_list_internal (state: &Arc <RelayState>)
|
||||||
-> ServerListPage <'static>
|
-> ServerListPage <'static>
|
||||||
{
|
{
|
||||||
|
let dev_mode;
|
||||||
let display_names: HashMap <String, String> = {
|
let display_names: HashMap <String, String> = {
|
||||||
let guard = state.config.read ().await;
|
let guard = state.config.read ().await;
|
||||||
|
|
||||||
|
dev_mode = guard.iso.dev_mode.is_some ();
|
||||||
let servers = (*guard).servers.iter ()
|
let servers = (*guard).servers.iter ()
|
||||||
.map (|(k, v)| {
|
.map (|(k, v)| {
|
||||||
let display_name = v.display_name
|
let display_name = v.display_name
|
||||||
|
@ -394,6 +398,8 @@ async fn handle_server_list_internal (state: &Arc <RelayState>)
|
||||||
servers.sort_by (|a, b| a.display_name.cmp (&b.display_name));
|
servers.sort_by (|a, b| a.display_name.cmp (&b.display_name));
|
||||||
|
|
||||||
ServerListPage {
|
ServerListPage {
|
||||||
|
dev_mode,
|
||||||
|
git_version: git_version::read_git_version ().await,
|
||||||
servers,
|
servers,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ 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?;
|
||||||
|
|
||||||
match read_git_version () {
|
match read_git_version ().await {
|
||||||
Some (x) => info! ("ptth_relay Git version: {:?}", x),
|
Some (x) => info! ("ptth_relay Git version: {:?}", x),
|
||||||
None => info! ("ptth_relay not built from Git"),
|
None => info! ("ptth_relay not built from Git"),
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,11 @@
|
||||||
|
|
||||||
<h1>Server list</h1>
|
<h1>Server list</h1>
|
||||||
|
|
||||||
|
{{#if dev_mode}}
|
||||||
|
<div style="color: red;">Relay is in dev mode. This should never be seen in production!</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
<div style="padding-top: 1em;">
|
||||||
{{#if servers}}
|
{{#if servers}}
|
||||||
<table class="entry_list">
|
<table class="entry_list">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -54,8 +59,17 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{{else}}
|
{{else}}
|
||||||
(No servers have reported since this relay started)
|
(No servers are registered in the config file)
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="color: #888; padding-top: 1em;">
|
||||||
|
{{#if git_version}}
|
||||||
|
Git version: {{git_version}}
|
||||||
|
{{else}}
|
||||||
|
Not built from Git
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
sudo docker run -it -v $PWD/config:/root/config -e RUST_LOG=ptth=trace ptth:latest
|
sudo docker run -it \
|
||||||
|
-v $PWD/config:/home/nonroot/config \
|
||||||
|
-e RUST_LOG=ptth=trace \
|
||||||
|
-p 4000:4000 \
|
||||||
|
ptth:latest
|
||||||
|
|
2
todo.md
2
todo.md
|
@ -1,9 +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`
|
||||||
|
|
||||||
- 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
|
|
||||||
- [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
|
||||||
- Track / Estimate bandwidth per server?
|
- Track / Estimate bandwidth per server?
|
||||||
- EOTPXGR3 Remote `tail -f` (_Complicated_) (Maybe use chunked encoding or something?)
|
- EOTPXGR3 Remote `tail -f` (_Complicated_) (Maybe use chunked encoding or something?)
|
||||||
|
|
Loading…
Reference in New Issue