-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add How-To guide on sharing portable resources between applications #824
Closed
Closed
Changes from 3 commits
Commits
Show all changes
4 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
98 changes: 98 additions & 0 deletions
98
docs/content/guides/author-apps/portable-resources/howto-share-resources/index.md
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
--- | ||
type: docs | ||
title: "How-To: Share portable resources between applications" | ||
linkTitle: "Share between apps" | ||
description: "Learn how to share portable resources between applications" | ||
weight: 400 | ||
categories: "Overview" | ||
--- | ||
|
||
This guide will show you how you can share portable resources between Radius applications. | ||
|
||
## Pre-requisites | ||
|
||
- [rad CLI]({{< ref "/guides/tooling/rad-cli/overview" >}}) | ||
- [rad development environment]({{< red "getting-started" >}}) | ||
|
||
## Step 1: Define an environment-scoped resource | ||
|
||
Portable resources can be environment-scoped, where they follow the lifecycle of an environment instead of an application. Define a resource, such as a Redis cache, in your app.bicep file: | ||
|
||
{{< rad file="snippets/app.bicep" embed=true >}} | ||
|
||
## Step 2: Deploy resource | ||
|
||
Deploy the resource with [`rad deploy`]({{< ref rad_deploy >}}), using the 'local-dev' Recipe: | ||
|
||
```bash | ||
rad deploy app.bicep | ||
``` | ||
|
||
You should see the resource deployed into your environment: | ||
|
||
```Building .\app.bicep... | ||
Deploying template '.\app.bicep' into environment 'default' from workspace 'default'... | ||
|
||
Deployment In Progress... | ||
|
||
... shared-cache Applications.Datastores/redisCaches | ||
|
||
Deployment Complete | ||
|
||
Resources: | ||
shared-cache Applications.Datastores/redisCaches | ||
``` | ||
|
||
## Step 3: Verify the resource was deployed | ||
|
||
Run [`rad resource show`]({{< ref rad_resource_show >}}) to verify the resource was deployed into the environment's Kubernetes namespace: | ||
|
||
```bash | ||
rad resource show rediscaches shared-cache -o json | ||
``` | ||
|
||
You should see the raw JSON output, including the `outputResources` property which shows the Kubernetes namespace the Redis cache was deployed into. It will match the environment's namespace ('default') and not an application's ('default-app1', 'default-app2'): | ||
|
||
``` | ||
{ | ||
"id": "/planes/radius/local/resourcegroups/default/providers/Applications.Datastores/redisCaches/shared-cache", | ||
"location": "global", | ||
"name": "shared-cache", | ||
"properties": { | ||
"application": "", | ||
"environment": "/planes/radius/local/resourceGroups/default/providers/applications.core/environments/default", | ||
"host": "redis-bvempevrr4ygm.default.svc.cluster.local", | ||
"port": 6379, | ||
"provisioningState": "Succeeded", | ||
"recipe": { | ||
"name": "default" | ||
}, | ||
"resourceProvisioning": "recipe", | ||
"status": { | ||
"outputResources": [ | ||
{ | ||
"id": "/planes/kubernetes/local/namespaces/default/providers/core/Service/redis-bvempevrr4ygm", | ||
"radiusManaged": true | ||
}, | ||
{ | ||
"id": "/planes/kubernetes/local/namespaces/default/providers/apps/Deployment/redis-bvempevrr4ygm", | ||
"radiusManaged": true | ||
} | ||
] | ||
}, | ||
"tls": false, | ||
"username": "" | ||
}, | ||
"systemData": {}, | ||
"tags": {}, | ||
"type": "Applications.Datastores/redisCaches" | ||
} | ||
``` | ||
|
||
## Done | ||
|
||
Now that you have an environment-scoped resource you can define connections to it from any Radius container from any application. You can also cleanup with the resource with [`rad resource delete`]({{< ref rad_resource_delete >}}): | ||
|
||
```bash | ||
rad resource delete rediscaches shared-cache -y | ||
``` |
12 changes: 12 additions & 0 deletions
12
docs/content/guides/author-apps/portable-resources/howto-share-resources/snippets/app.bicep
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import radius as rad | ||
|
||
@description('Environment ID of the Radius environment being deployed into. Injected automatically by the rad CLI.') | ||
param environment string | ||
|
||
resource sharedCache 'Applications.Datastores/redisCaches@2023-10-01-preview' = { | ||
name: 'shared-cache' | ||
properties: { | ||
environment: environment | ||
// No application property defined as this resource follows the lifecycle of the environment | ||
} | ||
} |
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.
This ends with the deployment of portable resources, should we teach the sharing part of multiple applications deployed to an env connecting to this resource?