diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..25eaa54 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,96 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + +permissions: + contents: read + +concurrency: + group: ci-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + CARGO_TERM_COLOR: always + # Required: `.cargo/config.toml` points DATABASE_URL at + # sqlite://ployer.db?mode=rwc, which would CREATE an empty database here and + # make every sqlx::query! macro fail with "no such table". Offline mode uses + # the committed .sqlx/ metadata instead. See DOCUMENTATION.md > Prerequisites. + SQLX_OFFLINE: true + +jobs: + # The lint gate runs on a PINNED toolchain, on purpose. + # + # `-D warnings` plus a floating `stable` means every six-week Rust release can + # red-light every open PR over a brand-new lint that has nothing to do with the + # change under review. Pinning makes the gate deterministic: a clippy upgrade + # becomes its own PR that bumps this version and fixes the new findings in one + # place, reviewed on its own merits. + # + # To upgrade: bump the version below, run + # cargo + clippy --workspace --all-targets -- -D warnings + # locally, fix what it finds, and ship both together. + lint: + name: Clippy (pinned 1.99.1) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.99.1 + components: clippy, rustfmt + + # reqwest is built with its default native-tls feature, so openssl-sys + # needs system OpenSSL or the build fails on the first dependency. + - name: Install build dependencies + run: | + sudo apt-get update -qq + sudo apt-get install -y libssl-dev pkg-config + + - name: Cache Rust dependencies + uses: Swatinem/rust-cache@v2 + with: + key: lint-1.99.1 + + # The gate. Any warning is an error; see DOCUMENTATION.md > + # Development Checks for how to handle a lint that is wrong for a + # specific call site. + - name: cargo clippy -- -D warnings + run: cargo clippy --workspace --all-targets -- -D warnings + + # Not a gate: the tree has ~325 unformatted hunks and a blanket reformat + # is a separate decision. GitHub reports a continue-on-error step as + # green whatever happens, so this is log-only visibility, not a signal. + - name: cargo fmt (advisory, non-blocking) + continue-on-error: true + run: cargo fmt --all -- --check + + # Tests run on floating `stable` so genuine compiler and runtime regressions + # still surface; a test failure is always worth looking at, whereas a new lint + # usually is not urgent. + test: + name: Tests (stable) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + + - name: Install build dependencies + run: | + sudo apt-get update -qq + sudo apt-get install -y libssl-dev pkg-config + + - name: Cache Rust dependencies + uses: Swatinem/rust-cache@v2 + with: + key: test-stable + + - name: cargo test + run: cargo test --workspace diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 6b7b4dd..70d9fc1 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -5,12 +5,53 @@ - **Rust** (1.75+) — [rustup.rs](https://rustup.rs) - **Node.js** (20+) or **Bun** (1.0+) — for frontend builds - **Docker** (optional) — required for container management features +- **OpenSSL headers** — `libssl-dev` on Debian/Ubuntu, `openssl-devel` on + Fedora/RHEL, `openssl` on macOS (Homebrew). Required: `reqwest` is built with + its default `native-tls` feature, so `openssl-sys` must find system OpenSSL + or the build fails on the very first dependency, long before any Ployer code + is reached. + + ```bash + sudo apt-get install -y libssl-dev pkg-config # Debian / Ubuntu + ``` + + The failure looks like this, and it is not a Ployer bug: + + ``` + error: failed to run custom build command for `openssl-sys v0.9.x` + Could not find directory of OpenSSL installation + ``` + +### `SQLX_OFFLINE=true` is required for every cargo command + +Ployer uses `sqlx`'s compile-time-checked `query!` macros, which need either a +live database matching the schema or the checked-in offline metadata in +`.sqlx/`. Always build and test with: + +```bash +export SQLX_OFFLINE=true +``` + +Without it, `.cargo/config.toml` points `DATABASE_URL` at +`sqlite://ployer.db?mode=rwc`, whose `mode=rwc` *creates* an empty database in +whatever directory you happen to be in. The macros then type-check against that +empty database and every one of them fails: + +``` +error: error returned from database: (code: 1) no such table: applications +``` + +The fix is never "run the migrations" — it is to set `SQLX_OFFLINE=true` and +use the committed `.sqlx/` metadata. Only regenerate that metadata +(`cargo sqlx prepare --workspace`, against a migrated database) when you change +a SQL query. ## Quick Start ### 1. Build the backend ```bash +export SQLX_OFFLINE=true cargo build --workspace ``` @@ -52,6 +93,32 @@ Expected response: `docker: false` is normal if Docker is not running. +## Development Checks + +CI (`.github/workflows/ci.yml`) runs these on every push and pull request, and +they are the same commands to run locally before opening a PR: + +```bash +export SQLX_OFFLINE=true +cargo clippy --workspace --all-targets -- -D warnings +cargo test --workspace +``` + +The clippy gate is enforced: **any** warning fails the build. If you are adding +a function that trips a lint you believe is wrong for the case at hand, add a +narrowly scoped `#[allow(clippy::the_lint)]` on that item with a comment saying +why, rather than widening the gate or silencing the lint crate-wide. There are +currently six such allows, all `clippy::too_many_arguments` on SQL writers whose +arguments are one-per-column. + +`cargo fmt --check` is **not** a gate: the tree predates any formatting +discipline and currently has ~325 unformatted hunks spread across nearly every +file, so turning it on would either fail immediately or require a tree-wide +reformat that would bury every subsequent `git blame`. That is its own +decision, not a side effect of a lint cleanup. CI still runs it as a +`continue-on-error` step, so the current state is one click away in the job +log; note that GitHub reports such a step as green regardless of its result. + ## CLI Commands | Command | Description | diff --git a/README.md b/README.md index 3eb0de0..58046be 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ A lightweight, self-hosted PaaS — deploy your apps from Git with automatic SSL > **Important:** Install on a **fresh, dedicated server**. Ployer owns ports 80 and 443 via Caddy. It will conflict with Nginx, Apache, Coolify, or any other reverse proxy already running on those ports. +**Building from source?** You need `libssl-dev` and `SQLX_OFFLINE=true` as well — see [DOCUMENTATION.md § Prerequisites](DOCUMENTATION.md#prerequisites). The above applies to *running* a release binary. + --- ## Quick Install diff --git a/crates/ployer-api/src/routes/domains.rs b/crates/ployer-api/src/routes/domains.rs index ed1161a..2d87224 100644 --- a/crates/ployer-api/src/routes/domains.rs +++ b/crates/ployer-api/src/routes/domains.rs @@ -128,7 +128,11 @@ async fn add_domain( let repo = DomainRepository::new(state.db.clone()); // Check if domain already exists - if let Some(_) = repo.find_by_domain(&domain_name).await.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))? { + let existing = repo + .find_by_domain(&domain_name) + .await + .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; + if existing.is_some() { return Err((StatusCode::CONFLICT, "Domain already exists".to_string())); } diff --git a/crates/ployer-api/src/routes/system.rs b/crates/ployer-api/src/routes/system.rs index 58b0fb0..0ef8f6c 100644 --- a/crates/ployer-api/src/routes/system.rs +++ b/crates/ployer-api/src/routes/system.rs @@ -101,7 +101,10 @@ async fn fetch_latest_version() -> Option { .map(|t| (t.to_string(), r)) }) .collect(); - candidates.sort_by(|a, b| version_key(&b.0).cmp(&version_key(&a.0))); + // `sort_by_cached_key` rather than `sort_by_key`: `version_key` allocates a + // Vec<(u32, String)> per call, and a plain comparator recomputes it twice per + // comparison. Caching makes it one key per element. + candidates.sort_by_cached_key(|c| std::cmp::Reverse(version_key(&c.0))); let latest_tag = candidates .into_iter() diff --git a/crates/ployer-api/src/services/deployment.rs b/crates/ployer-api/src/services/deployment.rs index b65f657..8bdcbc5 100644 --- a/crates/ployer-api/src/services/deployment.rs +++ b/crates/ployer-api/src/services/deployment.rs @@ -105,6 +105,11 @@ impl DeploymentService { } /// Execute the full deployment pipeline + // spawned as a detached task, so every dependency must be passed by value rather than + // borrowed from AppState; the first six are the ambient services and the last four are this + // job's inputs. Bundling them into a struct is a refactor of the deployment hot path, + // deliberately not folded into a lint fix. + #[allow(clippy::too_many_arguments)] async fn execute_deployment( db: SqlitePool, docker: Arc, @@ -226,9 +231,9 @@ impl DeploymentService { } // Also force-remove by fixed name (catches untracked containers with the same name) - match docker.remove_container(&container_name, true).await { - Ok(_) => send_log(format!("Removed existing container '{}'", container_name)).await, - Err(_) => {} // doesn't exist — that's fine + // An Err here just means no such container, which is the normal case. + if docker.remove_container(&container_name, true).await.is_ok() { + send_log(format!("Removed existing container '{}'", container_name)).await; } // Note: we no longer kill "containers bound to this port" — app containers diff --git a/crates/ployer-core/src/models/application.rs b/crates/ployer-core/src/models/application.rs index e6ff1c1..fd73343 100644 --- a/crates/ployer-core/src/models/application.rs +++ b/crates/ployer-core/src/models/application.rs @@ -23,20 +23,15 @@ pub struct Application { pub updated_at: DateTime, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)] #[serde(rename_all = "snake_case")] pub enum BuildStrategy { + #[default] Dockerfile, Nixpacks, DockerCompose, } -impl Default for BuildStrategy { - fn default() -> Self { - BuildStrategy::Dockerfile - } -} - impl BuildStrategy { pub fn as_str(&self) -> &str { match self { @@ -46,7 +41,16 @@ impl BuildStrategy { } } - pub fn from_str(s: &str) -> Self { + /// Parse a `BuildStrategy` out of the string stored in its database column. + /// + /// Total and lossy by design: an unrecognised value yields + /// [`BuildStrategy::Dockerfile`] rather than an error, so a row written by a newer + /// schema can never make an existing row unreadable. + /// + /// Deliberately not [`std::str::FromStr`]: that trait would need + /// `Err = Infallible`, which hides the fallback from callers and makes + /// `"nonsense".parse()` look like a successful parse. + pub fn from_db_str(s: &str) -> Self { match s { "dockerfile" => BuildStrategy::Dockerfile, "nixpacks" => BuildStrategy::Nixpacks, @@ -77,7 +81,16 @@ impl AppStatus { } } - pub fn from_str(s: &str) -> Self { + /// Parse a `AppStatus` out of the string stored in its database column. + /// + /// Total and lossy by design: an unrecognised value yields + /// [`AppStatus::Idle`] rather than an error, so a row written by a newer + /// schema can never make an existing row unreadable. + /// + /// Deliberately not [`std::str::FromStr`]: that trait would need + /// `Err = Infallible`, which hides the fallback from callers and makes + /// `"nonsense".parse()` look like a successful parse. + pub fn from_db_str(s: &str) -> Self { match s { "idle" => AppStatus::Idle, "building" => AppStatus::Building, diff --git a/crates/ployer-core/src/models/application_tests.rs b/crates/ployer-core/src/models/application_tests.rs index e2d4415..49bce45 100644 --- a/crates/ployer-core/src/models/application_tests.rs +++ b/crates/ployer-core/src/models/application_tests.rs @@ -8,13 +8,13 @@ fn build_strategy_round_trips() { (BuildStrategy::DockerCompose, "docker_compose"), ] { assert_eq!(variant.as_str(), s); - assert_eq!(BuildStrategy::from_str(s), variant); + assert_eq!(BuildStrategy::from_db_str(s), variant); } } #[test] fn build_strategy_unknown_defaults_to_dockerfile() { - assert_eq!(BuildStrategy::from_str("unknown"), BuildStrategy::Dockerfile); + assert_eq!(BuildStrategy::from_db_str("unknown"), BuildStrategy::Dockerfile); } #[test] @@ -27,13 +27,13 @@ fn app_status_round_trips() { (AppStatus::Failed, "failed"), ] { assert_eq!(variant.as_str(), s); - assert_eq!(AppStatus::from_str(s), variant); + assert_eq!(AppStatus::from_db_str(s), variant); } } #[test] fn app_status_unknown_defaults_to_idle() { - assert_eq!(AppStatus::from_str("mystery"), AppStatus::Idle); + assert_eq!(AppStatus::from_db_str("mystery"), AppStatus::Idle); } #[test] diff --git a/crates/ployer-core/src/models/deployment.rs b/crates/ployer-core/src/models/deployment.rs index ed1e19a..c5522e3 100644 --- a/crates/ployer-core/src/models/deployment.rs +++ b/crates/ployer-core/src/models/deployment.rs @@ -43,7 +43,16 @@ impl DeploymentStatus { } } - pub fn from_str(s: &str) -> Self { + /// Parse a `DeploymentStatus` out of the string stored in its database column. + /// + /// Total and lossy by design: an unrecognised value yields + /// [`DeploymentStatus::Queued`] rather than an error, so a row written by a newer + /// schema can never make an existing row unreadable. + /// + /// Deliberately not [`std::str::FromStr`]: that trait would need + /// `Err = Infallible`, which hides the fallback from callers and makes + /// `"nonsense".parse()` look like a successful parse. + pub fn from_db_str(s: &str) -> Self { match s { "queued" => DeploymentStatus::Queued, "cloning" => DeploymentStatus::Cloning, @@ -103,7 +112,16 @@ impl HealthCheckStatus { } } - pub fn from_str(s: &str) -> Self { + /// Parse a `HealthCheckStatus` out of the string stored in its database column. + /// + /// Total and lossy by design: an unrecognised value yields + /// [`HealthCheckStatus::Unknown`] rather than an error, so a row written by a newer + /// schema can never make an existing row unreadable. + /// + /// Deliberately not [`std::str::FromStr`]: that trait would need + /// `Err = Infallible`, which hides the fallback from callers and makes + /// `"nonsense".parse()` look like a successful parse. + pub fn from_db_str(s: &str) -> Self { match s { "healthy" => HealthCheckStatus::Healthy, "unhealthy" => HealthCheckStatus::Unhealthy, diff --git a/crates/ployer-core/src/models/deployment_tests.rs b/crates/ployer-core/src/models/deployment_tests.rs index 536fa78..52e4fbd 100644 --- a/crates/ployer-core/src/models/deployment_tests.rs +++ b/crates/ployer-core/src/models/deployment_tests.rs @@ -13,13 +13,13 @@ fn deployment_status_round_trips() { (DeploymentStatus::RolledBack, "rolled_back"), ] { assert_eq!(variant.as_str(), s); - assert_eq!(DeploymentStatus::from_str(s), variant); + assert_eq!(DeploymentStatus::from_db_str(s), variant); } } #[test] fn deployment_status_unknown_defaults_to_queued() { - assert_eq!(DeploymentStatus::from_str("unknown"), DeploymentStatus::Queued); + assert_eq!(DeploymentStatus::from_db_str("unknown"), DeploymentStatus::Queued); } #[test] @@ -30,11 +30,11 @@ fn health_check_status_round_trips() { (HealthCheckStatus::Unknown, "unknown"), ] { assert_eq!(variant.as_str(), s); - assert_eq!(HealthCheckStatus::from_str(s), variant); + assert_eq!(HealthCheckStatus::from_db_str(s), variant); } } #[test] fn health_check_status_unknown_defaults_to_unknown() { - assert_eq!(HealthCheckStatus::from_str("bad"), HealthCheckStatus::Unknown); + assert_eq!(HealthCheckStatus::from_db_str("bad"), HealthCheckStatus::Unknown); } diff --git a/crates/ployer-core/src/models/server.rs b/crates/ployer-core/src/models/server.rs index 37097c6..13b4b13 100644 --- a/crates/ployer-core/src/models/server.rs +++ b/crates/ployer-core/src/models/server.rs @@ -34,7 +34,16 @@ impl ServerStatus { } } - pub fn from_str(s: &str) -> Self { + /// Parse a `ServerStatus` out of the string stored in its database column. + /// + /// Total and lossy by design: an unrecognised value yields + /// [`ServerStatus::Unknown`] rather than an error, so a row written by a newer + /// schema can never make an existing row unreadable. + /// + /// Deliberately not [`std::str::FromStr`]: that trait would need + /// `Err = Infallible`, which hides the fallback from callers and makes + /// `"nonsense".parse()` look like a successful parse. + pub fn from_db_str(s: &str) -> Self { match s { "online" => ServerStatus::Online, "offline" => ServerStatus::Offline, diff --git a/crates/ployer-core/src/models/server_tests.rs b/crates/ployer-core/src/models/server_tests.rs index fb460a7..f20437e 100644 --- a/crates/ployer-core/src/models/server_tests.rs +++ b/crates/ployer-core/src/models/server_tests.rs @@ -8,11 +8,11 @@ fn server_status_round_trips() { (ServerStatus::Unknown, "unknown"), ] { assert_eq!(variant.as_str(), s); - assert_eq!(ServerStatus::from_str(s), variant); + assert_eq!(ServerStatus::from_db_str(s), variant); } } #[test] fn server_status_unknown_defaults_to_unknown() { - assert_eq!(ServerStatus::from_str("unreachable"), ServerStatus::Unknown); + assert_eq!(ServerStatus::from_db_str("unreachable"), ServerStatus::Unknown); } diff --git a/crates/ployer-core/src/models/user.rs b/crates/ployer-core/src/models/user.rs index 47a5615..7fa8e36 100644 --- a/crates/ployer-core/src/models/user.rs +++ b/crates/ployer-core/src/models/user.rs @@ -28,7 +28,19 @@ impl UserRole { } } - pub fn from_str(s: &str) -> Self { + /// Parse a `UserRole` out of the string stored in its database column. + /// + /// Total and lossy by design: an unrecognised value yields + /// [`UserRole::User`] rather than an error, so a row written by a newer + /// schema can never make an existing row unreadable. + /// + /// Anything that is not `"admin"` is treated as an unprivileged user, so a + /// corrupt value fails closed. + /// + /// Deliberately not [`std::str::FromStr`]: that trait would need + /// `Err = Infallible`, which hides the fallback from callers and makes + /// `"nonsense".parse()` look like a successful parse. + pub fn from_db_str(s: &str) -> Self { match s { "admin" => UserRole::Admin, _ => UserRole::User, diff --git a/crates/ployer-core/src/models/user_tests.rs b/crates/ployer-core/src/models/user_tests.rs index abae87b..9afa07c 100644 --- a/crates/ployer-core/src/models/user_tests.rs +++ b/crates/ployer-core/src/models/user_tests.rs @@ -4,11 +4,11 @@ use super::*; fn user_role_round_trips() { assert_eq!(UserRole::Admin.as_str(), "admin"); assert_eq!(UserRole::User.as_str(), "user"); - assert_eq!(UserRole::from_str("admin"), UserRole::Admin); - assert_eq!(UserRole::from_str("user"), UserRole::User); + assert_eq!(UserRole::from_db_str("admin"), UserRole::Admin); + assert_eq!(UserRole::from_db_str("user"), UserRole::User); } #[test] fn user_role_unknown_defaults_to_user() { - assert_eq!(UserRole::from_str("superadmin"), UserRole::User); + assert_eq!(UserRole::from_db_str("superadmin"), UserRole::User); } diff --git a/crates/ployer-core/src/models/webhook.rs b/crates/ployer-core/src/models/webhook.rs index 9f703f1..897885e 100644 --- a/crates/ployer-core/src/models/webhook.rs +++ b/crates/ployer-core/src/models/webhook.rs @@ -27,7 +27,18 @@ impl WebhookProvider { } } - pub fn from_str(s: &str) -> Self { + /// Parse a `WebhookProvider` out of the string stored in its database column. + /// + /// Total and lossy by design: an unrecognised value yields + /// [`WebhookProvider::GitHub`] rather than an error, so a row written by a newer + /// schema can never make an existing row unreadable. + /// + /// Matching is case-insensitive. + /// + /// Deliberately not [`std::str::FromStr`]: that trait would need + /// `Err = Infallible`, which hides the fallback from callers and makes + /// `"nonsense".parse()` look like a successful parse. + pub fn from_db_str(s: &str) -> Self { match s.to_lowercase().as_str() { "github" => WebhookProvider::GitHub, "gitlab" => WebhookProvider::GitLab, @@ -71,7 +82,16 @@ impl WebhookDeliveryStatus { } } - pub fn from_str(s: &str) -> Self { + /// Parse a `WebhookDeliveryStatus` out of the string stored in its database column. + /// + /// Total and lossy by design: an unrecognised value yields + /// [`WebhookDeliveryStatus::Failed`] rather than an error, so a row written by a newer + /// schema can never make an existing row unreadable. + /// + /// Deliberately not [`std::str::FromStr`]: that trait would need + /// `Err = Infallible`, which hides the fallback from callers and makes + /// `"nonsense".parse()` look like a successful parse. + pub fn from_db_str(s: &str) -> Self { match s { "success" => WebhookDeliveryStatus::Success, "failed" => WebhookDeliveryStatus::Failed, diff --git a/crates/ployer-core/src/models/webhook_tests.rs b/crates/ployer-core/src/models/webhook_tests.rs index 06ec91e..ffd44fd 100644 --- a/crates/ployer-core/src/models/webhook_tests.rs +++ b/crates/ployer-core/src/models/webhook_tests.rs @@ -4,19 +4,19 @@ use super::*; fn webhook_provider_round_trips() { assert_eq!(WebhookProvider::GitHub.as_str(), "github"); assert_eq!(WebhookProvider::GitLab.as_str(), "gitlab"); - assert_eq!(WebhookProvider::from_str("github"), WebhookProvider::GitHub); - assert_eq!(WebhookProvider::from_str("gitlab"), WebhookProvider::GitLab); + assert_eq!(WebhookProvider::from_db_str("github"), WebhookProvider::GitHub); + assert_eq!(WebhookProvider::from_db_str("gitlab"), WebhookProvider::GitLab); } #[test] fn webhook_provider_is_case_insensitive() { - assert_eq!(WebhookProvider::from_str("GitHub"), WebhookProvider::GitHub); - assert_eq!(WebhookProvider::from_str("GitLab"), WebhookProvider::GitLab); + assert_eq!(WebhookProvider::from_db_str("GitHub"), WebhookProvider::GitHub); + assert_eq!(WebhookProvider::from_db_str("GitLab"), WebhookProvider::GitLab); } #[test] fn webhook_provider_unknown_defaults_to_github() { - assert_eq!(WebhookProvider::from_str("bitbucket"), WebhookProvider::GitHub); + assert_eq!(WebhookProvider::from_db_str("bitbucket"), WebhookProvider::GitHub); } #[test] @@ -27,11 +27,11 @@ fn webhook_delivery_status_round_trips() { (WebhookDeliveryStatus::Skipped, "skipped"), ] { assert_eq!(variant.as_str(), s); - assert_eq!(WebhookDeliveryStatus::from_str(s), variant); + assert_eq!(WebhookDeliveryStatus::from_db_str(s), variant); } } #[test] fn webhook_delivery_status_unknown_defaults_to_failed() { - assert_eq!(WebhookDeliveryStatus::from_str("unknown"), WebhookDeliveryStatus::Failed); + assert_eq!(WebhookDeliveryStatus::from_db_str("unknown"), WebhookDeliveryStatus::Failed); } diff --git a/crates/ployer-db/src/repositories/application.rs b/crates/ployer-db/src/repositories/application.rs index 71de072..7da68df 100644 --- a/crates/ployer-db/src/repositories/application.rs +++ b/crates/ployer-db/src/repositories/application.rs @@ -12,6 +12,9 @@ impl ApplicationRepository { Self { pool } } + // one parameter per `applications` column; a params struct would duplicate the column list + // and could drift from the INSERT silently + #[allow(clippy::too_many_arguments)] pub async fn create( &self, name: &str, @@ -124,6 +127,9 @@ impl ApplicationRepository { Ok(rows.into_iter().map(|r| r.into()).collect()) } + // one parameter per `applications` column; a params struct would duplicate the column list + // and could drift from the UPDATE silently + #[allow(clippy::too_many_arguments)] pub async fn update( &self, id: &str, @@ -243,12 +249,12 @@ impl From for Application { server_id: row.server_id, git_url: row.git_url, git_branch: row.git_branch, - build_strategy: BuildStrategy::from_str(&row.build_strategy), + build_strategy: BuildStrategy::from_db_str(&row.build_strategy), dockerfile_path: row.dockerfile_path, port: row.port.map(|p| p as u16), cpu_limit: row.cpu_limit, memory_limit: row.memory_limit, - status: AppStatus::from_str(&row.status), + status: AppStatus::from_db_str(&row.status), auto_deploy: row.auto_deploy != 0, compose_content: row.compose_content, template_slug: row.template_slug, diff --git a/crates/ployer-db/src/repositories/container_stats.rs b/crates/ployer-db/src/repositories/container_stats.rs index 360b56a..50a9179 100644 --- a/crates/ployer-db/src/repositories/container_stats.rs +++ b/crates/ployer-db/src/repositories/container_stats.rs @@ -14,6 +14,9 @@ impl ContainerStatsRepository { } /// Record container stats + // one parameter per `container_stats` column; a params struct would duplicate the column + // list and could drift from the INSERT silently + #[allow(clippy::too_many_arguments)] pub async fn record( &self, container_id: &str, diff --git a/crates/ployer-db/src/repositories/deployment.rs b/crates/ployer-db/src/repositories/deployment.rs index 383d84f..d9661cf 100644 --- a/crates/ployer-db/src/repositories/deployment.rs +++ b/crates/ployer-db/src/repositories/deployment.rs @@ -83,7 +83,7 @@ impl DeploymentRepository { server_id: r.server_id, commit_sha: r.commit_sha, commit_message: r.commit_message, - status: DeploymentStatus::from_str(&r.status), + status: DeploymentStatus::from_db_str(&r.status), build_log: r.build_log, container_id: r.container_id, image_tag: r.image_tag, @@ -116,7 +116,7 @@ impl DeploymentRepository { server_id: r.server_id, commit_sha: r.commit_sha, commit_message: r.commit_message, - status: DeploymentStatus::from_str(&r.status), + status: DeploymentStatus::from_db_str(&r.status), build_log: r.build_log, container_id: r.container_id, image_tag: r.image_tag, @@ -214,7 +214,7 @@ impl DeploymentRepository { server_id: r.server_id, commit_sha: r.commit_sha, commit_message: r.commit_message, - status: DeploymentStatus::from_str(&r.status), + status: DeploymentStatus::from_db_str(&r.status), build_log: r.build_log, container_id: r.container_id, image_tag: r.image_tag, diff --git a/crates/ployer-db/src/repositories/health_check.rs b/crates/ployer-db/src/repositories/health_check.rs index 948e6a0..07d3cba 100644 --- a/crates/ployer-db/src/repositories/health_check.rs +++ b/crates/ployer-db/src/repositories/health_check.rs @@ -219,7 +219,7 @@ impl HealthCheckRepository { id: r.id, application_id: r.application_id, container_id: r.container_id, - status: HealthCheckStatus::from_str(&r.status), + status: HealthCheckStatus::from_db_str(&r.status), response_time_ms: r.response_time_ms.map(|v| v as i32), status_code: r.status_code.map(|v| v as i32), error_message: r.error_message, @@ -243,7 +243,7 @@ impl HealthCheckRepository { .fetch_optional(&self.pool) .await?; - Ok(row.map(|r| HealthCheckStatus::from_str(&r.status))) + Ok(row.map(|r| HealthCheckStatus::from_db_str(&r.status))) } /// Clean up old health check results (keep only last N days) diff --git a/crates/ployer-db/src/repositories/server.rs b/crates/ployer-db/src/repositories/server.rs index c7016c5..b88b9eb 100644 --- a/crates/ployer-db/src/repositories/server.rs +++ b/crates/ployer-db/src/repositories/server.rs @@ -70,6 +70,9 @@ impl ServerRepository { Ok(rows.into_iter().map(|r| r.into()).collect()) } + // one parameter per `servers` column; a params struct would duplicate the column list and + // could drift from the UPDATE silently + #[allow(clippy::too_many_arguments)] pub async fn update( &self, id: &str, @@ -167,7 +170,7 @@ impl From for Server { username: row.username, ssh_key_encrypted: row.ssh_key_encrypted, is_local: row.is_local != 0, - status: ServerStatus::from_str(&row.status), + status: ServerStatus::from_db_str(&row.status), last_seen_at: row.last_seen_at.and_then(|s| { chrono::DateTime::parse_from_rfc3339(&s) .ok() diff --git a/crates/ployer-db/src/repositories/user.rs b/crates/ployer-db/src/repositories/user.rs index 259dfda..f51fa56 100644 --- a/crates/ployer-db/src/repositories/user.rs +++ b/crates/ployer-db/src/repositories/user.rs @@ -107,7 +107,7 @@ impl From for User { email: row.email, password_hash: row.password_hash, name: row.name, - role: UserRole::from_str(&row.role), + role: UserRole::from_db_str(&row.role), created_at: chrono::DateTime::parse_from_rfc3339(&row.created_at) .unwrap() .with_timezone(&chrono::Utc), diff --git a/crates/ployer-db/src/repositories/webhook.rs b/crates/ployer-db/src/repositories/webhook.rs index 6586e7f..633b405 100644 --- a/crates/ployer-db/src/repositories/webhook.rs +++ b/crates/ployer-db/src/repositories/webhook.rs @@ -67,7 +67,7 @@ impl WebhookRepository { Ok(row.map(|r| Webhook { id: r.id, application_id: r.application_id, - provider: WebhookProvider::from_str(&r.provider), + provider: WebhookProvider::from_db_str(&r.provider), secret: r.secret, enabled: r.enabled != 0, created_at: r.created_at.parse().unwrap(), @@ -118,6 +118,9 @@ impl WebhookRepository { } /// Create a webhook delivery record + // one parameter per `webhook_deliveries` column; a params struct would duplicate the column + // list and could drift from the INSERT silently + #[allow(clippy::too_many_arguments)] pub async fn create_delivery( &self, webhook_id: &str, @@ -208,13 +211,13 @@ impl WebhookRepository { id: r.id, webhook_id: r.webhook_id, application_id: r.application_id, - provider: WebhookProvider::from_str(&r.provider), + provider: WebhookProvider::from_db_str(&r.provider), event_type: r.event_type, branch: r.branch, commit_sha: r.commit_sha, commit_message: r.commit_message, author: r.author, - status: WebhookDeliveryStatus::from_str(&r.status), + status: WebhookDeliveryStatus::from_db_str(&r.status), response_code: r.response_code.map(|c| c as i32), error_message: r.error_message, deployment_id: r.deployment_id, diff --git a/crates/ployer-git/src/lib.rs b/crates/ployer-git/src/lib.rs index b6506e4..9ec34d2 100644 --- a/crates/ployer-git/src/lib.rs +++ b/crates/ployer-git/src/lib.rs @@ -3,6 +3,7 @@ use git2::{Cred, FetchOptions, RemoteCallbacks, Repository}; use std::path::Path; use tracing::info; +#[derive(Debug, Clone, Copy, Default)] pub struct GitService; #[derive(Debug, Clone)] @@ -42,10 +43,10 @@ impl GitService { let mut n_bytes = private_key.n().to_bytes_be(); // SSH wire format: if MSB is set, prepend 0x00 to indicate positive number - if e_bytes.first().map_or(false, |&b| b & 0x80 != 0) { + if e_bytes.first().is_some_and(|&b| b & 0x80 != 0) { e_bytes.insert(0, 0x00); } - if n_bytes.first().map_or(false, |&b| b & 0x80 != 0) { + if n_bytes.first().is_some_and(|&b| b & 0x80 != 0) { n_bytes.insert(0, 0x00); } diff --git a/crates/ployer-server/src/lib.rs b/crates/ployer-server/src/lib.rs index ad551bb..76c4813 100644 --- a/crates/ployer-server/src/lib.rs +++ b/crates/ployer-server/src/lib.rs @@ -7,6 +7,12 @@ pub struct ServerManager { system: System, } +impl Default for ServerManager { + fn default() -> Self { + Self::new() + } +} + impl ServerManager { pub fn new() -> Self { info!("Server manager initialized"); diff --git a/crates/ployer-templates/src/compose.rs b/crates/ployer-templates/src/compose.rs index 7eba827..9e4e69b 100644 --- a/crates/ployer-templates/src/compose.rs +++ b/crates/ployer-templates/src/compose.rs @@ -68,7 +68,7 @@ pub fn remove_ports_from_all_services(yaml: &str) -> Result().is_err() { - return Err(TemplateError::InvalidInput { - key: spec.key.clone(), - reason: "expected number".to_string(), - }); - } + if matches!(spec.kind, InputKind::Number) && value.parse::().is_err() { + return Err(TemplateError::InvalidInput { + key: spec.key.clone(), + reason: "expected number".to_string(), + }); } out.insert(spec.key.clone(), value);