Minor cleanup & Dockerfile

This commit is contained in:
Garrett Mills 2025-02-23 13:29:38 -05:00
parent c89d94dd66
commit c95a73401e
8 changed files with 65 additions and 239 deletions

230
Cargo.lock generated
View File

@ -502,15 +502,6 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "crossbeam-channel"
version = "0.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2"
dependencies = [
"crossbeam-utils",
]
[[package]] [[package]]
name = "crossbeam-queue" name = "crossbeam-queue"
version = "0.3.11" version = "0.3.11"
@ -780,18 +771,6 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "filetime"
version = "0.2.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35c0522e981e68cbfa8c3f978441a5f34b30b96e146b33cd3359176b50fe8586"
dependencies = [
"cfg-if",
"libc",
"libredox",
"windows-sys 0.59.0",
]
[[package]] [[package]]
name = "flate2" name = "flate2"
version = "1.0.34" version = "1.0.34"
@ -843,15 +822,6 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "fsevent-sys"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "funty" name = "funty"
version = "2.0.0" version = "2.0.0"
@ -1023,20 +993,6 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "handlebars"
version = "5.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b"
dependencies = [
"log",
"pest",
"pest_derive",
"serde",
"serde_json",
"thiserror",
]
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.12.3" version = "0.12.3"
@ -1270,26 +1226,6 @@ version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8fae54786f62fb2918dcfae3d568594e50eb9b5c25bf04371af6fe7516452fb" checksum = "c8fae54786f62fb2918dcfae3d568594e50eb9b5c25bf04371af6fe7516452fb"
[[package]]
name = "inotify"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff"
dependencies = [
"bitflags 1.3.2",
"inotify-sys",
"libc",
]
[[package]]
name = "inotify-sys"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "instant" name = "instant"
version = "0.1.13" version = "0.1.13"
@ -1340,26 +1276,6 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "kqueue"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c"
dependencies = [
"kqueue-sys",
"libc",
]
[[package]]
name = "kqueue-sys"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b"
dependencies = [
"bitflags 1.3.2",
"libc",
]
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "1.5.0" version = "1.5.0"
@ -1381,17 +1297,6 @@ version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa"
[[package]]
name = "libredox"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [
"bitflags 2.6.0",
"libc",
"redox_syscall 0.5.7",
]
[[package]] [[package]]
name = "libsqlite3-sys" name = "libsqlite3-sys"
version = "0.30.1" version = "0.30.1"
@ -1512,18 +1417,6 @@ dependencies = [
"adler2", "adler2",
] ]
[[package]]
name = "mio"
version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c"
dependencies = [
"libc",
"log",
"wasi",
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "mio" name = "mio"
version = "1.0.2" version = "1.0.2"
@ -1582,34 +1475,6 @@ dependencies = [
"minimal-lexical", "minimal-lexical",
] ]
[[package]]
name = "normpath"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8911957c4b1549ac0dc74e30db9c8b0e66ddcd6d7acc33098f4c63a64a6d7ed"
dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "notify"
version = "6.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d"
dependencies = [
"bitflags 2.6.0",
"crossbeam-channel",
"filetime",
"fsevent-sys",
"inotify",
"kqueue",
"libc",
"log",
"mio 0.8.11",
"walkdir",
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "nu-ansi-term" name = "nu-ansi-term"
version = "0.46.0" version = "0.46.0"
@ -1803,7 +1668,6 @@ dependencies = [
"log", "log",
"proxmox-api", "proxmox-api",
"rocket", "rocket",
"rocket_dyn_templates",
"sea-orm", "sea-orm",
"sea-orm-migration", "sea-orm-migration",
"sea-orm-rocket", "sea-orm-rocket",
@ -1913,51 +1777,6 @@ version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]]
name = "pest"
version = "2.7.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "879952a81a83930934cbf1786752d6dedc3b1f29e8f8fb2ad1d0a36f377cf442"
dependencies = [
"memchr",
"thiserror",
"ucd-trie",
]
[[package]]
name = "pest_derive"
version = "2.7.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d214365f632b123a47fd913301e14c946c61d1c183ee245fa76eb752e59a02dd"
dependencies = [
"pest",
"pest_generator",
]
[[package]]
name = "pest_generator"
version = "2.7.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb55586734301717aea2ac313f50b2eb8f60d2fc3dc01d190eefa2e625f60c4e"
dependencies = [
"pest",
"pest_meta",
"proc-macro2",
"quote",
"syn 2.0.86",
]
[[package]]
name = "pest_meta"
version = "2.7.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b75da2a70cf4d9cb76833c990ac9cd3923c9a8905a8929789ce347c84564d03d"
dependencies = [
"once_cell",
"pest",
"sha2",
]
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.15" version = "0.2.15"
@ -2370,19 +2189,6 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "rocket_dyn_templates"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bbab919c9e67df3f7ac6624a32ef897df4cd61c0969f4d66f3ced0534660d7a"
dependencies = [
"handlebars",
"normpath",
"notify",
"rocket",
"walkdir",
]
[[package]] [[package]]
name = "rocket_http" name = "rocket_http"
version = "0.5.1" version = "0.5.1"
@ -2509,15 +2315,6 @@ version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]] [[package]]
name = "schannel" name = "schannel"
version = "0.1.26" version = "0.1.26"
@ -3336,7 +3133,7 @@ dependencies = [
"backtrace", "backtrace",
"bytes", "bytes",
"libc", "libc",
"mio 1.0.2", "mio",
"pin-project-lite", "pin-project-lite",
"signal-hook-registry", "signal-hook-registry",
"socket2", "socket2",
@ -3502,12 +3299,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "ucd-trie"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971"
[[package]] [[package]]
name = "uncased" name = "uncased"
version = "0.9.10" version = "0.9.10"
@ -3625,16 +3416,6 @@ version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "walkdir"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
dependencies = [
"same-file",
"winapi-util",
]
[[package]] [[package]]
name = "want" name = "want"
version = "0.3.1" version = "0.3.1"
@ -3746,15 +3527,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [
"windows-sys 0.59.0",
]
[[package]] [[package]]
name = "winapi-x86_64-pc-windows-gnu" name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"

View File

@ -12,7 +12,6 @@ sea-orm-rocket = "0.5.4"
serde = { version = "1.0.214", features = ["derive"] } serde = { version = "1.0.214", features = ["derive"] }
tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros"] } tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros"] }
async-trait = "0.1.83" async-trait = "0.1.83"
rocket_dyn_templates = { version = "0.2.0", features = ["handlebars"] }
sea-orm-migration = "1.1.0" sea-orm-migration = "1.1.0"
uuid = { version = "1.11.0", features = ["v4", "fast-rng"] } uuid = { version = "1.11.0", features = ["v4", "fast-rng"] }
ssh2 = "0.9.4" ssh2 = "0.9.4"

