-
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.
Signed-off-by: jasonviviano <[email protected]>
- Loading branch information
1 parent
d9be7b5
commit 3da0726
Showing
5 changed files
with
224 additions
and
1 deletion.
There are no files selected for viewing
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.
75 changes: 75 additions & 0 deletions
75
.../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,75 @@ | ||
--- | ||
type: docs | ||
title: "How-To: Author a portable resources" | ||
linkTitle: "Author a portable resource" | ||
description: "Learn how to author portable resources in Radius" | ||
weight: 200 | ||
categories: "How-To" | ||
tags: ["portability"] | ||
--- | ||
|
||
This guide will provide an overview of 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: | ||
|
||
- [Radius initialized with `rad init`]({{< ref getting-started >}}) | ||
- [Radius Bicep VSCode extension]({{< ref "installation#step-2-install-the-radius-bicep-extension" >}}) | ||
|
||
## Step 1: Define a container resource | ||
|
||
Create a Bicep file `app.bicep`, add a container resource that will be leveraged by your portable resource later: | ||
|
||
{{< rad file="snippets/app.bicep" embed=true marker="//EMPTYCONTAINER" >}} | ||
|
||
## Step 2: Define your portable resource | ||
|
||
{{< tabs Recipe Manual >}} | ||
|
||
{{% codetab %}} | ||
|
||
Recipes enable a separation of concerns between infrastructure operators and developers by automating infrastructure deployment. To learn more visit the [Recipes overview]({{< ref "/guides/recipes/overview" >}}) | ||
|
||
{{% /codetab %}} | ||
|
||
{{% codetab %}} | ||
|
||
Find the schema needed for the supported Radius resource by visiting the [Radius resource schema docs]({{< ref resource-schema >}}). For this example you can follow along and define a RedisCache resource: | ||
|
||
{{< rad file="snippets/app-redis-manual.bicep" embed=true marker="//MANUAL" >}} | ||
|
||
{{% /codetab %}} | ||
|
||
{{< /tabs >}} | ||
|
||
## Step 3: Accessing your portable resource | ||
|
||
Users can leverage their portable resources and establish connections to their container resources by adding accessing properties: | ||
|
||
{{< rad file="snippets/app-redis-manual.bicep" embed=true marker="//CONTAINER" markdownConfig="{linenos=table,hl_lines=[\"19-22\"]}">}} | ||
|
||
## Step 4: Deploy your 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: | ||
|
||
<img 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 portable-resources >}}) | ||
- [Radius Application overview]({{< ref "/guides/author-apps/application/overview" >}}) |
132 changes: 132 additions & 0 deletions
132
...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,132 @@ | ||
import radius as radius | ||
|
||
import kubernetes as kubernetes { | ||
kubeConfig: '' | ||
namespace: namespace | ||
} | ||
|
||
@description('Specifies the environment for resources.') | ||
param environment string | ||
|
||
@description('Specifies the application for resources.') | ||
param application string | ||
|
||
@description('Specifies the namespace for resources.') | ||
param namespace string | ||
|
||
//CONTAINER | ||
resource container 'Applications.Core/containers@2023-10-01-preview' = { | ||
name: 'demo' | ||
properties: { | ||
application: application | ||
container: { | ||
image: 'radius.azurecr.io/tutorial/webapp:edge' | ||
ports: { | ||
web: { | ||
containerPort: 3000 | ||
} | ||
} | ||
livenessProbe: { | ||
kind: 'httpGet' | ||
containerPort: 3000 | ||
path: '/healthz' | ||
initialDelaySeconds: 10 | ||
} | ||
} | ||
connections: { | ||
redis: { | ||
source: portableRedis.id | ||
} | ||
} | ||
} | ||
} | ||
//CONTAINER | ||
|
||
//MANUAL | ||
resource redis 'apps/Deployment@v1' = { | ||
metadata: { | ||
name: 'redis-${uniqueString(application)}' | ||
} | ||
spec: { | ||
selector: { | ||
matchLabels: { | ||
app: 'redis' | ||
resource: portableRedis.name | ||
} | ||
} | ||
template: { | ||
metadata: { | ||
labels: { | ||
app: 'redis' | ||
resource: portableRedis.name | ||
|
||
// Label pods with the application name so `rad run` can find the logs. | ||
'radapp.io/application': application == null ? '' : application | ||
} | ||
} | ||
spec: { | ||
containers: [ | ||
{ | ||
// This container is the running redis instance. | ||
name: 'redis' | ||
image: 'redis' | ||
ports: [ | ||
{ | ||
containerPort: 6379 | ||
} | ||
] | ||
} | ||
{ | ||
// This container will connect to redis and stream logs to stdout for aid in development. | ||
name: 'redis-monitor' | ||
image: 'redis' | ||
args: [ | ||
'redis-cli' | ||
'-h' | ||
'localhost' | ||
'MONITOR' | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
|
||
resource svc 'core/Service@v1' = { | ||
metadata: { | ||
name: 'redis-${uniqueString(application)}' | ||
} | ||
spec: { | ||
type: 'ClusterIP' | ||
selector: { | ||
app: 'redis' | ||
resource: portableRedis.name | ||
} | ||
ports: [ | ||
{ | ||
port: 6379 | ||
} | ||
] | ||
} | ||
} | ||
|
||
resource portableRedis 'Applications.Datastores/redisCaches@2023-10-01-preview' = { | ||
name: 'redisCache' | ||
properties: { | ||
environment: environment | ||
application: application | ||
resourceProvisioning: 'manual' | ||
resources: [{ | ||
id: '/planes/kubernetes/local/namespaces/${svc.metadata.namespace}/providers/core/Service/${svc.metadata.name}' | ||
} | ||
{ | ||
id: '/planes/kubernetes/local/namespaces/${redis.metadata.namespace}/providers/apps/Deployment/${redis.metadata.name}' | ||
} | ||
] | ||
username: 'myusername' | ||
host: '${svc.metadata.name}.${svc.metadata.namespace}.svc.cluster.local' | ||
port: svc.ports[0].port | ||
} | ||
} | ||
//MANUAL |
16 changes: 16 additions & 0 deletions
16
.../guides/author-apps/portable-resources/howto-author-portable-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,16 @@ | ||
import radius as radius | ||
|
||
@description('Specifies the application for resources.') | ||
param application string | ||
|
||
//CONTAINER | ||
resource container 'Applications.Core/containers@2023-10-01-preview' = { | ||
name: 'demo' | ||
properties: { | ||
application: application | ||
container: { | ||
image: 'radius.azurecr.io/tutorial/webapp:edge' | ||
} | ||
} | ||
} | ||
//CONTAINER |
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