diff options
| -rw-r--r-- | .github/workflows/rust.yml | 2 | ||||
| -rw-r--r-- | Cargo.lock | 5 | ||||
| -rw-r--r-- | Dockerfile | 8 | ||||
| -rw-r--r-- | crates/atuin-server/Cargo.toml | 12 | ||||
| -rw-r--r-- | crates/atuin-server/src/bin/main.rs | 73 | ||||
| -rw-r--r-- | crates/atuin/Cargo.toml | 18 | ||||
| -rw-r--r-- | crates/atuin/src/command/mod.rs | 10 | ||||
| -rw-r--r-- | crates/atuin/src/command/server.rs | 69 |
8 files changed, 101 insertions, 96 deletions
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 85d5e5d9..7f9b644b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -147,7 +147,7 @@ jobs: run: cargo check --no-default-features --features sync --workspace - name: Run cargo check (server) - run: cargo check --no-default-features --features server --workspace + run: cargo check -p atuin-server - name: Run cargo check (client only) run: cargo check --no-default-features --features client --workspace @@ -225,7 +225,6 @@ dependencies = [ "atuin-server", "atuin-server-database", "atuin-server-postgres", - "atuin-server-sqlite", "clap", "clap_complete", "clap_complete_nushell", @@ -435,7 +434,10 @@ dependencies = [ "async-trait", "atuin-common", "atuin-server-database", + "atuin-server-postgres", + "atuin-server-sqlite", "axum", + "clap", "config", "eyre", "fs-err", @@ -451,6 +453,7 @@ dependencies = [ "tower 0.5.3", "tower-http", "tracing", + "tracing-subscriber", ] [[package]] @@ -14,7 +14,7 @@ COPY --from=planner /app/recipe.json recipe.json RUN cargo chef cook --release --recipe-path recipe.json COPY . . -RUN cargo build --release --bin atuin +RUN cargo build --release --bin atuin-server FROM debian:bookworm-20260112-slim AS runtime @@ -26,8 +26,8 @@ WORKDIR app USER atuin ENV TZ=Etc/UTC -ENV RUST_LOG=atuin::api=info +ENV RUST_LOG=atuin_server=info ENV ATUIN_CONFIG_DIR=/config -COPY --from=builder /app/target/release/atuin /usr/local/bin -ENTRYPOINT ["/usr/local/bin/atuin"] +COPY --from=builder /app/target/release/atuin-server /usr/local/bin +ENTRYPOINT ["/usr/local/bin/atuin-server"] diff --git a/crates/atuin-server/Cargo.toml b/crates/atuin-server/Cargo.toml index 04bf61e7..edda2532 100644 --- a/crates/atuin-server/Cargo.toml +++ b/crates/atuin-server/Cargo.toml @@ -10,9 +10,19 @@ license = { workspace = true } homepage = { workspace = true } repository = { workspace = true } +[lib] +name = "atuin_server" +path = "src/lib.rs" + +[[bin]] +name = "atuin-server" +path = "src/bin/main.rs" + [dependencies] atuin-common = { path = "../atuin-common", version = "18.11.0" } atuin-server-database = { path = "../atuin-server-database", version = "18.11.0" } +atuin-server-postgres = { path = "../atuin-server-postgres", version = "18.11.0" } +atuin-server-sqlite = { path = "../atuin-server-sqlite", version = "18.11.0" } tracing = { workspace = true } time = { workspace = true } @@ -32,3 +42,5 @@ argon2 = "0.5" semver = { workspace = true } metrics-exporter-prometheus = { version = "0.18", default-features = false } metrics = "0.24" +clap = { workspace = true } +tracing-subscriber = { workspace = true } diff --git a/crates/atuin-server/src/bin/main.rs b/crates/atuin-server/src/bin/main.rs new file mode 100644 index 00000000..960bdf6e --- /dev/null +++ b/crates/atuin-server/src/bin/main.rs @@ -0,0 +1,73 @@ +#![forbid(unsafe_code)] + +use std::net::SocketAddr; + +use atuin_server::{Settings, example_config, launch, launch_metrics_server}; +use atuin_server_database::DbType; +use atuin_server_postgres::Postgres; +use atuin_server_sqlite::Sqlite; + +use clap::Parser; +use eyre::{Context, Result, eyre}; +use tracing_subscriber::{EnvFilter, fmt, prelude::*}; + +#[derive(Parser, Debug)] +#[clap( + name = "atuin-server", + about = "Atuin sync server", + version, + infer_subcommands = true +)] +enum Cmd { + /// Start the server + Start { + /// The host address to bind + #[clap(long)] + host: Option<String>, + + /// The port to bind + #[clap(long, short)] + port: Option<u16>, + }, + + /// Print server example configuration + DefaultConfig, +} + +#[tokio::main] +async fn main() -> Result<()> { + let cmd = Cmd::parse(); + + tracing_subscriber::registry() + .with(fmt::layer()) + .with(EnvFilter::from_default_env()) + .init(); + + tracing::trace!(command = ?cmd, "server command"); + + match cmd { + Cmd::Start { host, port } => { + let settings = Settings::new().wrap_err("could not load server settings")?; + let host = host.as_ref().unwrap_or(&settings.host).clone(); + let port = port.unwrap_or(settings.port); + let addr = SocketAddr::new(host.parse()?, port); + + if settings.metrics.enable { + tokio::spawn(launch_metrics_server( + settings.metrics.host.clone(), + settings.metrics.port, + )); + } + + match settings.db_settings.db_type() { + DbType::Postgres => launch::<Postgres>(settings, addr).await, + DbType::Sqlite => launch::<Sqlite>(settings, addr).await, + DbType::Unknown => Err(eyre!("db_uri must start with postgres:// or sqlite://")), + } + } + Cmd::DefaultConfig => { + println!("{}", example_config()); + Ok(()) + } + } +} diff --git a/crates/atuin/Cargo.toml b/crates/atuin/Cargo.toml index 77f8dc0a..f75c52b5 100644 --- a/crates/atuin/Cargo.toml +++ b/crates/atuin/Cargo.toml @@ -33,24 +33,14 @@ buildflags = ["--release"] atuin = { path = "/usr/bin/atuin" } [features] -default = ["client", "sync", "server", "clipboard", "check-update", "daemon"] +default = ["client", "sync", "clipboard", "check-update", "daemon"] client = ["atuin-client"] sync = ["atuin-client/sync"] daemon = ["atuin-client/daemon", "atuin-daemon"] -server = [ - "atuin-server", - "atuin-server-database", - "atuin-server-postgres", - "atuin-server-sqlite", -] clipboard = ["arboard"] check-update = ["atuin-client/check-update"] [dependencies] -atuin-server-database = { path = "../atuin-server-database", version = "18.11.0", optional = true } -atuin-server-postgres = { path = "../atuin-server-postgres", version = "18.11.0", optional = true } -atuin-server-sqlite = { path = "../atuin-server-sqlite", version = "18.11.0", optional = true } -atuin-server = { path = "../atuin-server", version = "18.11.0", optional = true } atuin-client = { path = "../atuin-client", version = "18.11.0", optional = true, default-features = false } atuin-common = { path = "../atuin-common", version = "18.11.0" } atuin-dotfiles = { path = "../atuin-dotfiles", version = "18.11.0" } @@ -103,3 +93,9 @@ arboard = { version = "3.4", optional = true, features = [ [dev-dependencies] tracing-tree = "0.4" + +# Integration tests in tests/ spin up a test server to verify sync functionality. +# TODO: Consider moving these tests to atuin-server crate instead (client would become a dev dep there) +atuin-server = { path = "../atuin-server", version = "18.11.0" } +atuin-server-database = { path = "../atuin-server-database", version = "18.11.0" } +atuin-server-postgres = { path = "../atuin-server-postgres", version = "18.11.0" } diff --git a/crates/atuin/src/command/mod.rs b/crates/atuin/src/command/mod.rs index a70ab629..d9fa53df 100644 --- a/crates/atuin/src/command/mod.rs +++ b/crates/atuin/src/command/mod.rs @@ -7,9 +7,6 @@ use rustix::{fs::Mode, process::umask}; #[cfg(feature = "client")] mod client; -#[cfg(feature = "server")] -mod server; - mod contributors; mod gen_completions; @@ -24,11 +21,6 @@ pub enum AtuinCmd { #[command(flatten)] Client(client::Cmd), - /// Start an atuin server - #[cfg(feature = "server")] - #[command(subcommand)] - Server(server::Cmd), - /// Generate a UUID Uuid, @@ -55,8 +47,6 @@ impl AtuinCmd { #[cfg(feature = "client")] Self::Client(client) => client.run(), - #[cfg(feature = "server")] - Self::Server(server) => server.run(), Self::Contributors => { contributors::run(); Ok(()) diff --git a/crates/atuin/src/command/server.rs b/crates/atuin/src/command/server.rs deleted file mode 100644 index fc09bd27..00000000 --- a/crates/atuin/src/command/server.rs +++ /dev/null @@ -1,69 +0,0 @@ -use std::net::SocketAddr; - -use atuin_server_database::DbType; -use atuin_server_postgres::Postgres; -use atuin_server_sqlite::Sqlite; -use tracing_subscriber::{EnvFilter, fmt, prelude::*}; - -use clap::Parser; -use eyre::{Context, Result, eyre}; - -use atuin_server::{Settings, example_config, launch, launch_metrics_server}; - -#[derive(Parser, Debug)] -#[clap(infer_subcommands = true)] -pub enum Cmd { - /// Start the server - Start { - /// The host address to bind - #[clap(long)] - host: Option<String>, - - /// The port to bind - #[clap(long, short)] - port: Option<u16>, - }, - - /// Print server example configuration - DefaultConfig, -} - -impl Cmd { - #[tokio::main] - pub async fn run(self) -> Result<()> { - tracing_subscriber::registry() - .with(fmt::layer()) - .with(EnvFilter::from_default_env()) - .init(); - - tracing::trace!(command = ?self, "server command"); - - match self { - Self::Start { host, port } => { - let settings = Settings::new().wrap_err("could not load server settings")?; - let host = host.as_ref().unwrap_or(&settings.host).clone(); - let port = port.unwrap_or(settings.port); - let addr = SocketAddr::new(host.parse()?, port); - - if settings.metrics.enable { - tokio::spawn(launch_metrics_server( - settings.metrics.host.clone(), - settings.metrics.port, - )); - } - - match settings.db_settings.db_type() { - DbType::Postgres => launch::<Postgres>(settings, addr).await, - DbType::Sqlite => launch::<Sqlite>(settings, addr).await, - DbType::Unknown => { - Err(eyre!("db_uri must start with postgres:// or sqlite://")) - } - } - } - Self::DefaultConfig => { - println!("{}", example_config()); - Ok(()) - } - } - } -} |
