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 how-to guide on Connect to dependencies #807

Merged
merged 26 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f3d0056
Add supported resource types
Reshrahim Sep 28, 2023
96850dd
Merge branch 'edge' of https://github.com/radius-project/docs into edge
Reshrahim Sep 29, 2023
37969c2
Merge branch 'edge' of https://github.com/radius-project/docs into edge
Reshrahim Oct 4, 2023
582b65e
Merge branch 'edge' of https://github.com/radius-project/docs into edge
Reshrahim Oct 4, 2023
29eb96f
Add how-to guide on connect to dependencies
Reshrahim Oct 4, 2023
21d0583
Remove link references
Reshrahim Oct 4, 2023
a91765e
Add connections step
Reshrahim Oct 5, 2023
adbc507
Fix spelling
Reshrahim Oct 5, 2023
5e67fc1
Merge branch 'edge' of https://github.com/radius-project/docs into edge
Reshrahim Oct 5, 2023
30d0730
Merge branch 'edge' of https://github.com/radius-project/docs into edge
Reshrahim Oct 6, 2023
e8379af
Merge branch 'edge' of https://github.com/radius-project/docs into edge
Reshrahim Oct 9, 2023
d4abfae
Address feedback
Reshrahim Oct 10, 2023
8ce197e
Address feedback
Reshrahim Oct 10, 2023
ffd2696
Remove env variables quickstart
Reshrahim Oct 10, 2023
13d782b
Fix ref faiure
Reshrahim Oct 11, 2023
1179473
Merge branch 'edge' into reshma/con
Reshrahim Oct 11, 2023
eb906f1
Address feedback
Reshrahim Oct 12, 2023
78d26fe
Remove spelling fix
Reshrahim Oct 12, 2023
cdcb8df
Merge branch 'edge' into reshma/con
Reshrahim Oct 12, 2023
124fe17
remove spelling fix
Reshrahim Oct 12, 2023
c911d29
resolve conflicts
Reshrahim Oct 12, 2023
ea38be3
Fix image to latest
Reshrahim Oct 12, 2023
3cb7111
Minor tweaks
Reshrahim Oct 12, 2023
c553a9f
Apply suggestions from code review
Reshrahim Oct 12, 2023
89f7be1
Update docs/content/guides/author-apps/containers/howto-connect-depen…
Reshrahim Oct 12, 2023
8f0b8d6
Resolve merge conflicts
Reshrahim Oct 12, 2023
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: 1 addition & 1 deletion .github/config/en-custom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -948,4 +948,4 @@ ConfigMap
CRD
composable
gatewaydemo
tlsdemo
tlsdemo
1 change: 0 additions & 1 deletion docs/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ tag = "tags"

[params]
copyright = "Radius"

version = "edge"
tag_version = "latest"
chart_version = "0.19.0"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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" >}}):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Open the `app.bicep` and view the [container]({{< ref "guides/author-apps/containers" >}}):
Create a file named `app.bicep` and add a [container]({{< ref "guides/author-apps/containers" >}}):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user would create a Radius environment as part of the prereqs where they select yes to set up the app. So the app.bicep will have the demo container definition


{{< 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
Reshrahim marked this conversation as resolved.
Show resolved Hide resolved
```
1. Visit [localhost:3000](http://localhost:3000) in your browser. You should see the following page, now showing injected environment variables:

<img src="./demo-with-redis-screenshot.png" alt="Screenshot of the demo app with all environment variables" width=1000px />

Reshrahim marked this conversation as resolved.
Show resolved Hide resolved
## Step 5: View the application connections
Reshrahim marked this conversation as resolved.
Show resolved Hide resolved

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:
Reshrahim marked this conversation as resolved.
Show resolved Hide resolved

```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
```
Reshrahim marked this conversation as resolved.
Show resolved Hide resolved

## Further reading

- [Connections]({{< ref "guides/author-apps/containers/overview#connections" >}})
- [Container schema]({{< ref container-schema >}})
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.')
Reshrahim marked this conversation as resolved.
Show resolved Hide resolved
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
param environment string
Reshrahim marked this conversation as resolved.
Show resolved Hide resolved
resource db 'Applications.Datastores/redisCaches@2023-10-01-preview' = {
name: 'db'
properties: {
application: application
environment: environment
}
}
//DB
Original file line number Diff line number Diff line change
@@ -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'
}
}
}
Binary file not shown.
Reshrahim marked this conversation as resolved.
Outdated
Show resolved Hide resolved

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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.

<!-- For more information on how to add connections, refer to the [connect to dependencies how-to guide]("guides/author-apps/containers/how-to-connect-dependencies"). -->

## Extensions

Expand Down
Loading