From 503f1e3c1ce8cfb8ffafad1846bb795eb2542e32 Mon Sep 17 00:00:00 2001 From: Amninder Kaur Date: Fri, 11 Aug 2023 15:05:59 +1000 Subject: [PATCH] chore: binaries and github actions --- .env | 2 +- .github/workflows/build.yml | 24 +- Cargo.lock | 570 ++++++++---------- Cargo.toml | 16 +- Dockerfile.chronos | 36 ++ Dockerfile.chronos-pg-migrations | 36 ++ benches/consumer_bench.rs | 2 +- chronos_bin/Cargo.toml | 40 ++ chronos_bin/src/bin/chronos.rs | 31 + {src => chronos_bin/src}/core.rs | 0 {src => chronos_bin/src}/kafka/config.rs | 0 {src => chronos_bin/src}/kafka/consumer.rs | 0 {src => chronos_bin/src}/kafka/errors.rs | 0 .../src}/kafka/kafka_deploy.rs | 0 {src => chronos_bin/src}/kafka/mod.rs | 1 - {src => chronos_bin/src}/kafka/producer.rs | 0 {src => chronos_bin/src}/kafka/utils.rs | 0 {src => chronos_bin/src}/lib.rs | 5 +- {src => chronos_bin/src}/message_processor.rs | 0 {src => chronos_bin/src}/message_receiver.rs | 0 {src => chronos_bin/src}/monitor.rs | 0 {src => chronos_bin/src}/persistence_store.rs | 0 {src => chronos_bin/src}/postgres/config.rs | 0 {src => chronos_bin/src}/postgres/errors.rs | 0 {src => chronos_bin/src}/postgres/mod.rs | 0 {src => chronos_bin/src}/postgres/pg.rs | 0 .../src}/postgres/pg_deploy.rs | 0 {src => chronos_bin/src}/postgres/utils.rs | 0 {src => chronos_bin/src}/runner.rs | 0 {src => chronos_bin/src}/utils/env.rs | 0 {src => chronos_bin/src}/utils/mod.rs | 0 {src => chronos_bin/src}/utils/util.rs | 0 examples/chronos_bin/Cargo.toml | 27 + .../chronos_bin/examples/chronos_binary.rs | 34 ++ examples/chronos_binary.rs | 81 --- migrations/Cargo.lock | 7 + migrations/Cargo.toml | 20 + migrations/migrations/V1__initial.sql | 10 + migrations/migrations/V2__index.sql | 1 + migrations/src/bin/chronos-pg-migrations.rs | 27 + migrations/src/config.rs | 39 ++ migrations/src/lib.rs | 1 + scripts/pre-commit-checks.sh | 7 + 43 files changed, 617 insertions(+), 400 deletions(-) create mode 100644 Dockerfile.chronos create mode 100644 Dockerfile.chronos-pg-migrations create mode 100644 chronos_bin/Cargo.toml create mode 100644 chronos_bin/src/bin/chronos.rs rename {src => chronos_bin/src}/core.rs (100%) rename {src => chronos_bin/src}/kafka/config.rs (100%) rename {src => chronos_bin/src}/kafka/consumer.rs (100%) rename {src => chronos_bin/src}/kafka/errors.rs (100%) rename {src => chronos_bin/src}/kafka/kafka_deploy.rs (100%) rename {src => chronos_bin/src}/kafka/mod.rs (83%) rename {src => chronos_bin/src}/kafka/producer.rs (100%) rename {src => chronos_bin/src}/kafka/utils.rs (100%) rename {src => chronos_bin/src}/lib.rs (70%) rename {src => chronos_bin/src}/message_processor.rs (100%) rename {src => chronos_bin/src}/message_receiver.rs (100%) rename {src => chronos_bin/src}/monitor.rs (100%) rename {src => chronos_bin/src}/persistence_store.rs (100%) rename {src => chronos_bin/src}/postgres/config.rs (100%) rename {src => chronos_bin/src}/postgres/errors.rs (100%) rename {src => chronos_bin/src}/postgres/mod.rs (100%) rename {src => chronos_bin/src}/postgres/pg.rs (100%) rename {src => chronos_bin/src}/postgres/pg_deploy.rs (100%) rename {src => chronos_bin/src}/postgres/utils.rs (100%) rename {src => chronos_bin/src}/runner.rs (100%) rename {src => chronos_bin/src}/utils/env.rs (100%) rename {src => chronos_bin/src}/utils/mod.rs (100%) rename {src => chronos_bin/src}/utils/util.rs (100%) create mode 100644 examples/chronos_bin/Cargo.toml create mode 100644 examples/chronos_bin/examples/chronos_binary.rs delete mode 100644 examples/chronos_binary.rs create mode 100644 migrations/Cargo.lock create mode 100644 migrations/Cargo.toml create mode 100644 migrations/migrations/V1__initial.sql create mode 100644 migrations/migrations/V2__index.sql create mode 100644 migrations/src/bin/chronos-pg-migrations.rs create mode 100644 migrations/src/config.rs create mode 100644 migrations/src/lib.rs create mode 100644 scripts/pre-commit-checks.sh diff --git a/.env b/.env index ecbcb6c..8bb4103 100644 --- a/.env +++ b/.env @@ -28,4 +28,4 @@ ADMIN_PG_PASSWORD=admin ADMIN_PG_DATABASE=postgres # CONFIG -RUST_LOG=info +RUST_LOG=info diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a86a4d8..310120a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,9 @@ name: build on: - workflow_call: + push: + branches: + - feature/* jobs: build: @@ -11,8 +13,24 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: toolchain: stable - - run: scripts/ubuntu-setup.sh - run: rustup component add rustfmt clippy - name: cargo build run: cargo build - - run: scripts/pre-commit-checks.sh + publish: + runs-on: ubuntu-latest + needs: build + if: needs.build.result == 'success' + steps: + - name: Checkout the repo + uses: actions/checkout@v3 + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.AMN_PAT }} + + - name: Build the chronos Docker image + run: | + docker build -f Dockerfile.chronos . --tag ghcr.io/kindredgroup/chronos:latest + docker push ghcr.io/kindredgroup/chronos:latest diff --git a/Cargo.lock b/Cargo.lock index a49ee5f..e7c709f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "aho-corasick" version = "0.7.20" @@ -17,6 +11,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + [[package]] name = "android_system_properties" version = "0.1.5" @@ -33,10 +33,53 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] -name = "anyhow" -version = "1.0.69" +name = "anstream" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" + +[[package]] +name = "anstyle-parse" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "anstyle-wincon" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" +dependencies = [ + "anstyle", + "windows-sys 0.48.0", +] [[package]] name = "arrayref" @@ -58,7 +101,7 @@ checksum = "b84f9ebcc6c1f5b8cb160f6990096a5c127f423fcb6e1ccc46c370cbdfb75dfc" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -90,6 +133,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" + [[package]] name = "blake2b_simd" version = "0.5.11" @@ -136,9 +185,12 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.0.79" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "305fe645edc1442a0fa8b6726ba61d422798d37a52e12eaecf4b022ebbb88f01" +dependencies = [ + "libc", +] [[package]] name = "cfg-if" @@ -148,13 +200,13 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.23" +version = "0.4.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" +checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" dependencies = [ + "android-tzdata", "iana-time-zone", "js-sys", - "num-integer", "num-traits", "time 0.1.45", "wasm-bindgen", @@ -165,17 +217,21 @@ dependencies = [ name = "chronos" version = "0.1.0" dependencies = [ - "anyhow", + "criterion", +] + +[[package]] +name = "chronos_bin" +version = "0.1.0" +dependencies = [ "async-trait", "chrono", - "clap 4.1.4", + "clap 4.3.21", "clippy", - "criterion", "deadpool-postgres", "dotenvy", "env_logger", "futures", - "hdrhistogram", "log", "rdkafka", "refinery", @@ -187,6 +243,20 @@ dependencies = [ "uuid", ] +[[package]] +name = "chronos_examples" +version = "0.1.0" +dependencies = [ + "async-trait", + "chronos_bin", + "dotenvy", + "env_logger", + "log", + "refinery", + "tokio", + "tokio-postgres", +] + [[package]] name = "ciborium" version = "0.2.0" @@ -220,38 +290,45 @@ version = "3.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" dependencies = [ - "bitflags", + "bitflags 1.3.2", "clap_lex 0.2.4", - "indexmap", + "indexmap 1.9.2", "textwrap", ] [[package]] name = "clap" -version = "4.1.4" +version = "4.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76" +checksum = "c27cdf28c0f604ba3f512b0c9a409f8de8513e4816705deb0498b627e7c3a3fd" dependencies = [ - "bitflags", + "clap_builder", "clap_derive", - "clap_lex 0.3.1", - "is-terminal", "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08a9f1ab5e9f01a9b81f202e8562eb9a10de70abf9eaeac1be465c28b75aa4aa" +dependencies = [ + "anstream", + "anstyle", + "clap_lex 0.5.0", "strsim", - "termcolor", ] [[package]] name = "clap_derive" -version = "4.1.0" +version = "4.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8" +checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" dependencies = [ "heck", - "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 2.0.28", ] [[package]] @@ -265,12 +342,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.3.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "783fe232adfca04f90f56201b26d79682d4cd2625e0bc7290b95123afe558ade" -dependencies = [ - "os_str_bytes", -] +checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" [[package]] name = "clippy" @@ -282,14 +356,10 @@ dependencies = [ ] [[package]] -name = "codespan-reporting" -version = "0.11.1" +name = "colorchoice" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" -dependencies = [ - "termcolor", - "unicode-width", -] +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "constant_time_eq" @@ -299,9 +369,9 @@ checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" [[package]] name = "core-foundation-sys" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] name = "cpufeatures" @@ -312,15 +382,6 @@ 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 = "criterion" version = "0.4.0" @@ -417,51 +478,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" dependencies = [ "quote", - "syn", -] - -[[package]] -name = "cxx" -version = "1.0.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d3488e7665a7a483b57e25bdd90d0aeb2bc7608c8d0346acf2ad3f1caf1d62" -dependencies = [ - "cc", - "cxxbridge-flags", - "cxxbridge-macro", - "link-cplusplus", -] - -[[package]] -name = "cxx-build" -version = "1.0.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48fcaf066a053a41a81dfb14d57d99738b767febb8b735c3016e469fac5da690" -dependencies = [ - "cc", - "codespan-reporting", - "once_cell", - "proc-macro2", - "quote", - "scratch", - "syn", -] - -[[package]] -name = "cxxbridge-flags" -version = "1.0.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2ef98b8b717a829ca5603af80e1f9e2e48013ab227b68ef37872ef84ee479bf" - -[[package]] -name = "cxxbridge-macro" -version = "1.0.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "086c685979a698443656e5cf7856c95c642295a38599f12fb1ff76fb28d19892" -dependencies = [ - "proc-macro2", - "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -522,9 +539,9 @@ dependencies = [ [[package]] name = "dotenvy" -version = "0.15.6" +version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03d8c417d7a8cb362e0c37e5d815f5eb7c37f79ff93707329d5a194e42e54ca0" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" [[package]] name = "duct" @@ -557,24 +574,30 @@ dependencies = [ "termcolor", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "erased-serde" -version = "0.3.25" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f2b0c2380453a92ea8b6c8e5f64ecaafccddde8ceab55ff7a8ac1029f894569" +checksum = "da96524cc884f6558f1769b6c46686af2fe8e8b4cd253bd5a3cdba8181b8e070" dependencies = [ "serde", ] [[package]] name = "errno" -version = "0.2.8" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" dependencies = [ "errno-dragonfly", "libc", - "winapi", + "windows-sys 0.48.0", ] [[package]] @@ -593,16 +616,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" -[[package]] -name = "flate2" -version = "1.0.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" -dependencies = [ - "crc32fast", - "miniz_oxide", -] - [[package]] name = "form_urlencoded" version = "1.1.0" @@ -614,9 +627,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.26" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e2792b0ff0340399d58445b88fd9770e3489eff258a4cbc1523418f12abf84" +checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" dependencies = [ "futures-channel", "futures-core", @@ -629,9 +642,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.26" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ "futures-core", "futures-sink", @@ -639,15 +652,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.26" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" [[package]] name = "futures-executor" -version = "0.3.26" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e" +checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" dependencies = [ "futures-core", "futures-task", @@ -656,38 +669,38 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.26" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" [[package]] name = "futures-macro" -version = "0.3.26" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.28", ] [[package]] name = "futures-sink" -version = "0.3.26" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" [[package]] name = "futures-task" -version = "0.3.26" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" [[package]] name = "futures-util" -version = "0.3.26" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ "futures-channel", "futures-core", @@ -746,18 +759,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] -name = "hdrhistogram" -version = "7.5.2" +name = "hashbrown" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f19b9f54f7c7f55e31401bb647626ce0cf0f67b0004982ce815b3ee72a02aa8" -dependencies = [ - "base64", - "byteorder", - "crossbeam-channel", - "flate2", - "nom", - "num-traits", -] +checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" [[package]] name = "heck" @@ -785,9 +790,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" [[package]] name = "hmac" @@ -806,26 +811,25 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "iana-time-zone" -version = "0.1.53" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "winapi", + "windows", ] [[package]] name = "iana-time-zone-haiku" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" dependencies = [ - "cxx", - "cxx-build", + "cc", ] [[package]] @@ -845,29 +849,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", ] [[package]] -name = "io-lifetimes" -version = "1.0.5" +name = "indexmap" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" +checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" dependencies = [ - "libc", - "windows-sys 0.45.0", + "equivalent", + "hashbrown 0.14.0", ] [[package]] name = "is-terminal" -version = "0.4.3" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e18b0a45d56fe973d6db23972bf5bc46f988a4a2385deac9cc29572f09daef" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ - "hermit-abi 0.3.1", - "io-lifetimes", + "hermit-abi 0.3.2", "rustix", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -902,15 +905,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.139" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libz-sys" -version = "1.1.8" +version = "1.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf" +checksum = "d97137b25e321a73eef1418d1d5d2eda4d77e12813f8e6dead84bc52c5870a7b" dependencies = [ "cc", "libc", @@ -918,20 +921,11 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "link-cplusplus" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" -dependencies = [ - "cc", -] - [[package]] name = "linux-raw-sys" -version = "0.1.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" +checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" [[package]] name = "lock_api" @@ -979,18 +973,13 @@ dependencies = [ ] [[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - -[[package]] -name = "miniz_oxide" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +name = "migrations" +version = "0.1.0" dependencies = [ - "adler", + "async-trait", + "refinery", + "tokio", + "tokio-postgres", ] [[package]] @@ -1005,35 +994,6 @@ dependencies = [ "windows-sys 0.42.0", ] -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - -[[package]] -name = "nom8" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8" -dependencies = [ - "memchr", -] - -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.15" @@ -1055,23 +1015,23 @@ dependencies = [ [[package]] name = "num_enum" -version = "0.5.9" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d829733185c1ca374f17e52b762f24f535ec625d2cc1f070e34c8a9068f341b" +checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9" dependencies = [ "num_enum_derive", ] [[package]] name = "num_enum_derive" -version = "0.5.9" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2be1598bf1c313dcdd12092e3f1920f463462525a21b7b4e11b4168353d0123e" +checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799" dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -1088,9 +1048,9 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" [[package]] name = "openssl-sys" -version = "0.9.87" +version = "0.9.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e17f59264b2809d77ae94f0e1ebabc434773f370d6ca667bd223ea10e06cc7e" +checksum = "866b5f16f90776b9bb8dc1e1802ac6f0513de3a7a7465867bfbc563dc737faac" dependencies = [ "cc", "libc", @@ -1175,9 +1135,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "plotters" @@ -1248,52 +1208,28 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro-crate" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66618389e4ec1c7afe67d51a9bf34ff9236480f8d51e7489b7d5ab0303c13f34" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" dependencies = [ "once_cell", "toml_edit", ] -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" dependencies = [ "proc-macro2", ] @@ -1370,9 +1306,9 @@ dependencies = [ [[package]] name = "rdkafka-sys" -version = "4.3.0+1.9.2" +version = "4.5.0+1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d222a401698c7f2010e3967353eae566d9934dcda49c29910da922414ab4e3f4" +checksum = "1bb0676c2112342ac7165decdedbc4e7086c0af384479ccce534546b10687a5d" dependencies = [ "libc", "libz-sys", @@ -1394,7 +1330,7 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -1450,7 +1386,7 @@ dependencies = [ "quote", "refinery-core", "regex", - "syn", + "syn 1.0.107", ] [[package]] @@ -1490,16 +1426,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.36.8" +version = "0.38.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644" +checksum = "172891ebdceb05aa0005f533a6cbfca599ddd7d966f6f5d4d9b2e70478e70399" dependencies = [ - "bitflags", + "bitflags 2.3.3", "errno", - "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -1535,37 +1470,31 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -[[package]] -name = "scratch" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" - [[package]] name = "serde" -version = "1.0.152" +version = "1.0.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.152" +version = "1.0.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.28", ] [[package]] name = "serde_fmt" -version = "1.0.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2963a69a2b3918c1dc75a45a18bd3fcd1120e31d3f59deb1b2f9b5d5ffb8baa4" +checksum = "e1d4ddca14104cd60529e8c7f7ba71a2c8acd8f7f5cfcdc2faf97eeb7c3010a4" dependencies = [ "serde", ] @@ -1684,6 +1613,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "term" version = "0.5.2" @@ -1727,7 +1667,7 @@ checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -1821,7 +1761,7 @@ checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -1873,19 +1813,19 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.5.1" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4553f467ac8e3d374bc9a177a26801e5d0f9b211aa1673fb137a403afd1c9cf5" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" [[package]] name = "toml_edit" -version = "0.18.1" +version = "0.19.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56c59d8dd7d0dcbc6428bf7aa2f0e823e26e43b3c9aca15bbc9475d23e5fa12b" +checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a" dependencies = [ - "indexmap", - "nom8", + "indexmap 2.0.0", "toml_datetime", + "winnow", ] [[package]] @@ -1935,12 +1875,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-width" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" - [[package]] name = "url" version = "2.3.1" @@ -1952,11 +1886,17 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "uuid" -version = "1.3.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" +checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" dependencies = [ "getrandom 0.2.8", "rand", @@ -1965,13 +1905,13 @@ dependencies = [ [[package]] name = "uuid-macro-internal" -version = "1.3.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1b300a878652a387d2a0de915bdae8f1a548f0c6d45e072fe2688794b656cc9" +checksum = "f7e1ba1f333bd65ce3c9f27de592fcbc256dafe3af2717f56d7c87761fbaccf4" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.28", ] [[package]] @@ -2050,7 +1990,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.107", "wasm-bindgen-shared", ] @@ -2072,7 +2012,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2124,6 +2064,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets 0.48.1", +] + [[package]] name = "windows-sys" version = "0.42.0" @@ -2154,7 +2103,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets 0.48.0", + "windows-targets 0.48.1", ] [[package]] @@ -2174,9 +2123,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.48.0" +version = "0.48.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" dependencies = [ "windows_aarch64_gnullvm 0.48.0", "windows_aarch64_msvc 0.48.0", @@ -2270,3 +2219,12 @@ name = "windows_x86_64_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + +[[package]] +name = "winnow" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acaaa1190073b2b101e15083c38ee8ec891b5e05cbee516521e94ec008f61e64" +dependencies = [ + "memchr", +] diff --git a/Cargo.toml b/Cargo.toml index 049b89a..d9b5c09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,19 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[dependencies] +[workspace] +members = [ + # chronos binary + "chronos_bin", + # migrations binary + "migrations", + #example binaries + 'examples/*' +] + +[workspace.dependencies] + +# [dependencies] #logging env_logger = "0.10.0" log = { version = "0.4", features = [ "kv_unstable", "std", "kv_unstable_serde" ] } @@ -22,7 +34,6 @@ tokio = { version = "1", features = ["full"] } serde = { version = "1.0.152", features = ["derive"] } serde_json = "1.0.93" -# postgres = {version="0.19.4",features=["with-chrono-0_4","with-serde_json-1","with-uuid-1"] } tokio-postgres = {version="0.7.7", features=["with-chrono-0_4","with-serde_json-1","with-uuid-1"] } rdkafka = { version = "0.29.0", features = ["sasl"] } clap = { version = "4.1.4", features = ["derive"] } @@ -34,7 +45,6 @@ uuid = { version="1.3.0", features = [ ] } dotenvy = "0.15" clippy = "0.0.302" -hdrhistogram = "7.5.2" deadpool-postgres = "0.10" refinery = { version = "0.8.7", features = ["tokio-postgres"] } thiserror = "1.0.31" diff --git a/Dockerfile.chronos b/Dockerfile.chronos new file mode 100644 index 0000000..de08698 --- /dev/null +++ b/Dockerfile.chronos @@ -0,0 +1,36 @@ +FROM rust:1.66.0-buster AS BUILD +# Install software +RUN update-ca-certificates && apt-get update && apt-get install -y libsasl2-dev +# Create appuser +ENV USER=chronos +ENV UID=1000 +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/nonexistent" \ + --shell "/sbin/nologin" \ + --no-create-home \ + --uid "${UID}" \ + "${USER}" + +WORKDIR /tmp +COPY ./ . +# Build binary in release mode +RUN cargo build -p chronos_bin --release + +# +# Run image based on buster-slim to reduce image size while still using glibc +# +FROM debian:buster-slim AS RUN +# SASL supports +RUN apt-get update && apt-get install -y libsasl2-dev +WORKDIR /opt/build +# Import users from build +COPY --from=BUILD /etc/passwd /etc/passwd +COPY --from=BUILD /etc/group /etc/group +# Copy binary from build +COPY --from=BUILD /tmp/target/release/chronos ./ +# Use an unprivileged user +USER ${USER}:${USER} +# Entry point +CMD ["/opt/build/chronos"] diff --git a/Dockerfile.chronos-pg-migrations b/Dockerfile.chronos-pg-migrations new file mode 100644 index 0000000..534bcf8 --- /dev/null +++ b/Dockerfile.chronos-pg-migrations @@ -0,0 +1,36 @@ +FROM rust:1.66.0-buster AS BUILD +# Install software +RUN update-ca-certificates && apt-get update && apt-get install -y libsasl2-dev +# Create appuser +ENV USER=chronos +ENV UID=1000 +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/nonexistent" \ + --shell "/sbin/nologin" \ + --no-create-home \ + --uid "${UID}" \ + "${USER}" + +WORKDIR /tmp +COPY ./ . +# Build binary in release mode +RUN cargo build -p chronos_bin --release + +# +# Run image based on buster-slim to reduce image size while still using glibc +# +FROM debian:buster-slim AS RUN +# SASL supports +RUN apt-get update && apt-get install -y libsasl2-dev +WORKDIR /opt/build +# Import users from build +COPY --from=BUILD /etc/passwd /etc/passwd +COPY --from=BUILD /etc/group /etc/group +# Copy binary from build +COPY --from=BUILD /tmp/target/release/chronos-pg-migrations ./ +# Use an unprivileged user +USER ${USER}:${USER} +# Entry point +CMD ["/opt/build/chronos-pg-migrations"] diff --git a/benches/consumer_bench.rs b/benches/consumer_bench.rs index 0cb0856..a794765 100644 --- a/benches/consumer_bench.rs +++ b/benches/consumer_bench.rs @@ -1,5 +1,5 @@ #![allow(unused)] -use chronos::runner::Runner; +use chronos_bin::runner::Runner; // use criterion::{black_box, criterion_group, criterion_main, Criterion}; // // use hello_cargo::fibonacci; // diff --git a/chronos_bin/Cargo.toml b/chronos_bin/Cargo.toml new file mode 100644 index 0000000..2de2c20 --- /dev/null +++ b/chronos_bin/Cargo.toml @@ -0,0 +1,40 @@ +[package] +name = "chronos_bin" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +#tokio and async +tokio= {workspace = true} +async-trait.workspace = true +futures.workspace = true + +#postgres +tokio-postgres.workspace = true +deadpool-postgres.workspace = true + +#migration +refinery.workspace = true + +#kafka +rdkafka.workspace = true + +# serialise-deserialise +serde.workspace = true +serde_json.workspace = true + +#exception-handling +thiserror.workspace = true + +#config +clippy.workspace = true +env_logger.workspace = true +log.workspace = true +clap.workspace = true +chrono.workspace = true +uuid.workspace = true +dotenvy.workspace = true + diff --git a/chronos_bin/src/bin/chronos.rs b/chronos_bin/src/bin/chronos.rs new file mode 100644 index 0000000..8d0d390 --- /dev/null +++ b/chronos_bin/src/bin/chronos.rs @@ -0,0 +1,31 @@ +use chronos_bin::kafka::config::KafkaConfig; +use chronos_bin::kafka::consumer::KafkaConsumer; +use chronos_bin::kafka::producer::KafkaProducer; +use chronos_bin::postgres::config::PgConfig; +use chronos_bin::postgres::pg::Pg; +use chronos_bin::runner::Runner; +use log::debug; +use std::sync::Arc; + +#[tokio::main] +async fn main() { + env_logger::init(); + dotenvy::dotenv().ok(); + + let kafka_config = KafkaConfig::from_env(); + let pg_config = PgConfig::from_env(); + + let kafka_consumer = KafkaConsumer::new(&kafka_config); + let kafka_producer = KafkaProducer::new(&kafka_config); + let data_store = Pg::new(pg_config).await.unwrap(); + + let r = Runner { + data_store: Arc::new(Box::new(data_store)), + producer: Arc::new(Box::new(kafka_producer)), + consumer: Arc::new(Box::new(kafka_consumer)), + }; + + debug!("debug logs starting chronos"); + + r.run().await; +} diff --git a/src/core.rs b/chronos_bin/src/core.rs similarity index 100% rename from src/core.rs rename to chronos_bin/src/core.rs diff --git a/src/kafka/config.rs b/chronos_bin/src/kafka/config.rs similarity index 100% rename from src/kafka/config.rs rename to chronos_bin/src/kafka/config.rs diff --git a/src/kafka/consumer.rs b/chronos_bin/src/kafka/consumer.rs similarity index 100% rename from src/kafka/consumer.rs rename to chronos_bin/src/kafka/consumer.rs diff --git a/src/kafka/errors.rs b/chronos_bin/src/kafka/errors.rs similarity index 100% rename from src/kafka/errors.rs rename to chronos_bin/src/kafka/errors.rs diff --git a/src/kafka/kafka_deploy.rs b/chronos_bin/src/kafka/kafka_deploy.rs similarity index 100% rename from src/kafka/kafka_deploy.rs rename to chronos_bin/src/kafka/kafka_deploy.rs diff --git a/src/kafka/mod.rs b/chronos_bin/src/kafka/mod.rs similarity index 83% rename from src/kafka/mod.rs rename to chronos_bin/src/kafka/mod.rs index f296215..2f7e54f 100644 --- a/src/kafka/mod.rs +++ b/chronos_bin/src/kafka/mod.rs @@ -3,4 +3,3 @@ pub mod consumer; pub mod errors; pub mod kafka_deploy; pub mod producer; -// pub mod utils; diff --git a/src/kafka/producer.rs b/chronos_bin/src/kafka/producer.rs similarity index 100% rename from src/kafka/producer.rs rename to chronos_bin/src/kafka/producer.rs diff --git a/src/kafka/utils.rs b/chronos_bin/src/kafka/utils.rs similarity index 100% rename from src/kafka/utils.rs rename to chronos_bin/src/kafka/utils.rs diff --git a/src/lib.rs b/chronos_bin/src/lib.rs similarity index 70% rename from src/lib.rs rename to chronos_bin/src/lib.rs index 070d0d9..47bff38 100644 --- a/src/lib.rs +++ b/chronos_bin/src/lib.rs @@ -3,9 +3,7 @@ pub mod core; mod message_processor; mod message_receiver; mod monitor; -// pub mod pg_client; -// pub mod persistence_store; -// pub mod producer; + pub mod runner; // utils @@ -13,4 +11,3 @@ pub mod utils; // Infra pub mod kafka; pub mod postgres; - diff --git a/src/message_processor.rs b/chronos_bin/src/message_processor.rs similarity index 100% rename from src/message_processor.rs rename to chronos_bin/src/message_processor.rs diff --git a/src/message_receiver.rs b/chronos_bin/src/message_receiver.rs similarity index 100% rename from src/message_receiver.rs rename to chronos_bin/src/message_receiver.rs diff --git a/src/monitor.rs b/chronos_bin/src/monitor.rs similarity index 100% rename from src/monitor.rs rename to chronos_bin/src/monitor.rs diff --git a/src/persistence_store.rs b/chronos_bin/src/persistence_store.rs similarity index 100% rename from src/persistence_store.rs rename to chronos_bin/src/persistence_store.rs diff --git a/src/postgres/config.rs b/chronos_bin/src/postgres/config.rs similarity index 100% rename from src/postgres/config.rs rename to chronos_bin/src/postgres/config.rs diff --git a/src/postgres/errors.rs b/chronos_bin/src/postgres/errors.rs similarity index 100% rename from src/postgres/errors.rs rename to chronos_bin/src/postgres/errors.rs diff --git a/src/postgres/mod.rs b/chronos_bin/src/postgres/mod.rs similarity index 100% rename from src/postgres/mod.rs rename to chronos_bin/src/postgres/mod.rs diff --git a/src/postgres/pg.rs b/chronos_bin/src/postgres/pg.rs similarity index 100% rename from src/postgres/pg.rs rename to chronos_bin/src/postgres/pg.rs diff --git a/src/postgres/pg_deploy.rs b/chronos_bin/src/postgres/pg_deploy.rs similarity index 100% rename from src/postgres/pg_deploy.rs rename to chronos_bin/src/postgres/pg_deploy.rs diff --git a/src/postgres/utils.rs b/chronos_bin/src/postgres/utils.rs similarity index 100% rename from src/postgres/utils.rs rename to chronos_bin/src/postgres/utils.rs diff --git a/src/runner.rs b/chronos_bin/src/runner.rs similarity index 100% rename from src/runner.rs rename to chronos_bin/src/runner.rs diff --git a/src/utils/env.rs b/chronos_bin/src/utils/env.rs similarity index 100% rename from src/utils/env.rs rename to chronos_bin/src/utils/env.rs diff --git a/src/utils/mod.rs b/chronos_bin/src/utils/mod.rs similarity index 100% rename from src/utils/mod.rs rename to chronos_bin/src/utils/mod.rs diff --git a/src/utils/util.rs b/chronos_bin/src/utils/util.rs similarity index 100% rename from src/utils/util.rs rename to chronos_bin/src/utils/util.rs diff --git a/examples/chronos_bin/Cargo.toml b/examples/chronos_bin/Cargo.toml new file mode 100644 index 0000000..35a94dc --- /dev/null +++ b/examples/chronos_bin/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "chronos_examples" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +# tokio and async +tokio.workspace = true +async-trait.workspace = true + +# postgres +tokio-postgres.workspace = true + +# Migration +refinery.workspace = true + +#logging +env_logger.workspace = true +log.workspace = true + +#confi +dotenvy.workspace = true + +chronos_bin = { path="../../chronos_bin" } diff --git a/examples/chronos_bin/examples/chronos_binary.rs b/examples/chronos_bin/examples/chronos_binary.rs new file mode 100644 index 0000000..9b47dbd --- /dev/null +++ b/examples/chronos_bin/examples/chronos_binary.rs @@ -0,0 +1,34 @@ +use chronos_bin::kafka::config::KafkaConfig; +use chronos_bin::kafka::consumer::KafkaConsumer; +use chronos_bin::kafka::producer::KafkaProducer; +use chronos_bin::postgres::config::PgConfig; +use chronos_bin::postgres::pg::Pg; +use chronos_bin::runner::Runner; +use log::debug; +use std::sync::Arc; + +#[tokio::main] +async fn main() { + env_logger::init(); + match dotenvy::dotenv() { + Ok(path) => println!(".env read successfully from {}", path.display()), + Err(e) => println!("Could not load .env file: {e}"), + }; + + let kafka_config = KafkaConfig::from_env(); + let pg_config = PgConfig::from_env(); + + let kafka_consumer = KafkaConsumer::new(&kafka_config); + let kafka_producer = KafkaProducer::new(&kafka_config); + let data_store = Pg::new(pg_config).await.unwrap(); + + let r = Runner { + data_store: Arc::new(Box::new(data_store)), + producer: Arc::new(Box::new(kafka_producer)), + consumer: Arc::new(Box::new(kafka_consumer)), + }; + + debug!("debug logs starting chronos using example"); + + r.run().await; +} diff --git a/examples/chronos_binary.rs b/examples/chronos_binary.rs deleted file mode 100644 index e1cc03a..0000000 --- a/examples/chronos_binary.rs +++ /dev/null @@ -1,81 +0,0 @@ -use std::sync::Arc; -use chronos::runner::Runner; -use env_logger::Env; -use log::{debug, error, info, warn}; -use chronos::postgres::pg::Pg; -use chronos::kafka::producer::KafkaProducer; -use chronos::kafka::consumer::KafkaConsumer; -use chronos::kafka::config::KafkaConfig; -use chronos::postgres::config::PgConfig; - -#[tokio::main] -async fn main() { - env_logger::init(); - match dotenvy::dotenv() { - Ok(path) => println!(".env read successfully from {}", path.display()), - Err(e) => println!("Could not load .env file: {e}"), - }; - - let kafka_config = KafkaConfig::from_env(); - let pg_config = PgConfig::from_env(); - - let kafka_consumer = KafkaConsumer::new(&kafka_config); - let kafka_producer = KafkaProducer::new(&kafka_config); - let data_store=Pg::new(pg_config).await.unwrap(); - - - - let r = Runner { - data_store: Arc::new(Box::new(data_store)), - producer: Arc::new(Box::new(kafka_producer)), - consumer: Arc::new(Box::new(kafka_consumer)) - }; - - debug!("debug logs starting chronos"); - - - r.run().await; -} - -// struct MyDataStore { -// data: Vec, -// } -// -// impl DataStore for MyDataStore { -// async fn insert( -// &self, -// message: ChronosDeliveryMessage, -// ) -> Result { -// todo!() -// } -// -// async fn delete( -// &self, -// message: ChronosDeliveryMessage, -// ) -> Result { -// todo!() -// } -// -// async fn move_to_initial_state( -// &self, -// message: ChronosDeliveryMessage, -// ) -> Result { -// todo!() -// } -// -// async fn move_to_ready_state( -// &self, -// message: ChronosDeliveryMessage, -// ) -> Result { -// todo!() -// } -// -// async fn get_messages( -// &self, -// status: ChronosMessageStatus, -// date_time: Option>, -// limit: Option, -// ) -> Result, ChronosError> { -// todo!() -// } -// } diff --git a/migrations/Cargo.lock b/migrations/Cargo.lock new file mode 100644 index 0000000..574d727 --- /dev/null +++ b/migrations/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "migrations" +version = "0.1.0" diff --git a/migrations/Cargo.toml b/migrations/Cargo.toml new file mode 100644 index 0000000..ab82d0d --- /dev/null +++ b/migrations/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "migrations" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +# tokio and async +tokio = { workspace = true } +async-trait = { workspace = true } + +# postgres +tokio-postgres = { workspace = true } + +# Migration +refinery = { workspace=true } + +# chronos= { path="../packages/chronos_bin" } diff --git a/migrations/migrations/V1__initial.sql b/migrations/migrations/V1__initial.sql new file mode 100644 index 0000000..f28959b --- /dev/null +++ b/migrations/migrations/V1__initial.sql @@ -0,0 +1,10 @@ +CREATE TABLE IF NOT EXISTS hanger ( + id varchar NOT NULL, + deadline timestamptz NOT NULL DEFAULT now(), + readied_at timestamptz, + readied_by uuid, + message_headers jsonb, + message_key varchar, + message_value json, + PRIMARY KEY ("id") +) \ No newline at end of file diff --git a/migrations/migrations/V2__index.sql b/migrations/migrations/V2__index.sql new file mode 100644 index 0000000..cc68d0d --- /dev/null +++ b/migrations/migrations/V2__index.sql @@ -0,0 +1 @@ +create index idx_hanger_deadline on hanger(deadline) \ No newline at end of file diff --git a/migrations/src/bin/chronos-pg-migrations.rs b/migrations/src/bin/chronos-pg-migrations.rs new file mode 100644 index 0000000..28a5478 --- /dev/null +++ b/migrations/src/bin/chronos-pg-migrations.rs @@ -0,0 +1,27 @@ +use migrations::config::PgConfig; +mod embedded { + use refinery::embed_migrations; + embed_migrations!("migrations"); +} + +#[tokio::main] +async fn main() -> Result<(), Box> { + let pg_config = PgConfig::new(); + + println!("Running DB migrations..."); + let (mut client, con) = tokio_postgres::connect(pg_config.get_database_connection_string().as_str(), tokio_postgres::NoTls).await?; + + tokio::spawn(async move { + if let Err(e) = con.await { + eprintln!("connection error: {}", e); + } + }); + + let migration_report = embedded::migrations::runner().run_async(&mut client).await?; + for migration in migration_report.applied_migrations() { + println!("Migration Applied - Name: {}, Version: {}", migration.name(), migration.version()); + } + println!("DB migrations finished!"); + + Ok(()) +} diff --git a/migrations/src/config.rs b/migrations/src/config.rs new file mode 100644 index 0000000..7b38c0a --- /dev/null +++ b/migrations/src/config.rs @@ -0,0 +1,39 @@ +use std::env; + +pub struct PgConfig { + pub user: String, + pub password: String, + pub host: String, + pub port: String, + pub database: String, +} + +impl PgConfig { + pub fn new() -> Self { + PgConfig { + user: env::var("PG_USER").expect("$PG_USER not set"), + password: env::var("PG_PASSWORD").expect("$PG_PASSWORD not set"), + host: env::var("PG_HOST").expect("$PG_HOST not set"), + port: env::var("PG_PORT").expect("$PG_PORT not set"), + database: env::var("PG_DATABASE").expect("$PG_DATABASE not set"), + } + } + + pub fn get_base_connection_string(&self) -> String { + let PgConfig { + user, password, host, port, .. + } = self; + format!("postgres://{user}:{password}@{host}:{port}") + } + + pub fn get_database_connection_string(&self) -> String { + let PgConfig { database, .. } = self; + let base_connection_string = self.get_base_connection_string(); + format!("{base_connection_string}/{database}") + } +} +impl Default for PgConfig { + fn default() -> Self { + Self::new() + } +} diff --git a/migrations/src/lib.rs b/migrations/src/lib.rs new file mode 100644 index 0000000..ef68c36 --- /dev/null +++ b/migrations/src/lib.rs @@ -0,0 +1 @@ +pub mod config; diff --git a/scripts/pre-commit-checks.sh b/scripts/pre-commit-checks.sh new file mode 100644 index 0000000..4b7d15c --- /dev/null +++ b/scripts/pre-commit-checks.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e + +make withenv RECIPE=lint +make withenv RECIPE=test.unit + +