-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'edge' into jasonviviano/kubernetes-incremental-guide
- Loading branch information
Showing
7 changed files
with
155 additions
and
1 deletion.
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
Binary file added
BIN
+145 KB
...rtable-resources/howto-author-portable-resources/demo-with-redis-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions
78
.../guides/author-apps/portable-resources/howto-author-portable-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,78 @@ | ||
--- | ||
type: docs | ||
title: "How-To: Author portable resources" | ||
linkTitle: "Author portable resources" | ||
description: "Learn how to author portable resources in Radius" | ||
weight: 200 | ||
categories: "How-To" | ||
tags: ["portability"] | ||
--- | ||
|
||
This guide will teach you how to author a portable resource for your [Radius Application]({{< ref "/guides/author-apps/application/overview" >}}). | ||
|
||
## Prerequisites | ||
|
||
Before you get started, you'll need to make sure you have the following tools and resources: | ||
|
||
- [rad CLI]({{< ref "installation#step-1-install-the-rad-cli" >}}) | ||
- [Radius environment]({{< ref "installation#step-3-initialize-radius" >}}) | ||
- [Radius Bicep VSCode extension]({{< ref "installation#step-2-install-the-vs-code-extension" >}}) | ||
|
||
## Step 1: Add a portable resource | ||
|
||
Portable resources provide **abstraction** and **portability** to Radius Applications. Radius currently offers options to manually provision the resources or automatically provision them via Recipes: | ||
|
||
{{< tabs Recipe Manual >}} | ||
|
||
{{% codetab %}} | ||
|
||
Recipes handle infrastructure provisioning for you. You can use a Recipe to provision a Redis cache, using your environment's default Recipe. | ||
|
||
Create a file named `app.bicep` and paste the following: | ||
|
||
{{< rad file="snippets/app-redis-recipe.bicep" embed=true marker="//RECIPE" >}} | ||
|
||
To learn more about Recipes visit the [Recipes overview page]({{< ref "/guides/recipes/overview" >}}). | ||
|
||
{{% /codetab %}} | ||
|
||
{{% codetab %}} | ||
|
||
You can also manually manage your infrastructure and use a portable resource to abstract the details. Create a file named `app.bicep` and paste the following: | ||
|
||
{{< rad file="snippets/app-redis-manual.bicep" embed=true marker="//MANUAL" >}} | ||
|
||
{{% /codetab %}} | ||
|
||
{{< /tabs >}} | ||
|
||
## Step 2: Add a container | ||
|
||
In your Bicep file `app.bicep`, add a container resource that will connect to the Redis cache. Note the connection to the Redis cache automatically injects connection-related environment variables into the container. Optionally, you can also manually access properties and set environment variables based on your portable resource values. | ||
|
||
{{< rad file="snippets/app-redis-manual.bicep" embed=true marker="//CONTAINER" >}} | ||
|
||
## Step 3: Deploy the app | ||
|
||
1. Run your application in your environment: | ||
|
||
```bash | ||
rad run ./app.bicep -a demo | ||
``` | ||
|
||
1. Visit [localhost:3000](http://localhost:3000) in your browser. You should see the following page, now showing injected environment variables: | ||
|
||
{{< image src="demo-with-redis-screenshot.png" alt="Screenshot of the demo app with all environment variables" width=1000px >}} | ||
|
||
## Cleanup | ||
|
||
Run `rad app delete` to cleanup your Radius application, container, and Redis cache: | ||
|
||
```bash | ||
rad app delete -a demo | ||
``` | ||
|
||
## Further reading | ||
|
||
- [Portable resource overview]({{< ref "/guides/author-apps/portable-resources/overview" >}}) | ||
- [Radius Application overview]({{< ref "/guides/author-apps/application/overview" >}}) |
51 changes: 51 additions & 0 deletions
51
...r-apps/portable-resources/howto-author-portable-resources/snippets/app-redis-manual.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,51 @@ | ||
//MANUAL | ||
import radius as radius | ||
|
||
@description('Specifies the environment for resources.') | ||
param environment string | ||
|
||
@description('Specifies the application for resources.') | ||
param application string | ||
|
||
resource redis 'Applications.Datastores/redisCaches@2023-10-01-preview' = { | ||
name: 'myredis' | ||
properties: { | ||
environment: environment | ||
application: application | ||
resourceProvisioning: 'manual' | ||
username: 'myusername' | ||
host: 'mycache.contoso.com' | ||
port: 8080 | ||
secrets: { | ||
password: '******' | ||
} | ||
} | ||
} | ||
//MANUAL | ||
|
||
//CONTAINER | ||
resource container 'Applications.Core/containers@2023-10-01-preview' = { | ||
name: 'demo' | ||
properties: { | ||
application: application | ||
container: { | ||
image: 'ghcr.io/radius-project/samples/demo:latest' | ||
env: { | ||
// Manually access Redis connection information | ||
REDIS_CONNECTION: redis.connectionString() | ||
} | ||
ports: { | ||
web: { | ||
containerPort: 3000 | ||
} | ||
} | ||
} | ||
connections: { | ||
// Automatically inject connection details | ||
redis: { | ||
source: redis.id | ||
} | ||
} | ||
} | ||
} | ||
//CONTAINER |
17 changes: 17 additions & 0 deletions
17
...r-apps/portable-resources/howto-author-portable-resources/snippets/app-redis-recipe.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,17 @@ | ||
//RECIPE | ||
import radius as radius | ||
|
||
@description('Specifies the environment for resources.') | ||
param environment string | ||
|
||
@description('Specifies the application for resources.') | ||
param application string | ||
|
||
resource redis 'Applications.Datastores/redisCaches@2023-10-01-preview'= { | ||
name: 'myredis' | ||
properties: { | ||
environment: environment | ||
application: application | ||
} | ||
} | ||
//RECIPE |
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