Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Crawfis <[email protected]>
  • Loading branch information
AaronCrawfis committed Dec 2, 2023
1 parent 9d170e1 commit fb7d67e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,59 +13,46 @@ This guide will teach you how to author a portable resource for your [Radius App
## 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: Choose how to define your portable resource
## 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.
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 enable a separation of concerns between infrastructure operators and developers by automating infrastructure deployment. You can run a default recipe registered in your environment or select the specific Recipe you want to run.
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" >}}
{{< rad file="snippets/app-redis-recipe.bicep" embed=true marker="//RECIPE" >}}

To learn more visit the [Recipes overview]({{< ref "/guides/recipes/overview" >}}).
To learn more about Recipes visit the [Recipes overview page]({{< ref "/guides/recipes/overview" >}}).

{{% /codetab %}}

{{% codetab %}}

Add a RedisCache resource with the `resourceProvisioning` mode as `manual`. This enables you to configure the underlying Redis resource
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" >}}

Refer to the [Redis resource schema]({{< ref "reference/resource-schema/cache/redis" >}}) for more details.

{{% /codetab %}}

{{< /tabs >}}

## Step 2: Define a container resource

In your Bicep file `app.bicep`, add a container resource that will be leveraged by your portable resource later:

{{< rad file="snippets/app.bicep" embed=true >}}

## Step 3: Access your portable resources

You can access the portable resource via [`connections`]({{< ref "guides/author-apps/containers#connections" >}}). Update your container definition to add a connection to the new Redis cache. This results in environment variables for connection information automatically set on the container.

In addition, you can manually access properties and set environment variables based on your portable resource values.

#### Manual

{{< rad file="snippets/app-redis-manual.bicep" embed=true >}}
## Step 2: Add a container

#### Recipe
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 enivronment 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-recipe.bicep" embed=true >}}
{{< rad file="snippets/app-redis-manual.bicep" embed=true marker="//CONTAINER" >}}

## Step 4: Deploy your app
## Step 3: Deploy the app

1. Run your application in your environment:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//MANUAL
import radius as radius

@description('Specifies the environment for resources.')
Expand All @@ -6,6 +7,22 @@ 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'
Expand All @@ -14,43 +31,21 @@ resource container 'Applications.Core/containers@2023-10-01-preview' = {
container: {
image: 'ghcr.io/radius-project/samples/demo:latest'
env: {
ConnectionString: portableRedis.connectionString()
// Manually access Redis connection information
REDIS_CONNECTION: redis.connectionString()
}
ports: {
web: {
containerPort: 3000
}
}
livenessProbe: {
kind: 'httpGet'
containerPort: 3000
path: '/healthz'
initialDelaySeconds: 10
}
}
connections: {
// Automatically inject connection details
redis: {
source: portableRedis.id
source: redis.id
}
}
}
}
//CONTAINER

//MANUAL
resource portableRedis 'Applications.Datastores/redisCaches@2023-10-01-preview' = {
name: 'redisCache'
properties: {
environment: environment
application: application
resourceProvisioning: 'manual'
username: 'myusername'
host: 'mycache.contoso.com'
port: 8080
secrets: {
password: '******'
}
}
}
//MANUAL

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//RECIPE
import radius as radius

@description('Specifies the environment for resources.')
Expand All @@ -6,44 +7,11 @@ param environment string
@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: 'ghcr.io/radius-project/samples/demo:latest'
env: {
connectionString: recipeRedis.connectionString()
}
ports: {
web: {
containerPort: 3000
}
}
livenessProbe: {
kind: 'httpGet'
containerPort: 3000
path: '/healthz'
initialDelaySeconds: 10
}
}
connections: {
redis: {
source: recipeRedis.id
}
}
}
}
//CONTAINER

//Recipe
resource recipeRedis 'Applications.Datastores/redisCaches@2023-10-01-preview'= {
name: 'myresource'
resource redis 'Applications.Datastores/redisCaches@2023-10-01-preview'= {
name: 'myredis'
properties: {
environment: environment
application: application
}
}
//Recipe

//RECIPE

This file was deleted.

0 comments on commit fb7d67e

Please sign in to comment.