-
Notifications
You must be signed in to change notification settings - Fork 47
Add tutorial to create a resource type in Radius #1409
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
Merged
Changes from all commits
Commits
Show all changes
105 commits
Select commit
Hold shift + click to select a range
35b542e
Add udt tutorial
Reshrahim 959073a
Updates
Reshrahim e65c08a
Updates
Reshrahim f38cc7d
Fix rad file
Reshrahim fcbb511
Add Bicep outputs
Reshrahim 21d4b7f
Refine steps
Reshrahim 1144242
Merge branch 'edge' into re/udt
Reshrahim eb99e9a
Fix bicep config
Reshrahim 5b8832b
Merge branch 're/udt' of https://github.com/radius-project/docs into …
Reshrahim 1f86c1b
Fix formatting
Reshrahim f068aa3
Fixes to docs and bicep files
Reshrahim e2312b3
Fix Recipes reference
Reshrahim e674ccc
Fix naming
Reshrahim 90d4145
Fix errors
Reshrahim 6612df4
Updates
Reshrahim 2424eb8
Fix code snippet formatting
Reshrahim 5ce2d2d
Fix code snippet formatting
Reshrahim 9fe4076
Fix code snippet formatting
Reshrahim e7eaf4c
Address feedback
Reshrahim 1ae227a
Fix refernce
Reshrahim bbf436a
Fix refernce
Reshrahim 3f48129
Fix refernce
Reshrahim 395daf3
Fix refernce
Reshrahim 4333f91
Fix refernce to guides
Reshrahim 975b59e
Address feddback
Reshrahim b4e40ec
Fix todoapp image
Reshrahim f97622a
Fix snippets
Reshrahim 9bb65e5
Updates
Reshrahim 25aa751
Update docs/content/tutorials/tutorial-resource-type/index.md
Reshrahim e63dc84
Update docs/content/tutorials/tutorial-resource-type/index.md
Reshrahim 10e935e
Update docs/content/tutorials/tutorial-resource-type/index.md
Reshrahim 7bf98cb
Address feedback
Reshrahim dfb81b6
Merge branch 're/udt' of https://github.com/radius-project/docs into …
Reshrahim ff22421
Address feedback
Reshrahim 411530b
Address feedback
Reshrahim 3952365
fix image
Reshrahim 73f9f83
fix image
Reshrahim 597388b
Apply suggestions from code review
Reshrahim 5d160ca
Apply suggestions from code review
Reshrahim 01beeb2
Apply suggestions from code review
Reshrahim 02eba8c
Address PR review feedback
Reshrahim 07b72cc
Fix bicep validation error
Reshrahim c93d797
Merge branch 'edge' into re/udt
Reshrahim da0f460
Update docs/content/tutorials/tutorial-resource-type/snippets/app.bicep
Reshrahim b97ee0d
Add caution on secrets
Reshrahim 989cf94
Updates
Reshrahim ec75bf5
Updates
Reshrahim 8ed29b3
Updates
Reshrahim 9784700
Add local registry
Reshrahim 8fbe694
fix tabs
Reshrahim 00b72c6
Nits
Reshrahim 34b9820
Trigger Build
Reshrahim 6a309de
Fixes
Reshrahim 3bfa9ee
Fixes
Reshrahim a3b68a3
Fixes
Reshrahim 2699f36
Fixes
Reshrahim a35a37b
Add terraform recipes
Reshrahim fca31af
Spell check
Reshrahim 3bf8b15
Fix pre-reqs
Reshrahim 78813cf
Fix pre-reqs
Reshrahim 7d1543e
Fix order
Reshrahim 3c7e7e5
Fix env variables
Reshrahim 427f2c1
Fix env variables
Reshrahim a5b140d
Add app
Reshrahim 603f930
Update tf Recipe
Reshrahim 8d62a89
Fix typo
Reshrahim 64ddd92
Fix typo
Reshrahim e71d1de
Add tf example
Reshrahim 9c56a7e
Update docs/content/tutorials/tutorial-resource-type/index.md
Reshrahim ed3045e
Add tf example
Reshrahim a4cbc99
tf module sources
Reshrahim 9e5d3ff
update tf
Reshrahim 6ca5293
Update index.md
jonvsm 39b7434
Add application flag
Reshrahim 6e529cc
Merge branch 're/udt' of https://github.com/radius-project/docs into …
Reshrahim d5ecdf7
Update docs for v0.46.0
rad-ci-bot d24985b
Add customizable property size to the definitions
Reshrahim 55d7638
Merge branch 'edge' into re/udt
Reshrahim 0af86b3
Add recipe outputs changes
Reshrahim ceea7a1
Merge branch 're/udt' of https://github.com/radius-project/docs into …
Reshrahim 4c8530a
Add warning
Reshrahim 1c57ed8
Add app graph
Reshrahim 28dd461
swapping out for correct demo-dashboard-appgraph
jonvsm 42f46b8
rename namespace and app defn
Reshrahim 00024be
Rename to types.yaml
Reshrahim 27e88c3
Reove mycompany refernce
Reshrahim 506eebe
Merge branch 'edge' into re/udt
Reshrahim 19bb64b
Added composite recipe tutorial
zachcasper 4bcc253
Updated all three tuturials to work together
zachcasper 4e2eef5
Merge branch 'edge' into re/udt
Reshrahim b33e9af
Spellcheck
Reshrahim 518382b
Spell check and Bicep validation fix
Reshrahim fc130b3
Minor edits
Reshrahim 1f300b0
Merge branch 're/udt' of https://github.com/radius-project/docs into …
zachcasper 9b02074
Updated diagrams
zachcasper 03b933a
Minor edits
Reshrahim 5733cd8
Update body-end.html
Reshrahim df2eb48
Link updates
Reshrahim 846f2c9
Update config.toml
Reshrahim af3a1bc
Lowercased webservices to render properly
zachcasper 1f8c18b
Resolved comments from Will
zachcasper 2d1b022
Spelling
zachcasper 1ec74ed
Spelling
zachcasper eb9f432
Spelling
zachcasper 37d1ff3
Fixed case for postgresql.bicep
zachcasper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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,228 @@ | ||
--- | ||
type: docs | ||
title: "Tutorial: Create a composite Recipe" | ||
linkTitle: "Create a composite Recipe" | ||
description: "Learn how to create a composite recipe for a custom resource type" | ||
weight: 140 | ||
categories: ["Tutorial"] | ||
--- | ||
## Overview | ||
|
||
This tutorial introduces composite Recipes. Rather than being composed of infrastructure or cloud resources like typical Recipes, composite Recipes are composed of other Radius resource types. Composite Recipes are authored in Bicep and can include any Radius resource types including built-in types, other custom types, AWS types, and/or Azure types. | ||
|
||
The previous tutorial demonstrated how to define a custom resource type for a PostgreSQL database, author a Recipe for deploying the database on Kubernetes, and adding the new Resource Type to an application. The sample Todo List application used the built-in Containers resource type for the frontend service. This tutorial continues using the same application but extends the Containers resource type with additional functionality. | ||
|
||
This tutorial demonstrates: | ||
|
||
* Creating a web service custom resource type which adds an `ingress` property to the Containers schema | ||
* Creating a composite Recipe in Bicep which creates a Gateway resource when the ingress property is true | ||
* Modifying the Todo List application to use the new web service | ||
|
||
{{< image src="tutorial3.png" alt="Diagram of the Todo List application with using a web service" width=600px >}} | ||
|
||
## Prerequisites | ||
|
||
This tutorial assumes you have completed the [Add a custom resource type]({{< ref "/tutorials/custom-resource-type" >}}) tutorial and have the demo application deployed with a PostgreSQL database and have Radius installed and configured. | ||
|
||
Composite Recipes are only written in Bicep. If you used Terraform in the previous tutorial for your Recipes, you will need an OCI registry to store your Recipe. While Terraform-based Recipes are stored in Git, Bicep-based Recipes can only be published to OCI registry. | ||
|
||
## Step 1: Create the web service resource type | ||
|
||
Create or modify the `types.yaml` file so that it has both the `postgreSQL` type from the previous tutorial and the new `webServices` type. The schema for the new web services resource type is lengthy, so it is best to download the fully prepared file with both resource types. | ||
|
||
{{< button text="Download types.yaml" link="snippets/types.yaml" newtab="true" >}} | ||
|
||
This web services schema is simpler than it appears: | ||
|
||
* `environment` and `application` have the same purpose as in the previous PostgreSQL example. These properties are on all resource types. | ||
* `connections` is used to create dependencies, see [How-To: Connect to dependencies]({{< ref "guides/author-apps/containers/howto-connect-dependencies" >}}) for more details | ||
* `ingress` is the first property the developer can set. The purpose of this property is to expose an option for developers to specify if the web service is accessible to connections from outside the cluster. This functionality will be implemented in the Recipe in step 3. | ||
* `container` is a duplication of the Containers schema. Since the web service resource type extended Containers, the original schema must be included here. As you will see when implementing the Recipe, duplicating the Containers schema exactly makes it simple to pass multiple properties in only a few lines of code. | ||
|
||
Create the resource type using the [rad resource-type create]({{< ref rad_resource-type_create >}}) command. | ||
|
||
```bash | ||
rad resource-type create webServices -f types.yaml | ||
``` | ||
|
||
``` | ||
$ rad resource-type create webServices -f types.yaml | ||
Resource provider "Radius.Resources" found. Registering resource type "webServices". | ||
Creating resource type Radius.Resources/webServices with capabilities SupportsRecipes | ||
Creating API Version Radius.Resources/webServices@2023-10-01-preview | ||
Updating location Radius.Resources/global with new resource type | ||
Resource type Radius.Resources/webServices created successfully | ||
|
||
TYPE NAMESPACE APIVERSION | ||
Radius.Resources/webServices Radius.Resources ["2023-10-01-preview"] | ||
``` | ||
|
||
You can confirm the resource type was created using [`rad resource-type list`]({{< ref rad_resource-type_list >}}) command. | ||
|
||
```bash | ||
rad resource-type list | ||
``` | ||
|
||
``` | ||
$ rad resource-type list | ||
TYPE NAMESPACE APIVERSION | ||
... | ||
Radius.Resources/postgreSQL Radius.Resources ["2023-10-01-preview"] | ||
Radius.Resources/webServices Radius.Resources ["2023-10-01-preview"] | ||
``` | ||
|
||
## Step 2: Update the Bicep extension | ||
|
||
Generate the Bicep extension using the [rad bicep publish-extension]({{< ref rad_bicep_publish-extension >}}) command. | ||
|
||
```bash | ||
rad bicep publish-extension -f types.yaml --target radiusResources.tgz | ||
``` | ||
``` | ||
$ rad bicep publish-extension -f types.yaml --target radiusResources.tgz | ||
Writing types to /var/folders/w8/89pqzjp52pbg4g256z9cpkww0000gn/T/bicep-extension-542196227/types.json | ||
Writing index to /var/folders/w8/89pqzjp52pbg4g256z9cpkww0000gn/T/bicep-extension-542196227/index.json | ||
Writing documentation to /var/folders/w8/89pqzjp52pbg4g256z9cpkww0000gn/T/bicep-extension-542196227/index.md | ||
WARNING: The 'publish-extension' CLI command group is an experimental feature. Experimental features should be enabled for testing purposes only, as there are no guarantees about the quality or stability of these features. Do not enable these settings for any production usage, or your production environment may be subject to breaking. | ||
Successfully published Bicep extension "types.yaml" to "radiusResources.tgz" | ||
``` | ||
|
||
Since the `bicepconfig.json` file was modified in the previous tutorial, it does not need to be further modified. | ||
|
||
## Step 3: Create, publish, and register the composite Recipe | ||
|
||
The previous tutorial demonstrated deploying a resource using Terraform or Bicep resource providers such as the Kubernetes provider. This tutorial creates a composite Recipes which uses only built-in Radius types. These composite Recipes are only possible using Bicep. | ||
|
||
1. Create a new file called `webservices.bicep` and add the following: | ||
|
||
{{% rad file="snippets/webservices.bicep" lang="bicep" embed=true %}} | ||
|
||
Notice that the `container` and `connections` properties are passed to the `Applications.Core/containers` built-in type using a single line. | ||
|
||
1. Publish the Recipe to an OCI registry. Make sure to replace `host` and `registry` with your container registry. | ||
|
||
```bash | ||
rad bicep publish --file webservices.bicep --target br:<host>/<registry>/webservices:latest | ||
``` | ||
``` | ||
$ rad bicep publish --file webservices.bicep --target br:<host>/<registry>/tutorial/webservices:latest | ||
Building webservices.bicep... | ||
WARNING: The following experimental Bicep features have been enabled: Extensibility. Experimental features should be enabled for testing purposes only, as there are no guarantees about the quality or stability of these features. Do not enable these settings for any production usage, or your production environment may be subject to breaking. | ||
Pushed to <host>/<registry>/webservices@... | ||
|
||
Successfully published Bicep file "webservices.bicep" to "<host>/<registry>/tutorial/webservices:latest" | ||
``` | ||
|
||
1. Register the Bicep template as the `default` Recipe in the `default` environment. | ||
|
||
```bash | ||
rad recipe register default --environment default \ | ||
--resource-type Radius.Resources/webServices \ | ||
--template-kind bicep \ | ||
--template-path <host>/<registry>/webservices:latest | ||
``` | ||
``` | ||
Successfully linked recipe "default" to environment "default" | ||
``` | ||
|
||
You can confirm the Recipe was registered using `rad recipe list` command. | ||
zachcasper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```bash | ||
rad recipe list | ||
``` | ||
``` | ||
rad recipe list | ||
RECIPE TYPE TEMPLATE KIND TEMPLATE VERSION TEMPLATE | ||
... | ||
default Radius.Resources/webServices bicep <host>/<registry>/webservices:latest | ||
default Radius.Resources/postgreSQL terraform git::https://github.com/<github-user-name>/recipes.git//kubernetes/postgres | ||
... | ||
``` | ||
|
||
## Step 4: Replace the container resource with a web service | ||
|
||
1. Using the same `app.bicep` file, change the resource type for the `demo` resource from `Applications.Core/containers` to `Radius.Resources/webServices`. | ||
|
||
```diff | ||
- resource demo 'Applications.Core/containers@2023-10-01-preview' = { | ||
+ resource demo 'Radius.Resources/webServices@2023-10-01-preview' = { | ||
``` | ||
|
||
1. Add `ingress: true` to the demo resource so that a Gateway gets deployed as part of the web service. The web service also needs an environment property similar to the database custom resource. | ||
|
||
```diff | ||
resource demo 'Radius.Resources/webServices@2023-10-01-preview' = { | ||
name: 'demo' | ||
properties: { | ||
application: application | ||
+ environment: environment | ||
+ ingress: true | ||
``` | ||
|
||
1. Since the web service resource type has a built-in Gateway, remove the Gateway resource. | ||
|
||
```diff | ||
- resource gateway 'Applications.Core/gateways@2023-10-01-preview' = { | ||
- name: 'gateway' | ||
- properties: { | ||
- application: application | ||
- routes: [ | ||
- { | ||
- path: '/' | ||
- destination: 'http://demo:3000' | ||
- } | ||
- ] | ||
- } | ||
- } | ||
``` | ||
|
||
1. Run the application using `rad run`. | ||
|
||
```bash | ||
rad deploy app.bicep | ||
``` | ||
``` | ||
$ rad deploy app.bicep | ||
Building app.bicep... | ||
WARNING: The following experimental Bicep features have been enabled: Extensibility. Experimental features should be enabled for testing purposes only, as there are no guarantees about the quality or stability of these features. Do not enable these settings for any production usage, or your production environment may be subject to breaking. | ||
Deploying template 'app.bicep' for application 'todolist' and environment '/planes/radius/local/resourceGroups/default/providers/Applications.Core/environments/default' from workspace 'default'... | ||
|
||
Deployment In Progress... | ||
|
||
Completed postgresql Radius.Resources/postgreSQL | ||
Completed backend Applications.Core/containers | ||
Completed demo Radius.Resources/webServices | ||
|
||
Deployment Complete | ||
|
||
Resources: | ||
backend Applications.Core/containers | ||
postgresql Radius.Resources/postgreSQL | ||
demo Radius.Resources/webServices | ||
``` | ||
|
||
1. Unlike before, the Gateway URL is not automatically shown. Use the `rad resource show` command to get the URL of the application. | ||
|
||
```bash | ||
rad resource show Applications.Core/gateways gateway -o json | grep url | ||
``` | ||
``` | ||
"url": "http://gateway.todolist.172.18.0.6.nip.io" | ||
``` | ||
|
||
zachcasper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
1. Open the URL in your browser. The application has not changed despite changing the demo from a container to a web service resource and removing the gateway. | ||
|
||
## Step 6: Clean up | ||
zachcasper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
1. Delete the application and all resources created by the application. | ||
|
||
```bash | ||
rad application delete todolist | ||
``` | ||
|
||
1. Delete the PostgreSQL and web service resource types. | ||
|
||
```bash | ||
rad resource-type delete Radius.Resources/postgreSQL | ||
rad resource-type delete Radius.Resources/webServices | ||
``` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.