Repository navigation
Document the Community Toolkit RavenDB Cloud hosting integration #2287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Gracjan Sadowicz (poissoncorp)
wants to merge
2
commits into
microsoft:main
Choose a base branch
from
poissoncorp:ravendb-cloud
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+367
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
337 changes: 337 additions & 0 deletions
337
src/frontend/src/content/docs/integrations/databases/ravendb/ravendb-cloud.mdx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,337 @@ | ||
| --- | ||
| title: Deploy RavenDB to RavenDB Cloud | ||
| seoTitle: 'Deploy the Aspire RavenDB server to RavenDB Cloud' | ||
| description: Learn how the Aspire RavenDB Cloud hosting integration creates or finds a RavenDB Cloud product during aspire deploy and gives every app its node URLs and a client certificate of its own. | ||
| --- | ||
|
|
||
| import { Image } from 'astro:assets'; | ||
| import { Aside, Badge, Tabs, TabItem } from '@astrojs/starlight/components'; | ||
| import LearnMore from '@components/LearnMore.astro'; | ||
| import ravendbIcon from '@assets/icons/ravendb-icon.png'; | ||
|
|
||
| <Badge text="⭐ Community Toolkit" variant="tip" size="large" /> | ||
|
|
||
| <Image | ||
| src={ravendbIcon} | ||
| alt="RavenDB logo" | ||
| width={100} | ||
| height={100} | ||
| fit="contain" | ||
| class:list={'float-inline-left icon'} | ||
| data-zoom-off | ||
| /> | ||
|
|
||
| The Aspire RavenDB Cloud hosting integration publishes the RavenDB server resource from the [RavenDB hosting integration](../ravendb-host/) to [RavenDB Cloud](https://cloud.ravendb.net). `aspire run` keeps starting the local RavenDB container. `aspire deploy` creates or finds a RavenDB Cloud product and hands every app that references the server the product's node URLs and a client certificate of its own. | ||
|
|
||
| <Aside type="note"> | ||
| The package is a preview, so its API may still change. It supports apps | ||
| deployed with [Docker Compose](/deployment/docker-compose/) only, see [Known | ||
| limitations](#known-limitations). | ||
| </Aside> | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - **A RavenDB Cloud API key.** Create it in the RavenDB Cloud portal, see [Cloud: API](https://docs.ravendb.net/cloud/cloud-api). The key acts as the account owner on every product of the account, so keep it in a secret parameter and never in source control. Keys expire after at most 12 months. | ||
| - **A Docker Compose environment.** The apps that use the server must be deployed with Docker Compose, and `aspire deploy` must run where Docker can start them. | ||
| - **Allowed IP ranges.** RavenDB Cloud accepts connections only from a product's allowed IP ranges: the machine or CI runner that runs `aspire deploy`, and the host that runs the apps. See [Network access](#network-access). | ||
|
|
||
| ## Installation | ||
|
|
||
| Install the [📦 CommunityToolkit.Aspire.Hosting.RavenDB.Cloud](https://nuget.org/packages/CommunityToolkit.Aspire.Hosting.RavenDB.Cloud) NuGet package in the AppHost. The package ships only prerelease versions, while a `release` quality CLI and the `*` version that most package references use select only stable releases, so name a prerelease version: | ||
|
|
||
| <Tabs syncKey="aspire-lang"> | ||
| <TabItem id="typescript" label="TypeScript"> | ||
|
|
||
| ```bash title="Terminal" | ||
| aspire add CommunityToolkit.Aspire.Hosting.RavenDB.Cloud --version <prerelease-version> | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem id="csharp" label="C#"> | ||
|
|
||
| ```bash title="Terminal" | ||
| aspire add CommunityToolkit.Aspire.Hosting.RavenDB.Cloud --version <prerelease-version> | ||
| ``` | ||
|
|
||
| Or add the package manually: | ||
|
|
||
| ```xml title="AppHost.csproj" | ||
| <PackageReference Include="CommunityToolkit.Aspire.Hosting.RavenDB.Cloud" Version="<prerelease-version>" /> | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| Replace `<prerelease-version>` with the latest prerelease version listed on NuGet. A `staging` or `dev` quality CLI also finds the package without the `--version` option. For more information, see the [install script options](/reference/cli/install-script/#options). | ||
|
|
||
| <LearnMore> | ||
| Learn more about [`aspire add`](/reference/cli/commands/aspire-add/) in the | ||
| command reference. | ||
| </LearnMore> | ||
|
|
||
| ## Publish the RavenDB server to RavenDB Cloud | ||
|
|
||
| Add a Docker Compose environment and a secret parameter for the API key, then publish the RavenDB server to RavenDB Cloud with a product name and a spec: | ||
|
|
||
| <Tabs syncKey="aspire-lang"> | ||
| <TabItem id="typescript" label="TypeScript"> | ||
|
|
||
| ```typescript title="apphost.mts" | ||
| import { | ||
| createBuilder, | ||
| RavenDBCloudDiskLayout, | ||
| RavenDBCloudProvider, | ||
| RavenDBCloudStorageType, | ||
| } from './.aspire/modules/aspire.mjs'; | ||
|
|
||
| const builder = await createBuilder(); | ||
|
|
||
| await builder.addDockerComposeEnvironment('compose'); | ||
|
|
||
| const apiKey = await builder.addParameter('ravendb-cloud-api-key', { | ||
| secret: true, | ||
| }); | ||
|
|
||
| const ravendb = await builder.addRavenDB('ravendb').publishAsRavenDBCloud( | ||
| apiKey, | ||
| 'shop-production', | ||
| async (spec) => { | ||
| await spec.production( | ||
| RavenDBCloudProvider.Azure, | ||
| 'westeurope', // region | ||
| 'P20', // instance type | ||
| 128, // disk size in GB | ||
| RavenDBCloudStorageType.SsdStandard, | ||
| RavenDBCloudDiskLayout.SingleDataDisk, | ||
| // release channel | ||
| 'Stable72' | ||
| ); | ||
| }, | ||
| { | ||
| configure: async (cloud) => { | ||
| await cloud.withAllowedIps(['203.0.113.0/24']); | ||
| }, | ||
| } | ||
| ); | ||
|
|
||
| const orders = await ravendb.addDatabase('orders', { ensureCreated: true }); | ||
|
|
||
| const api = await builder.addDotnetProject('api', '../Api/Api.csproj'); | ||
| await api.withReference(orders); | ||
|
|
||
| // After adding all resources, run the app... | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem id="csharp" label="C#"> | ||
|
|
||
| ```csharp title="AppHost.cs" | ||
| using CommunityToolkit.Aspire.Hosting.RavenDB.Cloud; | ||
|
|
||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| builder.AddDockerComposeEnvironment("compose"); | ||
|
|
||
| var apiKey = builder.AddParameter("ravendb-cloud-api-key", secret: true); | ||
|
|
||
| var ravendb = builder.AddRavenDB("ravendb") | ||
| .PublishAsRavenDBCloud( | ||
| apiKey, | ||
| productName: "shop-production", | ||
| RavenDBCloudSpec.Production( | ||
| RavenDBCloudProvider.Azure, | ||
| region: "westeurope", | ||
| instanceType: "P20", | ||
| diskSizeInGb: 128, | ||
| RavenDBCloudStorageType.SsdStandard, | ||
| RavenDBCloudDiskLayout.SingleDataDisk, | ||
| releaseChannel: "Stable72"), | ||
| cloud => cloud.WithAllowedIps("203.0.113.0/24")); | ||
|
|
||
| var orders = ravendb.AddDatabase("orders", ensureCreated: true); | ||
|
|
||
| builder.AddDotnetProject("api", "../Api/Api.csproj") | ||
| .WithReference(orders); | ||
|
|
||
| // After adding all resources, run the app... | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| The app uses the [RavenDB client integration](../ravendb-connect/) as it does locally; its code does not change. | ||
|
|
||
| The product name is the product's identity: every deployment, from any machine, finds the product by it. Give every environment a name of its own, for example built from the environment's name, so that a staging deployment never changes the production product. | ||
|
|
||
| ## Choose a spec | ||
|
|
||
| Everything that decides the cost of the product and where its data lives is explicit, and nothing has a default: | ||
|
|
||
| - **Tier**: `Development` (one node, no automatic backups) or `Production` (three nodes and automatic backups), chosen by the factory method. | ||
| - **Provider and region**: the provider's own region code, such as `eu-central-1` on AWS or `westeurope` on Azure. | ||
| - **Instance type**: RavenDB Cloud's name, such as `Dev10` or `P20`. | ||
| - **Disk size, storage type and disk layout**: the layout says where the data lives, `SingleDataDisk` on a data disk of its own or `RootOnly` on the instance's system disk. RavenDB Cloud decides which layouts a tier and instance type allow. | ||
| - **Release channel**: such as `Stable72`, which follows RavenDB 7.2. | ||
| - **IOPS and throughput**: optional, for premium disks. | ||
|
|
||
| To see what you can choose, run the plan. It checks the spec against what RavenDB Cloud offers the account in that region and lists the valid values for anything that is not offered: | ||
|
|
||
| ```bash title="Terminal" | ||
| aspire do ravendb-cloud-plan-ravendb | ||
| ``` | ||
|
|
||
| ```text title="Output" | ||
| instance type 'Dev99' is not offered for the Development tier in Aws eu-central-1. Offered: Dev10 (2 vCPU, ...), Dev20 (...), ... | ||
| ``` | ||
|
|
||
| ## The plan and approving changes | ||
|
|
||
| Every deployment starts with a plan, before anything is built or changed. The plan prints one line per decision: | ||
|
|
||
| | Line | Meaning | | ||
| | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | `create` | There is no product with the name; the deployment creates it from the spec. | | ||
| | `no changes` | The product matches the spec. | | ||
| | `change` | The product differs in something RavenDB Cloud can change (instance type, disk size, storage type, IOPS, throughput). The deployment stops unless the change is approved. | | ||
| | `impossible` | The tier, provider, region, release channel or disk layout differ, or the disk would shrink. RavenDB Cloud cannot change these, so the deployment stops. | | ||
| | `allowed IPs`, `unreachable` | A declared IP range is not allowed on the product, or the product does not answer this machine. | | ||
| | `no target` | An app that references the server is not deployed with Docker Compose. | | ||
|
|
||
| Approve changes with the `RavenDB__Cloud__ApproveChanges` environment variable: | ||
|
|
||
| ```bash title="Terminal" | ||
| RavenDB__Cloud__ApproveChanges=true aspire deploy | ||
| ``` | ||
|
|
||
| The deployment reads the approval only from the environment of the process that runs it, never from `appsettings.json`, user secrets or the AppHost, so no committed file can approve future changes. In CI, set it only in a manually approved job. | ||
|
|
||
| ## Attach to an existing product | ||
|
|
||
| To use a product that already exists, possibly shared with other AppHosts, attach to it instead. The deployment never creates, changes or terminates an attached product, and the client name keeps this AppHost's certificates apart from those of other clients: | ||
|
|
||
| <Tabs syncKey="aspire-lang"> | ||
| <TabItem id="typescript" label="TypeScript"> | ||
|
|
||
| ```typescript title="apphost.mts" | ||
| const ravendb = await builder | ||
| .addRavenDB('ravendb') | ||
| .publishAsExistingRavenDBCloud(apiKey, 'shared-production', 'shop'); | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem id="csharp" label="C#"> | ||
|
|
||
| ```csharp title="AppHost.cs" | ||
| var ravendb = builder.AddRavenDB("ravendb") | ||
| .PublishAsExistingRavenDBCloud(apiKey, productName: "shared-production", clientName: "shop"); | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| Attaching is what the AppHost declares, not a permission: the API key can manage every product of the account. | ||
|
|
||
| ## Network access | ||
|
|
||
| RavenDB Cloud accepts connections only from a product's allowed IP ranges, and the Cloud API sets them only when it creates a product. A product the deployment creates gets the ranges declared with `WithAllowedIps` (`withAllowedIps` in TypeScript). On every deployment the plan checks that each declared range is allowed on the product and that the product answers the machine that deploys. Add missing ranges in the RavenDB Cloud portal. | ||
|
|
||
| <Aside type="caution"> | ||
| Keep the ranges narrow. An address inside them is stopped only by the | ||
| certificates, so the plan warns about an IPv4 range wider than /16 or an IPv6 | ||
| range wider than /48. | ||
| </Aside> | ||
|
|
||
| ## What apps receive | ||
|
|
||
| Every resource that references the server or one of its databases gets: | ||
|
|
||
| - `ConnectionStrings__<name>`: the URLs of the product's nodes, separated by commas, so that the app reaches the cluster while one node is down, and the database. | ||
| - `Aspire__RavenDB__Client__<name>__CertificateBase64`: its own client certificate as base64-encoded .pfx content, under the same name as the connection string. When the app uses no other RavenDB server, the certificate also goes to `Aspire__RavenDB__Client__CertificateBase64`. | ||
|
|
||
| When you add this package, update the [RavenDB client integration](../ravendb-connect/) in the apps too: older versions ignore `CertificateBase64`. | ||
|
|
||
| The certificate grants admin access to the databases the app references, and nothing else. Databases declared with `ensureCreated` are created by the deployment. Every deployment issues new certificates and revokes the previous ones once the apps run with the new ones. | ||
|
|
||
| With Docker Compose the values are written to `aspire-output/.env.<environment>` in plain text on the machine that runs `aspire deploy`: protect that machine, keep `aspire-output/` out of source control, and do not upload it as a CI artifact. | ||
|
|
||
| ## Pipeline steps | ||
|
|
||
| For a server named `ravendb`, the integration adds these steps to the [deployment pipeline](/deployment/pipelines/): | ||
|
|
||
| | Step | What it does | | ||
| | ------------------------------------ | ------------------------------------------------------------------------------------ | | ||
| | `ravendb-cloud-plan-ravendb` | Shows the plan and stops the deployment on a blocking line. | | ||
| | `ravendb-cloud-provision-ravendb` | Creates or changes the product and waits until it is active. | | ||
| | `ravendb-cloud-databases-ravendb` | Creates the databases declared with `ensureCreated`. | | ||
| | `ravendb-cloud-certificates-ravendb` | Issues every app its certificate. | | ||
| | `ravendb-cloud-cleanup-ravendb` | Revokes the certificates the apps no longer use, after `docker compose up`. | | ||
| | `ravendb-cloud-destroy-ravendb` | Revokes the certificates in `aspire destroy`, and terminates the product when asked. | | ||
|
|
||
| <LearnMore> | ||
| Learn more about [`aspire do`](/reference/cli/commands/aspire-do/) and | ||
| [`aspire deploy`](/reference/cli/commands/aspire-deploy/) in the command | ||
| reference. | ||
| </LearnMore> | ||
|
|
||
| ## Destroy | ||
|
|
||
| Terminating a product deletes its data, so `aspire destroy` terminates it only when the AppHost sets `TerminateOnDestroy` (`terminateOnDestroy` in TypeScript) in the options of the publish call; it is off by default. Before terminating, destroy names the product and refuses one whose tier, provider, region, release channel or instance type differ from the AppHost. A product the AppHost attaches to is never terminated. | ||
|
|
||
| <Tabs syncKey="aspire-lang"> | ||
| <TabItem id="typescript" label="TypeScript"> | ||
|
|
||
| ```typescript title="apphost.mts" | ||
| { | ||
| configure: async cloud => { | ||
| await cloud.withAllowedIps(["203.0.113.0/24"]); | ||
| await cloud.terminateOnDestroy.set(true); | ||
| }, | ||
| } | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem id="csharp" label="C#"> | ||
|
|
||
| ```csharp title="AppHost.cs" | ||
| cloud => | ||
| { | ||
| cloud.WithAllowedIps("203.0.113.0/24"); | ||
| cloud.TerminateOnDestroy = true; | ||
| } | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| ## Continuous deployment | ||
|
|
||
| Pass the API key as the `Parameters__ravendb-cloud-api-key` environment variable: | ||
|
|
||
| ```yaml title=".github/workflows/deploy.yml" | ||
| jobs: | ||
| deploy: | ||
| runs-on: self-hosted | ||
| concurrency: deploy-production | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-dotnet@v4 | ||
| - run: dotnet tool install -g Aspire.Cli | ||
| - run: aspire deploy --non-interactive | ||
| env: | ||
| Parameters__ravendb-cloud-api-key: ${{ secrets.RAVENDB_CLOUD_API_KEY }} | ||
| ``` | ||
|
|
||
| `aspire deploy` starts the apps with Docker Compose on the Docker that the runner uses, so the apps run where that Docker runs. A GitHub-hosted runner is discarded when the job ends, together with the apps, while the RavenDB Cloud product keeps running. Run the job on a self-hosted runner on the machine that hosts the apps, with its outbound address in the product's allowed IP ranges. `concurrency` keeps two runs from deploying at once. Aspire saves parameter values, the API key included, in its [deployment state](/deployment/deployment-state-caching/), and a saved value wins over a new one from the environment: after replacing the key, deploy once with `aspire deploy --clear-cache`. | ||
|
|
||
| ## Known limitations | ||
|
|
||
| - The apps that use the server are deployed with Docker Compose for now. Elsewhere the plan stops with `no target`, because Azure Container Apps and Azure App Service would carry the certificate as a plain template parameter, visible in the deployment history. | ||
| - RavenDB Cloud creates free products only in the portal. To use one, attach to it. | ||
|
|
||
| ## See also | ||
|
|
||
| - [Set up RavenDB in the AppHost](../ravendb-host/) | ||
| - [Connect to RavenDB](../ravendb-connect/) | ||
| - [Deploy to Docker Compose](/deployment/docker-compose/) | ||
| - [RavenDB Cloud hosting integration README](https://github.com/CommunityToolkit/Aspire/tree/main/src/CommunityToolkit.Aspire.Hosting.RavenDB.Cloud), with troubleshooting | ||
| - [RavenDB Cloud documentation](https://docs.ravendb.net/cloud/cloud-overview) | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -153,6 +153,8 @@ The connection string is resolved from the `ConnectionStrings` section: | |
| } | ||
| ``` | ||
|
|
||
| For a cluster, list its nodes in `URL` separated by commas, for example `URL=https://a.example.com,https://b.example.com,https://c.example.com`: the client then reaches the cluster while one node is down. | ||
|
|
||
| **Configuration providers.** The client integration supports `Microsoft.Extensions.Configuration`. It loads `RavenDBClientSettings` from _appsettings.json_ (or any other configuration source) by using the `Aspire:RavenDB:Client` key: | ||
|
|
||
| ```json title="appsettings.json" | ||
|
|
@@ -171,6 +173,14 @@ The connection string is resolved from the `ConnectionStrings` section: | |
| } | ||
| ``` | ||
|
|
||
| **Client certificate.** A secured server needs a client certificate. Configuration can give it as a file (`CertificatePath`, with `CertificatePassword` if the file has one) or as the base64-encoded content of a .pfx file (`CertificateBase64`), which suits a certificate delivered as a value, such as an environment variable: | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The client with |
||
|
|
||
| ```bash title="Environment" | ||
| Aspire__RavenDB__Client__ravendb__CertificateBase64=MIIK... | ||
| ``` | ||
|
|
||
| `Certificate` set in code is used first, then `CertificateBase64`, then `CertificatePath`. The [RavenDB Cloud hosting integration](../ravendb-cloud/) delivers every app its certificate this way; older client versions ignore `CertificateBase64`. | ||
|
|
||
| **Inline delegates.** Pass an `Action<RavenDBClientSettings>` to configure settings inline, for example to disable health checks: | ||
|
|
||
| ```csharp title="Program.cs" | ||
|
|
||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Contradicted (Phase A). This sentence says a
releasequality CLI selects only stable releases. That isn't howaspire addworks today. The part about*floating versions is accurate.In
microsoft/aspire@2e31a5b(main):aspire addalways searches the implicit channel, and that channel isPackageChannelQuality.Bothprecisely so Community Toolkit prerelease packages show up (src/Aspire.Cli/Packaging/PackageChannel.cs:1139-1146).src/Aspire.Cli/Packaging/IntegrationPackageSearchService.cs:191-199says the implicit channel "must always participate so prerelease packages are reachable even when the explicit pin is Stable-quality". It cites aspire add kube adds first matching integration instead of failing aspire#17724 and Prerelease-only integrations like Aspire.Hosting.Foundry are filtered out of search aspire#17725, which were about prerelease-only packages likeAspire.Hosting.Foundry.src/Aspire.Cli/Commands/AddCommand.cs:783-790: with no pinned channel,aspire addorders the implicit channel first, then by the highest SemVer. So a prerelease-only package resolves without--version.Suggested fix: drop the "
releasequality CLI … select only stable releases" clause and thestaging/devremark on line 65.aspire add CommunityToolkit.Aspire.Hosting.RavenDB.Cloudshould work as-is. Keep the note that a manual<PackageReference>needs an explicit prerelease version, sinceVersion="*"doesn't float to prereleases.