From 2053220d013182d9f67a8079991313dba4c95ddb Mon Sep 17 00:00:00 2001 From: kjuulh Date: Tue, 7 Mar 2023 23:20:06 +0100 Subject: [PATCH] feat: add ci --- Cargo.lock | 855 +++++++++++++++++- Cargo.toml | 6 +- Makefile.toml | 5 + .../events/2023-03-06-gammeldags-oksesteg.md | 2 +- ci/Cargo.toml | 13 + ci/src/main.rs | 147 +++ crates/services/Cargo.toml | 2 + crates/services/src/lib.rs | 102 ++- src/api/events.rs | 13 +- src/main.rs | 18 +- 10 files changed, 1092 insertions(+), 71 deletions(-) create mode 100644 ci/Cargo.toml create mode 100644 ci/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 336bf43..3b155ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,6 +46,25 @@ dependencies = [ "libc", ] +[[package]] +name = "ascii" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e" + +[[package]] +name = "async-compression" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "942c7cd7ae39e91bde4820d74132e9862e62c2f386c3aa90ccf55949f5bad63a" +dependencies = [ + "flate2", + "futures-core", + "memchr", + "pin-project-lite", + "tokio", +] + [[package]] name = "async-recursion" version = "1.0.2" @@ -59,9 +78,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.65" +version = "0.1.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "095183a3539c7c7649b2beb87c2d3f0591f3a7fed07761cc546d244e27e0238c" +checksum = "b84f9ebcc6c1f5b8cb160f6990096a5c127f423fcb6e1ccc46c370cbdfb75dfc" dependencies = [ "proc-macro2", "quote", @@ -286,6 +305,9 @@ name = "cc" version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +dependencies = [ + "jobserver", +] [[package]] name = "cfg-if" @@ -309,6 +331,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "ci" +version = "0.1.0" +dependencies = [ + "chrono", + "color-eyre", + "dagger-sdk", + "eyre", + "tokio", +] + [[package]] name = "ciborium" version = "0.2.0" @@ -406,6 +439,19 @@ dependencies = [ "winapi", ] +[[package]] +name = "combine" +version = "3.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680" +dependencies = [ + "ascii", + "byteorder", + "either", + "memchr", + "unreachable", +] + [[package]] name = "common_macros" version = "0.1.1" @@ -460,6 +506,16 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.3" @@ -475,6 +531,26 @@ dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "cron" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ff76b51e4c068c52bfd2866e1567bee7c567ae8f24ada09fd4307019e25eab7" +dependencies = [ + "chrono", + "nom", + "once_cell", +] + [[package]] name = "crossterm" version = "0.25.0" @@ -512,9 +588,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.91" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d3488e7665a7a483b57e25bdd90d0aeb2bc7608c8d0346acf2ad3f1caf1d62" +checksum = "9a140f260e6f3f79013b8bfc65e7ce630c9ab4388c6a89c71e07226f49487b72" dependencies = [ "cc", "cxxbridge-flags", @@ -524,9 +600,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.91" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48fcaf066a053a41a81dfb14d57d99738b767febb8b735c3016e469fac5da690" +checksum = "da6383f459341ea689374bf0a42979739dc421874f112ff26f829b8040b8e613" dependencies = [ "cc", "codespan-reporting", @@ -539,21 +615,63 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.91" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2ef98b8b717a829ca5603af80e1f9e2e48013ab227b68ef37872ef84ee479bf" +checksum = "90201c1a650e95ccff1c8c0bb5a343213bdd317c6e600a93075bca2eff54ec97" [[package]] name = "cxxbridge-macro" -version = "1.0.91" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "086c685979a698443656e5cf7856c95c642295a38599f12fb1ff76fb28d19892" +checksum = "0b75aed41bb2e6367cae39e6326ef817a851db13c13e4f3263714ca3cfb8de56" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "dagger-core" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e41269348f54df20e0a70b80617d074ebc5138f38ea0cd8e7e2879a2032652c0" +dependencies = [ + "clap", + "dirs", + "eyre", + "flate2", + "genco", + "graphql-introspection-query", + "graphql_client", + "hex", + "hex-literal", + "platform-info", + "reqwest", + "serde", + "serde_json", + "sha2", + "tar", + "tempfile", + "tokio", +] + +[[package]] +name = "dagger-sdk" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "729d4b46f4a24dda5177c1a66ea8cffb18a2f08a83b085d086ff2b2caeff535e" +dependencies = [ + "base64 0.21.0", + "dagger-core", + "derive_builder", + "eyre", + "futures 0.3.26", + "gql_client", + "serde", + "serde_json", + "tokio", +] + [[package]] name = "darling" version = "0.14.3" @@ -589,6 +707,37 @@ dependencies = [ "syn", ] +[[package]] +name = "derive_builder" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d67778784b508018359cbc8696edb3db78160bab2c2a28ba7f56ef6932997f8" +dependencies = [ + "derive_builder_macro", +] + +[[package]] +name = "derive_builder_core" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "derive_builder_macro" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e" +dependencies = [ + "derive_builder_core", + "syn", +] + [[package]] name = "digest" version = "0.10.6" @@ -599,6 +748,26 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "dlv-list" version = "0.3.0" @@ -644,6 +813,15 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +[[package]] +name = "encoding_rs" +version = "0.8.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" +dependencies = [ + "cfg-if", +] + [[package]] name = "enum-ordinalize" version = "3.1.12" @@ -698,12 +876,50 @@ dependencies = [ "instant", ] +[[package]] +name = "filetime" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a3de6e8d11b22ff9edc6d916f890800597d60f8b2da1caf2955c274638d6412" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "windows-sys 0.45.0", +] + +[[package]] +name = "flate2" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" +dependencies = [ + "crc32fast", + "libz-sys", + "miniz_oxide", +] + [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.1.0" @@ -829,6 +1045,28 @@ dependencies = [ "slab", ] +[[package]] +name = "genco" +version = "0.17.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43de41c8ce1ed5ac84a1b11fb3e4ef604bf6773068798490eaa95e8151abad20" +dependencies = [ + "genco-macros", + "relative-path", + "smallvec", +] + +[[package]] +name = "genco-macros" +version = "0.17.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c85fd34848b1f708e6344a4af6f7bfc05172ae20ce4b35c8e417efffb4f306aa" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "generic-array" version = "0.14.6" @@ -858,6 +1096,38 @@ version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4" +[[package]] +name = "git2" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf7f68c2995f392c49fffb4f95ae2c873297830eb25c6bc4c114ce8f4562acc" +dependencies = [ + "bitflags", + "libc", + "libgit2-sys", + "log", + "openssl-probe", + "openssl-sys", + "url", +] + +[[package]] +name = "gitevents_sdk" +version = "0.1.0" +source = "git+https://github.com/kjuulh/gitevents.git?branch=main#6193de8778bdef94a2cdecd8c90f72ddeedd522c" +dependencies = [ + "async-trait", + "eyre", + "futures 0.3.26", + "git2", + "tokio", + "tokio-cron-scheduler", + "tracing", + "tracing-subscriber", + "tracing-test", + "uuid", +] + [[package]] name = "gloo-net" version = "0.2.6" @@ -891,6 +1161,96 @@ dependencies = [ "web-sys", ] +[[package]] +name = "gql_client" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e57f4862d3e5cd4ffe8df03fa2137e620e33578bbc1895e6f8f569630e17b1db" +dependencies = [ + "log", + "reqwest", + "serde", + "serde_json", +] + +[[package]] +name = "graphql-introspection-query" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f2a4732cf5140bd6c082434494f785a19cfb566ab07d1382c3671f5812fed6d" +dependencies = [ + "serde", +] + +[[package]] +name = "graphql-parser" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ebc8013b4426d5b81a4364c419a95ed0b404af2b82e2457de52d9348f0e474" +dependencies = [ + "combine", + "thiserror", +] + +[[package]] +name = "graphql_client" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa61bb9dc6d373a8b465a5da17b62809483e8527a34b0e9034dc0915b09e160a" +dependencies = [ + "graphql_query_derive", + "reqwest", + "serde", + "serde_json", +] + +[[package]] +name = "graphql_client_codegen" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e55df64cc702c4ad6647f8df13a799ad11688a3781fadf5045f7ba12733fa9b" +dependencies = [ + "graphql-introspection-query", + "graphql-parser", + "heck", + "lazy_static", + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn", +] + +[[package]] +name = "graphql_query_derive" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52fc9cde811f44b15ec0692b31e56a3067f6f431c5ace712f286e47c1dacc98" +dependencies = [ + "graphql_client_codegen", + "proc-macro2", + "syn", +] + +[[package]] +name = "h2" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be7b54589b581f624f566bf5d8eb2bab1db736c51528720b6bd36b96b55924d" +dependencies = [ + "bytes 1.4.0", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "half" version = "1.8.2" @@ -942,6 +1302,18 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hex-literal" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" + [[package]] name = "html-escape" version = "0.2.13" @@ -1001,6 +1373,7 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", + "h2", "http", "http-body", "httparse", @@ -1014,6 +1387,19 @@ dependencies = [ "want", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes 1.4.0", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "iana-time-zone" version = "0.1.53" @@ -1116,6 +1502,12 @@ dependencies = [ "libc", ] +[[package]] +name = "ipnet" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" + [[package]] name = "is-terminal" version = "0.4.4" @@ -1143,6 +1535,15 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +[[package]] +name = "jobserver" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.61" @@ -1371,6 +1772,46 @@ version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +[[package]] +name = "libgit2-sys" +version = "0.14.2+1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f3d95f6b51075fe9810a7ae22c7095f12b98005ab364d8544797a825ce946a4" +dependencies = [ + "cc", + "libc", + "libssh2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", +] + +[[package]] +name = "libssh2-sys" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b094a36eb4b8b8c8a7b4b8ae43b2944502be3e59cd87687595cf6b0a71b3f4ca" +dependencies = [ + "cc", + "libc", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "libz-sys" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linear-map" version = "1.2.0" @@ -1417,6 +1858,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 = "matchit" version = "0.7.0" @@ -1472,6 +1922,24 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "newline-converter" version = "0.2.2" @@ -1512,6 +1980,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-derive" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -1565,6 +2044,61 @@ version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +[[package]] +name = "openssl" +version = "0.10.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-src" +version = "111.25.1+1.1.1t" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ef9a9cc6ea7d9d5e7c4a913dc4b48d0e359eddf01af1dfec96ba7064b4aba10" +dependencies = [ + "cc", +] + +[[package]] +name = "openssl-sys" +version = "0.9.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7" +dependencies = [ + "autocfg", + "cc", + "libc", + "openssl-src", + "pkg-config", + "vcpkg", +] + [[package]] name = "ordered-multimap" version = "0.4.3" @@ -1624,9 +2158,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba" +checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" [[package]] name = "pathdiff" @@ -1642,9 +2176,9 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pest" -version = "2.5.5" +version = "2.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "028accff104c4e513bad663bbcd2ad7cfd5304144404c31ed0a77ac103d00660" +checksum = "8cbd939b234e95d72bc393d51788aec68aeeb5d51e748ca08ff3aad58cb722f7" dependencies = [ "thiserror", "ucd-trie", @@ -1652,9 +2186,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.5.5" +version = "2.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ac3922aac69a40733080f53c1ce7f91dcf57e1a5f6c52f421fadec7fbdc4b69" +checksum = "a81186863f3d0a27340815be8f2078dd8050b14cd71913db9fbda795e5f707d7" dependencies = [ "pest", "pest_generator", @@ -1662,9 +2196,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.5.5" +version = "2.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d06646e185566b5961b4058dd107e0a7f56e77c3f484549fb119867773c0f202" +checksum = "75a1ef20bf3193c15ac345acb32e26b3dc3223aff4d77ae4fc5359567683796b" dependencies = [ "pest", "pest_meta", @@ -1675,9 +2209,9 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.5.5" +version = "2.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6f60b2ba541577e2a0c307c8f39d1439108120eb7903adeb6497fa880c59616" +checksum = "5e3b284b1f13a20dc5ebc90aff59a51b8d7137c221131b52a7260c08cbc1cc80" dependencies = [ "once_cell", "pest", @@ -1717,10 +2251,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] -name = "prettyplease" -version = "0.1.23" +name = "pkg-config" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e97e3215779627f01ee256d2fad52f3d95e8e1c11e9fc6fd08f7cd455d5d5c78" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" + +[[package]] +name = "platform-info" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7c23cfae725ae06d9e43010153fa77bdfa8c827bf08fe4beeb2a3514e6be12" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "prettyplease" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebcd279d20a4a0a2404a33056388e950504d891c855c7975b9a8fef75f3bf04" dependencies = [ "proc-macro2", "syn", @@ -1777,6 +2327,17 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom", + "redox_syscall", + "thiserror", +] + [[package]] name = "regex" version = "1.7.1" @@ -1788,12 +2349,67 @@ 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 = "relative-path" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bf2521270932c3c7bed1a59151222bd7643c79310f2916f01925e1e16255698" + +[[package]] +name = "reqwest" +version = "0.11.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21eed90ec8570952d53b772ecf8f206aa1ec9a3d76b2521c56c42973f2d91ee9" +dependencies = [ + "async-compression", + "base64 0.21.0", + "bytes 1.4.0", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "tokio-util", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-streams", + "web-sys", + "winreg", +] + [[package]] name = "ron" version = "0.7.1" @@ -1852,9 +2468,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" +checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" [[package]] name = "ryu" @@ -1862,6 +2478,15 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +[[package]] +name = "schannel" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +dependencies = [ + "windows-sys 0.42.0", +] + [[package]] name = "scopeguard" version = "1.1.0" @@ -1870,9 +2495,32 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "scratch" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d5e082f6ea090deaf0e6dd04b68360fd5cddb152af6ce8927c9d25db299f98c" +checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1" + +[[package]] +name = "security-framework" +version = "2.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" +dependencies = [ + "core-foundation-sys", + "libc", +] [[package]] name = "semver" @@ -1882,9 +2530,9 @@ checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a" [[package]] name = "serde" -version = "1.0.152" +version = "1.0.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +checksum = "3a382c72b4ba118526e187430bb4963cd6d55051ebf13d9b25574d379cc98d20" dependencies = [ "serde_derive", ] @@ -1902,9 +2550,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.152" +version = "1.0.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +checksum = "1ef476a5790f0f6decbc66726b6e5d63680ed518283e64c7df415989d880954f" dependencies = [ "proc-macro2", "quote", @@ -1964,10 +2612,12 @@ dependencies = [ "chrono", "domain", "eyre", + "gitevents_sdk", "serde", "serde_json", "serde_yaml", "tokio", + "tracing", "uuid", ] @@ -2092,6 +2742,8 @@ dependencies = [ "tokio", "tower", "tower-http", + "tracing", + "tracing-subscriber", "uuid", "wasm-bindgen", ] @@ -2131,6 +2783,17 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "tar" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b55807c0344e1e6c04d7c965f5289c39a8d94ae23ed5c0b57aabac549f871c6" +dependencies = [ + "filetime", + "libc", + "xattr", +] + [[package]] name = "tempfile" version = "3.4.0" @@ -2155,18 +2818,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.38" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" +checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.38" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" +checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" dependencies = [ "proc-macro2", "quote", @@ -2258,6 +2921,21 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "tokio-cron-scheduler" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de2c1fd54a857b29c6cd1846f31903d0ae8e28175615c14a277aed45c58d8e27" +dependencies = [ + "chrono", + "cron", + "num-derive", + "num-traits", + "tokio", + "tracing", + "uuid", +] + [[package]] name = "tokio-macros" version = "1.8.2" @@ -2269,6 +2947,16 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.7" @@ -2280,6 +2968,7 @@ dependencies = [ "futures-sink", "pin-project-lite", "tokio", + "tracing", ] [[package]] @@ -2399,18 +3088,58 @@ dependencies = [ "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 = "tracing-test" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a2c0ff408fe918a94c428a3f2ad04e4afd5c95bbc08fcf868eff750c15728a4" +dependencies = [ + "lazy_static", + "tracing-core", + "tracing-subscriber", + "tracing-test-macro", +] + +[[package]] +name = "tracing-test-macro" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258bc1c4f8e2e73a977812ab339d503e6feeb92700f6d07a6de4d321522d5c08" +dependencies = [ + "lazy_static", + "quote", + "syn", ] [[package]] @@ -2459,9 +3188,9 @@ checksum = "d54675592c1dbefd78cbd98db9bacd89886e1ca50692a0692baefffdeb92dd58" [[package]] name = "unicode-ident" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "775c11906edafc97bc378816b94585fbd9a054eabaf86fdd0ced94af449efab7" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" [[package]] name = "unicode-normalization" @@ -2484,6 +3213,15 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +[[package]] +name = "unreachable" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" +dependencies = [ + "void", +] + [[package]] name = "unsafe-libyaml" version = "0.2.7" @@ -2524,12 +3262,24 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + [[package]] name = "want" version = "0.3.0" @@ -2618,6 +3368,19 @@ version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +[[package]] +name = "wasm-streams" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bbae3363c08332cadccd13b67db371814cd214c2524020932f0804b8cf7c078" +dependencies = [ + "futures-util", + "js-sys", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "web-sys" version = "0.3.61" @@ -2740,6 +3503,24 @@ version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] + +[[package]] +name = "xattr" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d1526bbe5aaeb5eb06885f4d987bcdfa5e23187055de9b83fe00156a821fabc" +dependencies = [ + "libc", +] + [[package]] name = "yaml-rust" version = "0.4.5" diff --git a/Cargo.toml b/Cargo.toml index 84837ed..091de89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = [".", "crates/services", "crates/domain", "crates/biteme"] +members = [".", "crates/services", "crates/domain", "crates/biteme", "ci"] [workspace.dependencies] domain = { path = "crates/domain" } @@ -35,6 +35,8 @@ tower = { version = "0.4.13", optional = true } tower-http = { version = "0.3.4", features = ["fs"], optional = true } tokio = { version = "1", features = ["time"], optional = true } wasm-bindgen = "0.2" +tracing-subscriber = { version = "0.3.16", optional = true } +tracing = { version = "0.1.37", features = ["log"], optional = true } serde = { workspace = true } chrono = { workspace = true } @@ -55,6 +57,8 @@ ssr = [ "leptos_router/ssr", "dep:leptos_axum", "dep:services", + "dep:tracing-subscriber", + "dep:tracing", ] [package.metadata.leptos] diff --git a/Makefile.toml b/Makefile.toml index 5b9e15f..c8af747 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -30,3 +30,8 @@ command = "cargo" args = ["install", "--path", "crates/biteme"] workspace = false install_crate = "cargo-all-features" + +[tasks.ci] +command = "cargo" +args = ["run", "-p", "ci"] +workspace = false diff --git a/articles/events/2023-03-06-gammeldags-oksesteg.md b/articles/events/2023-03-06-gammeldags-oksesteg.md index 9910ccc..d91d911 100644 --- a/articles/events/2023-03-06-gammeldags-oksesteg.md +++ b/articles/events/2023-03-06-gammeldags-oksesteg.md @@ -7,7 +7,7 @@ description: | God gammeldags oksesteg med en intens og fyldig brun sauce. Gammeldags oksesteg er rigtig simremad som gør de fleste glade. Så server en gammeldags oksesteg for din gæster... både de unge og de gamle. -time: 2023-03-06 +time: 2025-03-06 --- Some article diff --git a/ci/Cargo.toml b/ci/Cargo.toml new file mode 100644 index 0000000..db60045 --- /dev/null +++ b/ci/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "ci" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +dagger-sdk = "0.2.15" +eyre = "0.6.8" +color-eyre = "0.6.2" +tokio = { version = "1.26.0", features = ["full"] } +chrono.workspace = true diff --git a/ci/src/main.rs b/ci/src/main.rs new file mode 100644 index 0000000..299b611 --- /dev/null +++ b/ci/src/main.rs @@ -0,0 +1,147 @@ +#[tokio::main] +async fn main() -> eyre::Result<()> { + let rust_image = "rustlang/rust:nightly"; + + let client = dagger_sdk::connect().await?; + + let workdir = client.host().directory_opts( + ".", + dagger_sdk::HostDirectoryOpts { + exclude: Some(vec!["target/", ".git/"]), + include: None, + }, + ); + + let minio_url = "https://github.com/mozilla/sccache/releases/download/v0.3.3/sccache-v0.3.3-x86_64-unknown-linux-musl.tar.gz"; + + // Main container + let rust_base = client + .container() + .from(rust_image) + .with_exec(vec!["apt-get", "update"]) + .with_exec(vec!["apt-get", "install", "--yes", "libpq-dev", "wget"]) + .with_exec(vec!["wget", minio_url]) + .with_exec(vec![ + "tar", + "xzf", + "sccache-v0.3.3-x86_64-unknown-linux-musl.tar.gz", + ]) + .with_exec(vec![ + "mv", + "sccache-v0.3.3-x86_64-unknown-linux-musl/sccache", + "/usr/local/bin/sccache", + ]) + .with_exec(vec!["chmod", "+x", "/usr/local/bin/sccache"]) + .with_env_variable("RUSTC_WRAPPER", "/usr/local/bin/sccache") + .with_env_variable( + "AWS_ACCESS_KEY_ID", + std::env::var("AWS_ACCESS_KEY_ID").unwrap_or("".into()), + ) + .with_env_variable( + "AWS_SECRET_ACCESS_KEY", + std::env::var("AWS_SECRET_ACCESS_KEY").unwrap_or("".into()), + ) + .with_env_variable("SCCACHE_BUCKET", "sccache") + .with_env_variable("SCCACHE_REGION", "auto") + .with_env_variable("SCCACHE_ENDPOINT", "https://api-minio.front.kjuulh.io") + .with_exec(vec!["cargo", "install", "cargo-chef"]) + .with_exec(vec!["cargo", "install", "cargo-leptos"]) + .with_workdir("/app"); + + let exit_code = rust_base.exit_code().await?; + if exit_code != 0 { + eyre::bail!("could not build base"); + } + + let rust_prepare = rust_base + .with_mounted_directory(".", workdir.id().await?) + .with_exec(vec![ + "cargo", + "chef", + "prepare", + "--recipe-path", + "recipe.json", + ]); + + let exit_code = rust_prepare.exit_code().await?; + if exit_code != 0 { + eyre::bail!("could not build prepare"); + } + + let rust_cacher = rust_base + .with_exec(vec!["apt", "update"]) + .with_exec(vec![ + "apt", + "install", + "pkg-config", + "openssl", + "libssl-dev", + "-y", + ]) + .with_exec(vec!["rustup", "target", "add", "wasm32-unknown-unknown"]) + .with_file( + "/recipe.json", + rust_prepare.file("./recipe.json").id().await?, + ) + .with_mounted_directory(".", workdir.id().await?) + .with_exec(vec![ + "cargo", + "chef", + "cook", + "--release", + "--recipe-path", + "/recipe.json", + ]); + + let exit_code = rust_cacher.exit_code().await?; + if exit_code != 0 { + eyre::bail!("could not build cacher"); + } + + let rust_builder = rust_base + .with_exec(vec![ + "curl", + "-sL", + "https://deb.nodesource.com/setup_12.x", + "-o", + "/node_12.txt", + ]) + .with_exec(vec!["chmod", "+x", "/node_12.txt"]) + .with_exec(vec!["bash", "-c", "/node_12.txt"]) + .with_exec(vec!["apt-get", "update"]) + .with_exec(vec!["apt-get", "install", "nodejs"]) + .with_mounted_directory(".", workdir.id().await?) + .with_directory( + "/app/target", + rust_cacher.directory("/app/target").id().await?, + ) + .with_directory( + "/usr/local/cargo", + rust_cacher.directory("/usr/local/cargo").id().await?, + ) + .with_exec(vec!["rustup", "target", "add", "wasm32-unknown-unknown"]) + .with_exec(vec!["npm", "install", "-g", "sass"]) + .with_env_variable("LEPTOS_BROWSERQUERY", "defaults") + .with_exec(vec!["cargo", "leptos", "build", "--release"]); + + let exit_code = rust_builder.exit_code().await?; + if exit_code != 0 { + eyre::bail!("could not build builder"); + } + + let tag = chrono::Utc::now().timestamp(); + + let prod_image = "gcr.io/distroless/cc-debian11"; + let prod = client + .container() + .from(prod_image) + .with_workdir("/app") + .with_directory("/app", rust_builder.directory("/app/target").id().await?) + .with_env_variable("LEPTOS_SITE_ADDRESS", "0.0.0.0:3000") + .with_entrypoint(vec!["./server/release/ssr_mode_axum"]); + + prod.publish(format!("docker.io/kasperhermansen/bitebuds:{tag}")) + .await?; + + Ok(()) +} diff --git a/crates/services/Cargo.toml b/crates/services/Cargo.toml index 58b5848..9d05500 100644 --- a/crates/services/Cargo.toml +++ b/crates/services/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +gitevents_sdk = { git = "https://github.com/kjuulh/gitevents.git", branch = "main" } cached = "0.42.0" chrono = { version = "0.4.23", features = ["serde"] } domain = { path = "../domain" } @@ -18,3 +19,4 @@ serde_json = "1.0.94" serde_yaml = "0.9.19" tokio = { version = "1.26.0", features = ["full"] } uuid = { version = "1.3.0", features = ["v4", "serde"] } +tracing = { version = "0.1.37", features = ["log"] } diff --git a/crates/services/src/lib.rs b/crates/services/src/lib.rs index 3246ae2..91342f2 100644 --- a/crates/services/src/lib.rs +++ b/crates/services/src/lib.rs @@ -1,15 +1,10 @@ +use cached::proc_macro::once; +use domain::{Event, Image, Metadata}; +use gitevents_sdk::events::EventResponse; +use serde::{Deserialize, Serialize}; use std::path::PathBuf; use std::sync::Arc; -use cached::proc_macro::{cached, once}; -use domain::{Event, Image, Metadata}; -use serde::{Deserialize, Serialize}; - -pub struct EventStore { - pub path: PathBuf, - events: Arc>>, -} - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RawImage { pub url: String, @@ -81,28 +76,89 @@ impl From for Image { } } +struct InnerEventStore { + url: Option, + pub path: PathBuf, + events: Arc>>, +} + +#[derive(Clone)] +pub struct EventStore { + inner: Arc, +} + impl EventStore { pub fn new(path: PathBuf) -> Self { + let article_repo_url = std::env::var("BITE_ARTICLE_REPO_URL") + .map(|a| (a != "").then(|| a)) + .unwrap_or(None); Self { - path, - events: Default::default(), + inner: Arc::new(InnerEventStore { + url: article_repo_url, + path, + events: Default::default(), + }), } } + pub async fn bootstrap(&self) -> eyre::Result<()> { + tracing::info!("boostrapping event_store"); + //let mut event_path = self.inner.path.clone(); + //event_path.push("events"); + + //let events = fetch_events(event_path.clone()).await?; + + //let mut e = self.inner.events.write().await; + //*e = events; + + if let Some(repo_url) = self.inner.url.clone() { + tracing::info!(repo_url = repo_url, "subscribing to repo"); + let inner = self.inner.clone(); + + tokio::task::spawn(async move { + gitevents_sdk::builder::Builder::new() + .set_generic_git_url(repo_url) + .set_scheduler_opts(&gitevents_sdk::cron::SchedulerOpts { + duration: std::time::Duration::from_secs(30), + }) + .action(move |req| { + let inner = inner.clone(); + + async move { + tracing::info!("updating articles"); + let mut event_path = req.git.path.clone(); + event_path.push("articles/events"); + + tracing::debug!( + path = event_path.display().to_string(), + "reading from" + ); + + let events = fetch_events(event_path).await.unwrap(); + + let mut e = inner.events.write().await; + *e = events.clone(); + + Ok(EventResponse {}) + } + }) + .execute() + .await + .unwrap(); + }); + } + + Ok(()) + } + pub async fn get_upcoming_events(&self) -> eyre::Result> { - let mut event_path = self.path.clone(); - event_path.push("events"); - - let events = fetch_events(event_path).await?; - - let mut e = self.events.write().await; - *e = events.clone(); + let events = self.inner.events.read().await.clone(); Ok(events) } pub async fn get_event(&self, event_id: uuid::Uuid) -> eyre::Result> { - let events = self.events.read().await; + let events = self.inner.events.read().await; let event = events.iter().find(|e| e.id == event_id); @@ -110,7 +166,6 @@ impl EventStore { } } -#[once(time = 60, result = true, sync_writes = true)] pub async fn fetch_events(event_path: PathBuf) -> eyre::Result> { let mut dir = tokio::fs::read_dir(event_path).await?; @@ -140,8 +195,11 @@ pub async fn fetch_events(event_path: PathBuf) -> eyre::Result> { impl Default for EventStore { fn default() -> Self { Self { - path: PathBuf::from("articles"), - events: Default::default(), + inner: Arc::new(InnerEventStore { + url: Default::default(), + path: PathBuf::from("articles"), + events: Default::default(), + }), } } } diff --git a/src/api/events.rs b/src/api/events.rs index 1365458..8c23b2b 100644 --- a/src/api/events.rs +++ b/src/api/events.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use cfg_if::cfg_if; use leptos::*; use serde::{Deserialize, Serialize}; @@ -10,11 +12,9 @@ cfg_if! { use lazy_static::lazy_static; lazy_static! { - static ref EVENTSTORE: EventStore = EventStore::default(); + static ref EVENTSTORE: EventStore = EventStore::new(PathBuf::from("articles")); } async fn get_upcoming_events_fn() -> Result { - let current_time = chrono::Utc::now(); - let mut events: Vec = EVENTSTORE .get_upcoming_events() .await @@ -24,7 +24,7 @@ cfg_if! { .map(|data| data.clone().into()) .collect(); - events.sort_by(|a, b| a.time.cmp(&b.time)); + events.sort_by(|a, b| a.time.cmp(&b.time)) ; Ok(UpcomingEventsOverview { events }) } @@ -33,9 +33,12 @@ cfg_if! { .get_event(event_id) .await .map_err(|e| ServerFnError::ServerError(e.to_string()))?; - Ok(event) } + + pub async fn boostrap() -> Result<(), ServerFnError> { + EVENTSTORE.bootstrap().await.map_err(|e| ServerFnError::ServerError(e.to_string())) + } } } diff --git a/src/main.rs b/src/main.rs index 2b4efd1..5b3f1ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,24 @@ #[cfg(feature = "ssr")] #[tokio::main] async fn main() { - use axum::{ - extract::{Extension, Path}, - routing::{get, post}, - Router, - }; + use axum::{extract::Extension, routing::post, Router}; use leptos::*; use leptos_axum::{generate_route_list, LeptosRoutes}; use ssr_modes_axum::app::*; use ssr_modes_axum::fallback::file_and_error_handler; use std::sync::Arc; + use tracing::metadata::LevelFilter; + + std::env::set_var( + "BITE_ARTICLE_REPO_URL", + "git@git.front.kjuulh.io:kjuulh/articles.git", + ); + + tracing_subscriber::fmt() + .with_max_level(LevelFilter::TRACE) + .init(); + + ssr_modes_axum::api::events::boostrap().await.unwrap(); let conf = get_configuration(None).await.unwrap(); let addr = conf.leptos_options.site_addr;