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 13 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
3 changes: 2 additions & 1 deletion .github/config/en-custom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -947,5 +947,6 @@ PodSpec
ConfigMap
CRD
composable
mycontainer
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
Reshrahim marked this conversation as resolved.
Show resolved Hide resolved
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,89 @@
---
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: Model an app and container

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

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

## Step 2: Add a Mongo database as a dependency

Next, add to `app.bicep` a [Mongo database]({{< ref "/guides/author-apps/portable-resources/overview" >}}), leveraging the default "local-dev" Recipe:

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

## Step 3: 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/app-mongodb.bicep" embed=true marker="//CONTAINER" markdownConfig="{linenos=table,hl_lines=[\"8-12\"],linenostart=7}" >}}

## Step 4: Deploy your app

1. Run your application in your environment:

```bash
rad run ./app.bicep -a myapp
```
1. Visit [localhost:5000](http://localhost:5000) in your browser. You should see the following page, now showing injected environment variables:
Reshrahim marked this conversation as resolved.
Show resolved Hide resolved

<img src="./connections.png" alt="Screenshot of the app printing all the 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 `mycontainer` and the `db` Mongo database, along with information about the underlying Kubernetes resources running the app:

```
Displaying application: myapp

Name: mycontainer (Applications.Core/containers)
Connections:
mycontainer -> mongo-db (Applications.Datastores/mongoDatabases)
Resources:
mycontainer (kubernetes: apps/Deployment)
mycontainer (kubernetes: core/Secret)
mycontainer (kubernetes: core/ServiceAccount)
mycontainer (kubernetes: rbac.authorization.k8s.io/Role)
mycontainer (kubernetes: rbac.authorization.k8s.io/RoleBinding)

Name: mongo-db (Applications.Datastores/mongoDatabases)
Connections:
mycontainer (Applications.Core/containers) -> mongo-db
Resources:
mongo-xxx(kubernetes: apps/Deployment)
mongo-xxx(kubernetes: core/Service)
```

## Cleanup

Run `rad app delete` to cleanup your Radius application, container, and mongo database:

```bash
rad app delete -a myapp
```
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
@@ -1,25 +1,15 @@
import radius as rad

param environment string

resource app 'Applications.Core/applications@2023-10-01-preview' = {
name: 'myapp'
properties: {
environment: environment
}
}
@description('The app ID of your Radius application. Set automatically by the rad CLI.')
param application string

//CONTAINER
resource container 'Applications.Core/containers@2023-10-01-preview' = {
name: 'mycontainer'
properties: {
application: app.id
application: application
container: {
image: 'radius.azurecr.io/quickstarts/envvars:edge'
env: {
FOO: 'BAR'
BAZ: app.name
}
}
connections: {
myconnection: {
Expand All @@ -30,13 +20,16 @@ resource container 'Applications.Core/containers@2023-10-01-preview' = {
}
//CONTAINER

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

resource mongoDatabase 'Applications.Datastores/mongoDatabases@2023-10-01-preview' = {
name: 'mongo-db'
properties: {
environment: environment
application: app.id
application: application
// Use the "default" Recipe to provision the MongoDB
}
}
//LINK
//DB
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import radius as rad

param environment string

resource app 'Applications.Core/applications@2023-10-01-preview' = {
name: 'myapp'
properties: {
environment: environment
}
}
@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: 'mycontainer'
properties: {
application: app.id
application: application
container: {
image: 'radius.azurecr.io/quickstarts/envvars:edge'
Reshrahim marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
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.

Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ 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. Refer to the [connect to dependencies how-to guide]({{< ref howto-connect-dependencies >}}) for more details.

## Extensions

Expand Down
Loading