21
Dockerfile Normal file
View File

@ -0,0 +1,21 @@
FROM ubuntu:24.04
RUN groupadd --gid 3450 p5x \
&& useradd --uid 3450 --gid 3450 p5x \
&& mkdir -p /p5x/data \
&& chown -R p5x:p5x /p5x \
&& chmod 755 /p5x \
&& usermod -d /p5x p5x
COPY ./target/x86_64-unknown-linux-gnu/release/p5x /p5x/p5x
COPY Rocket.toml /p5x/Rocket.toml
WORKDIR /p5x
USER p5x:p5x
ENV ROCKET_PROFILE="docker"
ENV RUST_LOG="p5x=debug,sqlx=warn,info"
ENV P5X_SSH_PUBKEY_PATH="/p5x/data/ssh-pubkey.pem"
ENV P5X_SSH_PRIVKEY_PATH="/p5x/data/ssh-privkey.pem"
CMD ["/p5x/p5x", "api-server"]

View File

@ -1,5 +1,4 @@
[default] [default]
template_dir = "resources/views"
address = "0.0.0.0" address = "0.0.0.0"
port = 3450 port = 3450
@ -8,3 +7,6 @@ pvemaster = ""
[default.databases.p5x_api] [default.databases.p5x_api]
url = "sqlite://p5x_api.sqlite?mode=rwc" url = "sqlite://p5x_api.sqlite?mode=rwc"
[docker.databases.p5x_api]
url = "sqlite:///p5x/data/p5x_api.sqlite?mode=rwc"

