From af875e46887dc745ea3dd809277db3632db9ef9a Mon Sep 17 00:00:00 2001 From: kjuulh Date: Mon, 21 Nov 2022 14:09:03 +0100 Subject: [PATCH] add logging --- .cuddle/base | 1 + .cuddle/tmp/build_release.Dockerfile | 7 + .../tmp/build_release.Dockerfile.dockerignore | 2 + .../docker-compose.deploy_release.yml.tmpl | 17 ++ .env | 2 + Cargo.lock | 187 ++++++++++++++++++ Cargo.toml | 12 +- crates/octopush_cli/Cargo.toml | 5 +- crates/octopush_cli/src/commands/execute.rs | 2 +- crates/octopush_cli/src/lib.rs | 1 + crates/octopush_core/Cargo.toml | 1 + crates/octopush_core/src/git/mod.rs | 5 +- crates/octopush_infra/src/lib.rs | 15 -- src/main.rs | 10 + 14 files changed, 244 insertions(+), 23 deletions(-) create mode 160000 .cuddle/base create mode 100644 .cuddle/tmp/build_release.Dockerfile create mode 100644 .cuddle/tmp/build_release.Dockerfile.dockerignore create mode 100644 .cuddle/tmp/docker-compose.deploy_release.yml.tmpl create mode 100644 .env diff --git a/.cuddle/base b/.cuddle/base new file mode 160000 index 0000000..08a6b4d --- /dev/null +++ b/.cuddle/base @@ -0,0 +1 @@ +Subproject commit 08a6b4dda7513b2688733bfe27748952db5471ce diff --git a/.cuddle/tmp/build_release.Dockerfile b/.cuddle/tmp/build_release.Dockerfile new file mode 100644 index 0000000..34c3f87 --- /dev/null +++ b/.cuddle/tmp/build_release.Dockerfile @@ -0,0 +1,7 @@ +FROM golang + +COPY . . + +RUN go build cmd/main.go + +CMD [ "main" ] diff --git a/.cuddle/tmp/build_release.Dockerfile.dockerignore b/.cuddle/tmp/build_release.Dockerfile.dockerignore new file mode 100644 index 0000000..83cfe9f --- /dev/null +++ b/.cuddle/tmp/build_release.Dockerfile.dockerignore @@ -0,0 +1,2 @@ +.cuddle/ +main/ diff --git a/.cuddle/tmp/docker-compose.deploy_release.yml.tmpl b/.cuddle/tmp/docker-compose.deploy_release.yml.tmpl new file mode 100644 index 0000000..929fcf8 --- /dev/null +++ b/.cuddle/tmp/docker-compose.deploy_release.yml.tmpl @@ -0,0 +1,17 @@ +version: '3.7' + +services: + {{ service }}: + image: {{ image }} + ports: + - {{ port }} + env_file: ".env" + restart: always + depends_on: + - db + db: + image: postgres:13.5 + restart: always + env_file: ".env" + volumes: + - ./data/postgres:/var/lib/postgresql/data diff --git a/.env b/.env new file mode 100644 index 0000000..fbee64a --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +GITEA_USERNAME=kjuulh +GITEA_API_TOKEN=c0bd801cc9a7f2ed559ea45d603afc92f5443f19 diff --git a/Cargo.lock b/Cargo.lock index 02589e2..a11502e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -155,6 +155,12 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" +[[package]] +name = "itoa" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" + [[package]] name = "jobserver" version = "0.1.25" @@ -164,6 +170,12 @@ dependencies = [ "libc", ] +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" version = "0.2.136" @@ -229,6 +241,15 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata", +] + [[package]] name = "memchr" version = "2.5.0" @@ -247,6 +268,16 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num_cpus" version = "1.13.1" @@ -264,6 +295,8 @@ dependencies = [ "eyre", "octopush_cli", "tokio", + "tracing", + "tracing-subscriber", ] [[package]] @@ -274,6 +307,7 @@ dependencies = [ "eyre", "octopush_core", "octopush_infra", + "tracing", ] [[package]] @@ -327,6 +361,12 @@ version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "parking_lot" version = "0.12.1" @@ -431,12 +471,68 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + +[[package]] +name = "ryu" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" + [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "serde" +version = "1.0.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" + +[[package]] +name = "serde_json" +version = "1.0.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e8b3801309262e8184d9687fb697586833e939767aea0dda89f5a8e650e8bd7" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -488,6 +584,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "thread_local" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +dependencies = [ + "once_cell", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -534,6 +639,82 @@ dependencies = [ "syn", ] +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if", + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-serde" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" +dependencies = [ + "serde", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "serde", + "serde_json", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", + "tracing-serde", +] + [[package]] name = "unicode-bidi" version = "0.3.8" @@ -566,6 +747,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index 4b29b14..2d0b8c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,13 +12,17 @@ members = [ "crates/octopush_core", ] +[workspace.dependencies] +eyre = { version = "0.6.8" } +async-trait = "0.1.58" +tokio = { version = "1.21.2", features = ["full", "test-util"] } +tracing = { version = "0.1.37", features = ["log"] } + [dependencies] octopush_cli = { path = "crates/octopush_cli" } eyre = { workspace = true } tokio = { workspace = true } +tracing = { workspace = true } -[workspace.dependencies] -eyre = { version = "0.6.8" } -async-trait = "0.1.58" -tokio = { version = "1.21.2", features = ["full", "test-util"] } +tracing-subscriber = { version = "0.3.16", features = ["json", "env-filter"] } diff --git a/crates/octopush_cli/Cargo.toml b/crates/octopush_cli/Cargo.toml index 094612c..b8dc312 100644 --- a/crates/octopush_cli/Cargo.toml +++ b/crates/octopush_cli/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" octopush_infra = { path = "../octopush_infra" } octopush_core = { path = "../octopush_core" } -clap = { version = "4.0.18" } - eyre = { workspace = true } +tracing = { workspace = true } + +clap = { version = "4.0.18" } diff --git a/crates/octopush_cli/src/commands/execute.rs b/crates/octopush_cli/src/commands/execute.rs index 08e8f5b..c066840 100644 --- a/crates/octopush_cli/src/commands/execute.rs +++ b/crates/octopush_cli/src/commands/execute.rs @@ -16,7 +16,7 @@ pub fn execute_cmd() -> Command { } pub async fn execute_subcommand(args: &ArgMatches) -> eyre::Result<()> { - let action = args + let _action = args .get_one::("action") .ok_or(eyre::anyhow!("--action is required"))?; diff --git a/crates/octopush_cli/src/lib.rs b/crates/octopush_cli/src/lib.rs index ddd11b4..8d895fd 100644 --- a/crates/octopush_cli/src/lib.rs +++ b/crates/octopush_cli/src/lib.rs @@ -27,6 +27,7 @@ impl OctopushCli { match matches.subcommand() { Some(("execute", execute_sub)) => { + tracing::debug!("executing subcommand 'execute'"); commands::execute::execute_subcommand(execute_sub).await?; } Some(_) => return Err(eyre::anyhow!("unknown subcommand, please see --help")), diff --git a/crates/octopush_core/Cargo.toml b/crates/octopush_core/Cargo.toml index c100547..7b49219 100644 --- a/crates/octopush_core/Cargo.toml +++ b/crates/octopush_core/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" async-trait = { workspace = true } eyre = { workspace = true } tokio = { workspace = true } + rand = "0.8.5" hex = "0.4.3" git2 = "0.15.0" diff --git a/crates/octopush_core/src/git/mod.rs b/crates/octopush_core/src/git/mod.rs index fdbc491..385df10 100644 --- a/crates/octopush_core/src/git/mod.rs +++ b/crates/octopush_core/src/git/mod.rs @@ -1,9 +1,12 @@ use std::sync::Arc; +use async_trait::async_trait; + pub mod github; -#[async_trait::async_trait] +#[async_trait] pub trait GitProvider { async fn clone_from_url(&self, url: String) -> eyre::Result<()>; } + pub type DynGitProvider = Arc; diff --git a/crates/octopush_infra/src/lib.rs b/crates/octopush_infra/src/lib.rs index 1ae5b5e..8107689 100644 --- a/crates/octopush_infra/src/lib.rs +++ b/crates/octopush_infra/src/lib.rs @@ -1,16 +1 @@ pub mod service_register; - -pub fn add(left: usize, right: usize) -> usize { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} diff --git a/src/main.rs b/src/main.rs index 8d20109..0e86ad0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,15 @@ +use tracing_subscriber::prelude::*; + #[tokio::main] async fn main() -> eyre::Result<()> { + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG") + .unwrap_or_else(|_| "octopush,octopush_cli,octopush_core,octopush_infra".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); + let cli = octopush_cli::OctopushCli::new(); cli.execute().await }