-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move secrets and metadata plugins to runtime (#1673)
* refactor: move secrets and metadata plugins to runtime * feat: impl config::Source for SecretStore * ci: skip crates * fix lock * Revert "feat: impl config::Source for SecretStore" This reverts commit 7442c24. * fix docs * fix: deprecation warnings * bump examples * fix * fix serenity * nit * bump examples * fix serenity * fix rocket doc test * bump examples * bump examples
- Loading branch information
Showing
28 changed files
with
211 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule examples
updated
50 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,3 @@ | ||
# Shuttle Metadata | ||
|
||
This plugin allows applications to obtain certain information about their runtime environment. | ||
|
||
## Usage | ||
|
||
Add `shuttle-metadata` to the dependencies for your service. | ||
|
||
You can get this resource using the `shuttle_metadata::ShuttleMetadata` attribute to get a `Metadata`. This struct will contain information such as the Shuttle service name. | ||
|
||
```rust | ||
#[shuttle_runtime::main] | ||
async fn app( | ||
#[shuttle_metadata::ShuttleMetadata] metadata: shuttle_metadata::Metadata, | ||
) -> __ { ... } | ||
``` | ||
|
||
#### Example projects that use `shuttle-metadata` | ||
|
||
| Framework | Link | | ||
| --------- | -------------------------------------------------------------------------------------- | | ||
| Axum | [axum example](https://github.com/shuttle-hq/shuttle-examples/tree/main/axum/metadata) | | ||
This plugin has been moved to [shuttle-runtime](https://crates.io/crates/shuttle-runtime). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,3 @@ | ||
# Shuttle Secrets | ||
|
||
This plugin manages secrets on [Shuttle](https://www.shuttle.rs). | ||
|
||
## Usage | ||
|
||
Add `shuttle-secrets` to the dependencies for your service, and add a `Secrets.toml` to the root of your project | ||
with the secrets you'd like to store. Make sure to add `Secrets*.toml` to a `.gitignore` to omit your secrets from version control. | ||
|
||
Next, pass `#[shuttle_secrets::Secrets] secret_store: SecretStore` as an argument to your `shuttle_service::main` function. | ||
`SecretStore::get` can now be called to retrieve your API keys and other secrets at runtime. | ||
|
||
## Example | ||
|
||
```rust,ignore | ||
#[shuttle_runtime::main] | ||
async fn rocket( | ||
#[shuttle_secrets::Secrets] secret_store: SecretStore, | ||
) -> ShuttleRocket { | ||
// get secret defined in `Secrets.toml` file. | ||
let secret = if let Some(secret) = secret_store.get("MY_API_KEY") { | ||
secret | ||
} else { | ||
return Err(anyhow!("secret was not found").into()); | ||
}; | ||
let state = MyState { secret }; | ||
let rocket = rocket::build().mount("/", routes![secret]).manage(state); | ||
Ok(rocket.into()) | ||
} | ||
``` | ||
This plugin has been moved to [shuttle-runtime](https://crates.io/crates/shuttle-runtime). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,93 @@ | ||
# shuttle-runtime | ||
# Shuttle - Deploy Rust apps with a single Cargo subcommand | ||
|
||
[Shuttle](https://www.shuttle.rs/) is a Rust-native cloud development platform that lets you deploy your Rust apps for free. | ||
|
||
Shuttle is built for productivity, reliability and performance: | ||
<div style="display: flex; margin-top: 30px; margin-bottom: 30px;"> | ||
<img src="https://raw.githubusercontent.com/shuttle-hq/shuttle/main/assets/logo-rectangle-transparent.png" width="400px" style="margin-left: auto; margin-right: auto;"/> | ||
</div> | ||
|
||
- Zero-Configuration support for Rust using annotations | ||
- Automatic resource provisioning (databases, caches, subdomains, etc.) via [Infrastructure-From-Code](https://www.shuttle.rs/blog/2022/05/09/ifc) | ||
- First-class support for popular Rust frameworks ([Actix Web](https://docs.shuttle.rs/examples/actix), [Rocket](https://docs.shuttle.rs/examples/rocket), [Axum](https://docs.shuttle.rs/examples/axum), and [more](https://docs.shuttle.rs/examples/other)) | ||
- Support for deploying Discord bots using [Serenity](https://docs.shuttle.rs/examples/serenity) | ||
- Scalable hosting (with optional self-hosting in the future) | ||
[Shuttle](https://www.shuttle.rs/) is a Rust-native cloud development platform that lets you deploy your Rust apps for free. | ||
|
||
📖 Check out our documentation to get started quickly: [docs.shuttle.rs](https://docs.shuttle.rs) | ||
|
||
🙋♂️ If you have any questions, join our [Discord](https://discord.gg/shuttle) server. | ||
|
||
## Usage | ||
|
||
Start by installing the [`cargo shuttle`](https://docs.rs/crate/cargo-shuttle/latest) subcommand by running the following in a terminal: | ||
|
||
```bash | ||
cargo install cargo-shuttle | ||
``` | ||
|
||
Now that Shuttle is installed, you can initialize a project with Axum boilerplate: | ||
|
||
```bash | ||
cargo shuttle init --template axum my-axum-app | ||
``` | ||
|
||
By looking at the `Cargo.toml` file of the generated `my-axum-app` project you will see it has been made to | ||
be a binary crate with a few dependencies including `shuttle-runtime` and `shuttle-axum`. | ||
|
||
```toml | ||
axum = "0.7.3" | ||
shuttle-axum = "0.41.0" | ||
shuttle-runtime = "0.41.0" | ||
tokio = "1.28.2" | ||
``` | ||
|
||
A boilerplate code for your axum project can also be found in `src/main.rs`: | ||
|
||
```rust,no_run | ||
use axum::{routing::get, Router}; | ||
async fn hello_world() -> &'static str { | ||
"Hello, world!" | ||
} | ||
#[shuttle_runtime::main] | ||
async fn main() -> shuttle_axum::ShuttleAxum { | ||
let router = Router::new().route("/", get(hello_world)); | ||
Ok(router.into()) | ||
} | ||
``` | ||
|
||
Check out [our docs](https://docs.shuttle.rs/introduction/welcome) to see all the frameworks we support, or | ||
our [examples](https://github.com/shuttle-hq/shuttle-examples) if you prefer that format. | ||
|
||
## Running locally | ||
|
||
To test your app locally before deploying, use: | ||
|
||
```bash | ||
cargo shuttle run | ||
``` | ||
|
||
You should see your app build and start on the default port 8000. You can test this using; | ||
|
||
```bash | ||
curl http://localhost:8000/ | ||
# Hello, world! | ||
``` | ||
|
||
## Deploying | ||
|
||
Before you can deploy, you have to create a project. This will start a deployer container for your | ||
project under the hood, ensuring isolation from other users' projects. PS. you don't have to do this | ||
now if you did in in the `cargo shuttle init` flow. | ||
|
||
```bash | ||
cargo shuttle project start | ||
``` | ||
|
||
Then, deploy the service with: | ||
|
||
```bash | ||
cargo shuttle deploy | ||
``` | ||
|
||
Your service will immediately be available at `https://{project_name}.shuttleapp.rs/`. For example: | ||
|
||
```bash | ||
curl https://my-axum-app.shuttleapp.rs/ | ||
# Hello, world! | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.