diff --git a/docs/config.toml b/docs/config.toml index c5fb08957..f106191f5 100644 --- a/docs/config.toml +++ b/docs/config.toml @@ -62,7 +62,6 @@ tag = "tags" [params] copyright = "Radius" - version = "edge" tag_version = "latest" chart_version = "0.19.0" diff --git a/docs/content/guides/author-apps/containers/howto-connect-dependencies/demo-with-redis-screenshot.png b/docs/content/guides/author-apps/containers/howto-connect-dependencies/demo-with-redis-screenshot.png new file mode 100644 index 000000000..9aa700ed3 Binary files /dev/null and b/docs/content/guides/author-apps/containers/howto-connect-dependencies/demo-with-redis-screenshot.png differ diff --git a/docs/content/guides/author-apps/containers/howto-connect-dependencies/index.md b/docs/content/guides/author-apps/containers/howto-connect-dependencies/index.md new file mode 100644 index 000000000..d9875dc44 --- /dev/null +++ b/docs/content/guides/author-apps/containers/howto-connect-dependencies/index.md @@ -0,0 +1,90 @@ +--- +type: docs +title: "How-To: Connect to dependencies" +linkTitle: "Connect to dependencies" +description: "Learn how to connect to dependencies in your application via connections" +weight: 200 +categories: "How-To" +tags: ["containers"] +--- + +This how-to guide will teach how to connect to your dependencies via [connections]({{< ref "guides/author-apps/containers#connections" >}}) + +## Prerequisites + +- [Radius CLI]({{< ref "installation#step-1-install-the-rad-cli" >}}) +- [Radius environment]({{< ref "installation#step-3-initialize-the-radius-control-plane-and-the-radius-environment" >}}) + +## Step 1: View the container definition + +Open the `app.bicep` and view the [container]({{< ref "guides/author-apps/containers" >}}): + +{{< rad file="snippets/app.bicep" embed=true >}} + +## Step 2: Add a Redis cache as a dependency + +Next, add to `app.bicep` a [Redis cache]({{< ref "/guides/author-apps/portable-resources/overview" >}}), leveraging the default "local-dev" Recipe: + +{{< rad file="snippets/app-with-redis.bicep" embed=true marker="//DB" >}} + +## Step 3: Connect to the Redis cache + +Connections from a container to a resource result in environment variables for connection information automatically being set on the container. Update your container definition to add a connection to the new Redis cache: + +{{< rad file="snippets/app-with-redis.bicep" embed=true marker="//CONTAINER" markdownConfig="{linenos=table,hl_lines=[\"13-17\"],linenostart=7}" >}} + +## 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: + + Screenshot of the demo app with all environment variables + +## Step 5: View the Application Connections + +Radius Connections are more than just environment variables and configuration. You can also access the "application graph" and understand the connections within your application with the following command: + +```bash +rad app connections +``` + +You should see the following output, detailing the connections between the `demo` container and the `db` Redis cache, along with information about the underlying Kubernetes resources running the app: + +``` +Displaying application: demo + +Name: demo (Applications.Core/containers) +Connections: + demo -> db (Applications.Datastores/redisCaches) +Resources: + demo (kubernetes: apps/Deployment) + demo (kubernetes: core/Secret) + demo (kubernetes: core/Service) + demo (kubernetes: core/ServiceAccount) + demo (kubernetes: rbac.authorization.k8s.io/Role) + demo (kubernetes: rbac.authorization.k8s.io/RoleBinding) + +Name: db (Applications.Datastores/redisCaches) +Connections: + demo (Applications.Core/containers) -> db +Resources: + redis-r5tcrra3d7uh6 (kubernetes: apps/Deployment) + redis-r5tcrra3d7uh6 (kubernetes: core/Service) +``` + +## Cleanup + +Run `rad app delete` to cleanup your Radius application, container, and Redis cache: + +```bash +rad app delete -a demo +``` + +## Further reading + +- [Connections]({{< ref "guides/author-apps/containers/overview#connections" >}}) +- [Container schema]({{< ref container-schema >}}) diff --git a/docs/content/guides/author-apps/containers/howto-connect-dependencies/snippets/app-with-redis.bicep b/docs/content/guides/author-apps/containers/howto-connect-dependencies/snippets/app-with-redis.bicep new file mode 100644 index 000000000..423f0810a --- /dev/null +++ b/docs/content/guides/author-apps/containers/howto-connect-dependencies/snippets/app-with-redis.bicep @@ -0,0 +1,40 @@ +// Import the set of Radius resources (Applications.*) into Bicep +import radius as radius + +@description('The app ID of your Radius Application. Set automatically by the rad CLI.') +param application string + +//CONTAINER +resource demo 'Applications.Core/containers@2023-10-01-preview' = { + name: 'demo' + properties: { + application: application + container: { + image: 'radius.azurecr.io/samples/demo:latest' + ports: { + web: { + containerPort: 3000 + } + } + } + connections: { + redis: { + source: db.id + } + } + } +} +//CONTAINER + +//DB +@description('The env ID of your Radius Environment. Set automatically by the rad CLI.') +param environment string + +resource db 'Applications.Datastores/redisCaches@2023-10-01-preview' = { + name: 'db' + properties: { + application: application + environment: environment + } +} +//DB diff --git a/docs/content/guides/author-apps/containers/howto-connect-dependencies/snippets/app.bicep b/docs/content/guides/author-apps/containers/howto-connect-dependencies/snippets/app.bicep new file mode 100644 index 000000000..eaae366b4 --- /dev/null +++ b/docs/content/guides/author-apps/containers/howto-connect-dependencies/snippets/app.bicep @@ -0,0 +1,14 @@ +import radius as rad + +@description('The app ID of your Radius application. Set automatically by the rad CLI.') +param application string + +resource container 'Applications.Core/containers@2023-10-01-preview' = { + name: 'demo' + properties: { + application: application + container: { + image: 'radius.azurecr.io/samples/demo:latest' + } + } +} diff --git a/docs/content/guides/author-apps/containers/howto-environment-variables/icon.png b/docs/content/guides/author-apps/containers/howto-environment-variables/icon.png deleted file mode 100644 index b2fcdc82b..000000000 Binary files a/docs/content/guides/author-apps/containers/howto-environment-variables/icon.png and /dev/null differ diff --git a/docs/content/guides/author-apps/containers/howto-environment-variables/index.md b/docs/content/guides/author-apps/containers/howto-environment-variables/index.md deleted file mode 100644 index 890a3bdd5..000000000 --- a/docs/content/guides/author-apps/containers/howto-environment-variables/index.md +++ /dev/null @@ -1,88 +0,0 @@ ---- -type: docs -title: "How-To: Set environment variables on a container" -linkTitle: "Set Env vars" -description: "Learn how to set environment variables manually and through connections" -weight: 400 -slug: "environment-variables" -categories: "How-To" -tags: ["containers"] ---- - -This how-to guide will teach you: - -1. How to set environment variables manually -1. How to set environment variables through connections - -## Prerequisites - -- [Radius CLI]({{< ref "getting-started" >}}) -- [Radius Environment]({{< ref "/guides/deploy-apps/environments/overview" >}}) - -## Step 1: Model an app and container - -Create a new file named `app.bicep` and add an application and a [container]({{< ref "guides/author-apps/containers" >}}): - -{{< rad file="snippets/1-app.bicep" embed=true >}} - -The image `radius.azurecr.io/quickstarts/envvars` simply prints out the environment variables that are set on the container. - -## Step 2: Manually set environment variables - -Add an `env` property which will contain a list of environment variables to set. Within `env` set the `FOO` environment variable to the string `bar` and the `BAZ` environment variable to the value of `app.name`: - -{{< rad file="snippets/2-app.bicep" embed=true marker="//CONTAINER" >}} - -## Step 3: Deploy your app - -1. Deploy your application to your environment: - - ```bash - rad deploy ./app.bicep - ``` -1. Port-forward the container to your machine with [`rad resource expose`]({{< ref rad_resource_expose >}}): - - ```bash - rad resource expose containers mycontainer -a myapp --port 5000 - ``` -1. Visit [localhost:5000](http://localhost:5000) in your browser. You should see the following page: - - Screenshot of the app printing the environment variables - - Here you can see the environment variables `FOO` and `BAZ`, with their accompanying values. - -## Step 4: Add a Mongo database - -Next, add to `app.bicep` a [Mongo database]({{< ref portable-resources >}}), leveraging the default "dev" Recipe: - -{{< rad file="snippets/3-app.bicep" embed=true marker="//LINK" >}} - -## Step 5: Connect to the Mongo database - -Connections from a container to a resource result in environment variables for connection information automatically being set on the container. Update your container definition to add a connection to the new Mongo database: - -{{< rad file="snippets/3-app.bicep" embed=true marker="//CONTAINER" >}} - -## Step 6: Deploy your app - -1. Deploy your application to your environment: - - ```bash - rad deploy ./app.bicep - ``` -1. Port-forward the container to your machine: - - ```bash - rad resource expose containers mycontainer -a myapp --port 5000 - ``` -1. Visit [localhost:5000](http://localhost:5000) in your browser. You should see the following page, now showing injected environment variables: - - Screenshot of the app printing all the environment variables - -## Cleanup - -Run `rad app delete` to cleanup your Radius Application, container, and link: - -```bash -rad app delete -a myapp -``` diff --git a/docs/content/guides/author-apps/containers/howto-environment-variables/screenshot-all.jpg b/docs/content/guides/author-apps/containers/howto-environment-variables/screenshot-all.jpg deleted file mode 100644 index c4b6b6b75..000000000 Binary files a/docs/content/guides/author-apps/containers/howto-environment-variables/screenshot-all.jpg and /dev/null differ diff --git a/docs/content/guides/author-apps/containers/howto-environment-variables/screenshot.jpg b/docs/content/guides/author-apps/containers/howto-environment-variables/screenshot.jpg deleted file mode 100644 index 3d2fff4fd..000000000 Binary files a/docs/content/guides/author-apps/containers/howto-environment-variables/screenshot.jpg and /dev/null differ diff --git a/docs/content/guides/author-apps/containers/howto-environment-variables/snippets/1-app.bicep b/docs/content/guides/author-apps/containers/howto-environment-variables/snippets/1-app.bicep deleted file mode 100644 index 1b2c4b40a..000000000 --- a/docs/content/guides/author-apps/containers/howto-environment-variables/snippets/1-app.bicep +++ /dev/null @@ -1,20 +0,0 @@ -import radius as rad - -param environment string - -resource app 'Applications.Core/applications@2023-10-01-preview' = { - name: 'myapp' - properties: { - environment: environment - } -} - -resource container 'Applications.Core/containers@2023-10-01-preview' = { - name: 'mycontainer' - properties: { - application: app.id - container: { - image: 'radius.azurecr.io/quickstarts/envvars:edge' - } - } -} diff --git a/docs/content/guides/author-apps/containers/howto-environment-variables/snippets/2-app.bicep b/docs/content/guides/author-apps/containers/howto-environment-variables/snippets/2-app.bicep deleted file mode 100644 index 769f2cbf4..000000000 --- a/docs/content/guides/author-apps/containers/howto-environment-variables/snippets/2-app.bicep +++ /dev/null @@ -1,26 +0,0 @@ -import radius as rad - -param environment string - -resource app 'Applications.Core/applications@2023-10-01-preview' = { - name: 'myapp' - properties: { - environment: environment - } -} - -//CONTAINER -resource container 'Applications.Core/containers@2023-10-01-preview' = { - name: 'mycontainer' - properties: { - application: app.id - container: { - image: 'radius.azurecr.io/quickstarts/envvars:edge' - env: { - FOO: 'BAR' - BAZ: app.name - } - } - } -} -//CONTAINER diff --git a/docs/content/guides/author-apps/containers/howto-environment-variables/snippets/3-app.bicep b/docs/content/guides/author-apps/containers/howto-environment-variables/snippets/3-app.bicep deleted file mode 100644 index 85a561da6..000000000 --- a/docs/content/guides/author-apps/containers/howto-environment-variables/snippets/3-app.bicep +++ /dev/null @@ -1,42 +0,0 @@ -import radius as rad - -param environment string - -resource app 'Applications.Core/applications@2023-10-01-preview' = { - name: 'myapp' - properties: { - environment: environment - } -} - -//CONTAINER -resource container 'Applications.Core/containers@2023-10-01-preview' = { - name: 'mycontainer' - properties: { - application: app.id - container: { - image: 'radius.azurecr.io/quickstarts/envvars:edge' - env: { - FOO: 'BAR' - BAZ: app.name - } - } - connections: { - myconnection: { - source: mongoDatabase.id - } - } - } -} -//CONTAINER - -//LINK -resource mongoDatabase 'Applications.Datastores/mongoDatabases@2023-10-01-preview' = { - name: 'mongo-db' - properties: { - environment: environment - application: app.id - // Use the "default" Recipe to provision the MongoDB - } -} -//LINK diff --git a/docs/content/guides/author-apps/containers/overview/index.md b/docs/content/guides/author-apps/containers/overview/index.md index 1e88f8438..35665aad8 100644 --- a/docs/content/guides/author-apps/containers/overview/index.md +++ b/docs/content/guides/author-apps/containers/overview/index.md @@ -103,7 +103,9 @@ For example, adding a connection called `database` that connects to a MongoDB re | `CONNECTION_DATABASE_USERNAME` | Username of the target database | | `CONNECTION_DATABASE_PASSWORD` | Password of the target database | -Alternatively, if you already have another convention you would like to follow or if you just prefer to be explicit, you may ignore the values generated by a connection and instead override it by setting your own environment variable values. Refer to the [environment variables how-to guide]({{< ref howto-environment-variables >}}) for more details. +Alternatively, if you already have another convention you would like to follow or if you just prefer to be explicit, you may ignore the values generated by a connection and instead override it by setting your own environment variable values. + + ## Extensions