diff --git a/docs/content/guides/author-apps/portable-resources/howto-author-portable-resources/index.md b/docs/content/guides/author-apps/portable-resources/howto-author-portable-resources/index.md index 81acccaa0..bebaae9a3 100644 --- a/docs/content/guides/author-apps/portable-resources/howto-author-portable-resources/index.md +++ b/docs/content/guides/author-apps/portable-resources/howto-author-portable-resources/index.md @@ -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: diff --git a/docs/content/guides/author-apps/portable-resources/howto-author-portable-resources/snippets/app-redis-manual.bicep b/docs/content/guides/author-apps/portable-resources/howto-author-portable-resources/snippets/app-redis-manual.bicep index 3228669fd..8384f763c 100644 --- a/docs/content/guides/author-apps/portable-resources/howto-author-portable-resources/snippets/app-redis-manual.bicep +++ b/docs/content/guides/author-apps/portable-resources/howto-author-portable-resources/snippets/app-redis-manual.bicep @@ -1,3 +1,4 @@ +//MANUAL import radius as radius @description('Specifies the environment for resources.') @@ -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' @@ -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 - diff --git a/docs/content/guides/author-apps/portable-resources/howto-author-portable-resources/snippets/app-redis-recipe.bicep b/docs/content/guides/author-apps/portable-resources/howto-author-portable-resources/snippets/app-redis-recipe.bicep index 1f6c9b3d8..c4bea58dc 100644 --- a/docs/content/guides/author-apps/portable-resources/howto-author-portable-resources/snippets/app-redis-recipe.bicep +++ b/docs/content/guides/author-apps/portable-resources/howto-author-portable-resources/snippets/app-redis-recipe.bicep @@ -1,3 +1,4 @@ +//RECIPE import radius as radius @description('Specifies the environment for resources.') @@ -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 diff --git a/docs/content/guides/author-apps/portable-resources/howto-author-portable-resources/snippets/app.bicep b/docs/content/guides/author-apps/portable-resources/howto-author-portable-resources/snippets/app.bicep deleted file mode 100644 index 7bbff7199..000000000 --- a/docs/content/guides/author-apps/portable-resources/howto-author-portable-resources/snippets/app.bicep +++ /dev/null @@ -1,32 +0,0 @@ -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: 'ghcr.io/radius-project/samples/demo:latest' - ports: { - web: { - containerPort: 3000 - } - } - livenessProbe: { - kind: 'httpGet' - containerPort: 3000 - path: '/healthz' - initialDelaySeconds: 10 - } - } - connections: { - redis: { - //... - } - } - } -} -//CONTAINER