Skip to content
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 extender docs #933

Merged
merged 9 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/config/en-custom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1077,4 +1077,6 @@ reimagines
TechCrunch
ZDNET
Newstrail
postgresql
natively
NuGet
7 changes: 7 additions & 0 deletions docs/content/guides/author-apps/custom/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
type: docs
title: "Custom resources"
AaronCrawfis marked this conversation as resolved.
Show resolved Hide resolved
linkTitle: "Custom resources"
description: "Model and deploy your own resource types"
weight: 550
---
78 changes: 78 additions & 0 deletions docs/content/guides/author-apps/custom/howto-extenders/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
type: docs
title: "How-To: Model any resource with an extender"
linkTitle: "Extenders"
description: "Learn how to use extenders in an application"
weight: 300
---

This guide will walk you through how to use an [extender]({{< ref "/guides/author-apps/custom/overview#extenders" >}}) in an application to model resources beyond those currently built into Radius. These might be abstractions or resources unique to your organization, or resources that don't yet have a native Radius type.

## Prerequisites

- [rad CLI]({{< ref "installation#step-1-install-the-rad-cli" >}})
- [Radius Bicep VSCode extension]({{< ref "installation#step-2-install-the-vs-code-extension" >}})
- [Radius environment]({{< ref "installation#step-3-initialize-radius" >}})

## Step 1: Register an extender Recipe

In this guide you will leverage a [Recipe]({{< ref "/guides/recipes/overview" >}}) to deploy backing infrastructure for your resource. Begin by registering the 'extender-postgresql' Recipe in your environment:

```bash
rad recipe register postgresql --resource-type "Applications.Core/extenders" --template-kind bicep --template-path "ghcr.io/radius-project/recipes/local-dev/postgresql:latest"
```

## Step 2: Define an extender

Open a new file named `app.bicep` and define an extender:
AaronCrawfis marked this conversation as resolved.
Show resolved Hide resolved

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

## Step 3: Add a container

Add a container to your `app.bicep` file, accessing the extender's properties and secrets:

{{< rad file="snippets/app-container.bicep" embed=true marker="//CONTAINER" >}}

## Step 4: Deploy the app

Deploy and [run]({{< ref rad_run >}}) the app using the following command:

```bash
rad run app.bicep -a demo
```

You should see your application deployed:

```
Building .\app.bicep...
Deploying template '.\app.bicep' for application 'demo' and environment 'default' from workspace 'default'...

Deployment In Progress...


Deployment Complete

Resources:
demo Applications.Core/containers
extender Applications.Core/extenders

Starting log stream...

demo-bb9df8798-b68rc › demo
demo-bb9df8798-b68rc demo Using in-memory store: no connection string found
demo-bb9df8798-b68rc demo Server is running at http://localhost:3000
demo-bb9df8798-b68rc demo [port-forward] connected from localhost:3000 -> ::3000
```

## Step 5: Test the app

Visit [https://localhost:3000](https://localhost:3000) to see your app running. You should see the environment variables and secrets you referenced in your container.

## Cleanup

To clean up the resources created in this guide, run:

```bash
rad app delete demo -y
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import radius as rad

@description('The ID of your Radius environment. Set automatically by the rad CLI.')
param environment string

@description('The ID of your Radius application. Set automatically by the rad CLI.')
param application string

resource extender 'Applications.Core/extenders@2023-10-01-preview' = {
name: 'postgresql'
properties: {
environment: environment
application: application
recipe: {
name: 'postgresql'
}
}
}

//CONTAINER
resource demo 'Applications.Core/containers@2023-10-01-preview' = {
name: 'demo'
properties: {
application: application
container: {
image: 'ghcr.io/radius-project/samples/demo:latest'
env: {
POSTGRESQL_HOST: extender.properties.host
POSTGRESQL_PORT: extender.properties.port
POSTGRESQL_USERNAME: extender.properties.username
POSTGRESQL_PASSWORD: extender.secrets('password')
}
ports: {
web: {
containerPort: 3000
}
}
}
connections: {
postgresql: {
source: extender.id
}
}
}
}
//CONTAINER
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import radius as rad

@description('The ID of your Radius environment. Set automatically by the rad CLI.')
param environment string

@description('The ID of your Radius application. Set automatically by the rad CLI.')
param application string

resource extender 'Applications.Core/extenders@2023-10-01-preview' = {
name: 'postgresql'
properties: {
environment: environment
application: application
recipe: {
name: 'postgresql'
}
}
}
17 changes: 17 additions & 0 deletions docs/content/guides/author-apps/custom/overview/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
type: docs
title: "Overview: Custom resource types"
linkTitle: "Overview"
description: "Learn how to model and deploy your own resource types in Radius"
weight: 100
---

When you have a need for types beyond those currently built into Radius, you can model and deploy your own resource types. Currently, Radius supports an untyped "extender" resource which allows you to pass in any property or secret.

## Extenders

Extenders are a special type of resource that allows you to pass in any property or secret. This is useful for modeling resources that aren't natively supported by Radius.

[Recipes]({{< ref "/guides/recipes/overview" >}}) can be used with extenders to manage the backing infrastructure.

Refer to the [How-To: Extenders guide]({{< ref howto-extenders >}}) for more information on how to use an extender.
Loading