From 656cb2ea256b5706e19462cd1787244421fb6834 Mon Sep 17 00:00:00 2001 From: Vlad Stepanov <8uk.8ak@gmail.com> Date: Fri, 5 May 2023 20:24:15 +0400 Subject: [PATCH 1/4] add option to use rustls instead of native-tls in `shuttle-shared-db` --- resources/shared-db/Cargo.toml | 5 +++-- resources/shared-db/README.md | 10 +++++----- resources/shared-db/src/lib.rs | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/resources/shared-db/Cargo.toml b/resources/shared-db/Cargo.toml index 45d19c87a..7badfcb68 100644 --- a/resources/shared-db/Cargo.toml +++ b/resources/shared-db/Cargo.toml @@ -11,7 +11,8 @@ async-trait = "0.1.56" mongodb = { version = "2.3.0", optional = true } serde = { version = "1.0.148", features = ["derive"] } shuttle-service = { path = "../../service", version = "0.15.0", default-features = false } -sqlx = { version = "0.6.2", features = ["runtime-tokio-native-tls"], optional = true } +sqlx = { version = "0.6.2", optional = true } [features] -postgres = ["sqlx/postgres"] +postgres = ["sqlx/postgres", "sqlx/runtime-tokio-native-tls"] +postgres-rustls = ["sqlx/postgres", "sqlx/runtime-tokio-rustls"] diff --git a/resources/shared-db/README.md b/resources/shared-db/README.md index 9ec88351b..354fca468 100644 --- a/resources/shared-db/README.md +++ b/resources/shared-db/README.md @@ -4,12 +4,12 @@ This plugin manages databases that are shared with other services on [shuttle](h ## Usage -Add `shuttle-shared-db` to the dependencies for your service. Every type of shareable database is behind the following feature flag and attribute path +Add `shuttle-shared-db` to the dependencies for your service. Every type of shareable database is behind the following feature flag and attribute path (`*-rustls` uses rustls for TLS, the default uses native-tls). -| Engine | Feature flag | Attribute path | -|----------|--------------|-----------------------------| -| Postgres | postgres | shuttle_shared_db::Postgres | -| MongoDB | mongodb | shuttle_shared_db::MongoDb | +| Engine | Feature flags | Attribute path | +|----------|--------------------------------|-----------------------------| +| Postgres | `postgres` / `postgres-rustls` | shuttle_shared_db::Postgres | +| MongoDB | `mongodb` | shuttle_shared_db::MongoDb | An example using the Rocket framework can be found on [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/rocket/postgres) diff --git a/resources/shared-db/src/lib.rs b/resources/shared-db/src/lib.rs index dfc96f795..0a02e1f24 100644 --- a/resources/shared-db/src/lib.rs +++ b/resources/shared-db/src/lib.rs @@ -5,8 +5,8 @@ mod mongo; #[cfg(feature = "mongodb")] pub use mongo::MongoDb; -#[cfg(feature = "postgres")] +#[cfg(any(feature = "postgres", feature = "postgres-rustls"))] mod postgres; -#[cfg(feature = "postgres")] +#[cfg(any(feature = "postgres", feature = "postgres-rustls"))] pub use postgres::Postgres; From c6a2fb51ff8634b697315693301bbab003e467c2 Mon Sep 17 00:00:00 2001 From: Vlad Stepanov <8uk.8ak@gmail.com> Date: Fri, 5 May 2023 23:40:43 +0400 Subject: [PATCH 2/4] Update CircleCI config Allow specifying features by one for a specific crates. Test `shuttle-shared-db` features one by one. --- .circleci/config.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 94affdff5..4de680f2d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -202,6 +202,10 @@ jobs: path: description: "Path to crate external from workspace" type: string + features: + description: "Features to enable" + type: string + default: --all-features executor: docker-rust environment: CARGO_REGISTRIES_CRATES_IO_PROTOCOL: "sparse" @@ -218,13 +222,13 @@ jobs: - run: | cargo clippy --tests \ --all-targets \ - --all-features \ + << parameters.features >> \ --manifest-path << parameters.path >>/Cargo.toml \ --no-deps -- \ --D warnings \ -A clippy::let-unit-value \ -A clippy::format-push-string - - run: cargo test --all-features --manifest-path << parameters.path >>/Cargo.toml -- --nocapture + - run: cargo test << parameters.features >> --manifest-path << parameters.path >>/Cargo.toml -- --nocapture - save-cargo-cache platform-test: parameters: @@ -491,7 +495,6 @@ workflows: - resources/aws-rds - resources/persist - resources/secrets - - resources/shared-db - resources/static-folder - services/shuttle-actix-web - services/shuttle-axum @@ -505,6 +508,16 @@ workflows: - services/shuttle-tide - services/shuttle-tower - services/shuttle-warp + - check-standalone: + name: resources/shared-db + matrix: + alias: check-standalone-shared-db + parameters: + path: [resources/shared-db] + features: + - "-F mongodb" + - "-F postgres" + - "-F postgres-rustls" - platform-test: name: << matrix.crate >> requires: @@ -527,6 +540,7 @@ workflows: requires: - platform-test - check-standalone + - check-standalone-shared-db filters: branches: only: production From dc718ba104acebc51028c520a8380b5bd9caadf2 Mon Sep 17 00:00:00 2001 From: Vlad Stepanov <8uk.8ak@gmail.com> Date: Fri, 5 May 2023 23:46:05 +0400 Subject: [PATCH 3/4] more readable CI job name --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4de680f2d..ded145c95 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -509,7 +509,7 @@ workflows: - services/shuttle-tower - services/shuttle-warp - check-standalone: - name: resources/shared-db + name: "resources/shared-db: << matrix.features >>" matrix: alias: check-standalone-shared-db parameters: From 0ff99131ea89261bc1c3522a59f5ae8336f46ec9 Mon Sep 17 00:00:00 2001 From: Vlad Stepanov <8uk.8ak@gmail.com> Date: Mon, 8 May 2023 17:06:37 +0400 Subject: [PATCH 4/4] Add comment to CircleCI config --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index ded145c95..7c3851668 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -509,6 +509,8 @@ workflows: - services/shuttle-tower - services/shuttle-warp - check-standalone: + # shuttle-shared-db has mutually exclusive features + # so we run checks for each feature separately name: "resources/shared-db: << matrix.features >>" matrix: alias: check-standalone-shared-db