9
scripts/build.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh -e
if ! [ -f Cargo.toml ]; then
echo "This script must be run from the root of the repo."
exit 1
fi
cargo build --release --target x86_64-unknown-linux-gnu
docker build -t "${DOCKER_REGISTRY}/p5x-rs:latest" .

27
scripts/run.sh Executable file
View File

@ -0,0 +1,27 @@
#!/bin/sh -e
# Build the release binary
echo ""
echo "Building p5x..."
echo ""
./scripts/build.sh
# Create a data volume if one doesn't already exist
if ! docker volume inspect p5x-data >/dev/null; then
docker volume create p5x-data
fi
# Run the docker container for the server (use -it if we have TTY)
P5X_ARGS="-p 3450:3450 --rm --mount source=p5x-data,target=/p5x/data"
if [ -t 1 ]; then
P5X_ARGS="$P5X_ARGS -it"
fi
if [ -f .env ]; then
P5X_ARGS="$P5X_ARGS --env-file .env"
fi
echo ""
echo "Running p5x..."
echo ""
docker run $P5X_ARGS "$DOCKER_REGISTRY/p5x-rs:latest"

View File

@ -3,16 +3,14 @@ use std::net::TcpStream;
use ssh2::{OpenFlags, OpenType, Session}; use ssh2::{OpenFlags, OpenType, Session};
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::path::Path; use std::path::Path;
use std::str::FromStr;
use std::time::Duration; use std::time::Duration;
use sea_orm::entity::prelude::*; use sea_orm::entity::prelude::*;
use sea_orm::QueryOrder; use sea_orm::QueryOrder;
use serde::{de, Deserialize, Deserializer, Serialize}; use serde::{Deserialize, Serialize};
use tokio::time::sleep; use tokio::time::sleep;
use proxmox_api; use proxmox_api;
use log::{warn, debug}; use log::{warn, debug};
use proxmox_api::types::VmId; use proxmox_api::types::VmId;
use serde::de::Error;
use crate::api::entity::locks; use crate::api::entity::locks;
use crate::api::entity::locks::{lock, try_lock, LockHandle}; use crate::api::entity::locks::{lock, try_lock, LockHandle};
use crate::api::services::{Services, ServiceError, SshError, ssh_run_trimmed}; use crate::api::services::{Services, ServiceError, SshError, ssh_run_trimmed};

View File

@ -4,14 +4,10 @@ use dotenv::dotenv;
use rocket::{Build, Rocket}; use rocket::{Build, Rocket};
use log::{error, info}; use log::{error, info};
use std::{env, process}; use std::{env, process};
use rocket::figment::Figment; use crate::api::util::read_p5x_config;
use rocket::figment::providers::{Env, Format, Toml};
use rocket_dyn_templates::{ Template};
use serde::Deserialize;
fn configure_rocket() -> Rocket<Build> { fn configure_rocket() -> Rocket<Build> {
rocket::build() rocket::build()
.attach(Template::fairing())
.attach(api::init()) .attach(api::init())
} }
@ -27,6 +23,8 @@ async fn main() {
process::exit(1); process::exit(1);
} }
read_p5x_config(); // Do this so we early-fail if there are missing env vars
let mode = &args[1]; let mode = &args[1];
if mode == "api-server" { if mode == "api-server" {
let rocket = configure_rocket(); let rocket = configure_rocket();