add logging

This commit is contained in:
Kasper Juul Hermansen 2022-11-21 14:09:03 +01:00
parent dce155979e
commit af875e4688
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
14 changed files with 244 additions and 23 deletions

1
.cuddle/base Submodule

@ -0,0 +1 @@
Subproject commit 08a6b4dda7513b2688733bfe27748952db5471ce

View File

@ -0,0 +1,7 @@
FROM golang
COPY . .
RUN go build cmd/main.go
CMD [ "main" ]

View File

@ -0,0 +1,2 @@
.cuddle/
main/

View File

@ -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

2
.env Normal file
View File

@ -0,0 +1,2 @@
GITEA_USERNAME=kjuulh
GITEA_API_TOKEN=c0bd801cc9a7f2ed559ea45d603afc92f5443f19

187
Cargo.lock generated
View File

@ -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"

View File

@ -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"] }

View File

@ -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" }

View File

@ -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::<String>("action")
.ok_or(eyre::anyhow!("--action is required"))?;

View File

@ -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")),

View File

@ -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"

View File

@ -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<dyn GitProvider + Send + Sync>;

View File

@ -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);
}
}

View File

@ -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
}