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 8 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 @@ -946,4 +946,5 @@ XRay
PodSpec
ConfigMap
CRD
composable
composable
mycontainer
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,95 @@
---
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 an application and 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 "portable-resources#overview" >}}), leveraging the default "dev" Recipe:
Reshrahim marked this conversation as resolved.
Show resolved Hide resolved

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

## Step 4: 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
Reshrahim marked this conversation as resolved.
Show resolved Hide resolved
```
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#connections" >}})
Reshrahim marked this conversation as resolved.
Show resolved Hide resolved
- [Container schema]({{< ref container-schema >}})

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ resource container 'Applications.Core/containers@2023-10-01-preview' = {
application: app.id
container: {
image: 'radius.azurecr.io/quickstarts/envvars:edge'
env: {
FOO: 'BAR'
BAZ: app.name
}
}
connections: {
myconnection: {
Expand All @@ -30,7 +26,7 @@ resource container 'Applications.Core/containers@2023-10-01-preview' = {
}
//CONTAINER

//LINK
//DB
resource mongoDatabase 'Applications.Datastores/mongoDatabases@2023-10-01-preview' = {
name: 'mongo-db'
properties: {
Expand All @@ -39,4 +35,4 @@ resource mongoDatabase 'Applications.Datastores/mongoDatabases@2023-10-01-previe
// Use the "default" Recipe to provision the MongoDB
}
}
//LINK
//DB
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import radius as rad

param environment string

resource app 'Applications.Core/applications@2023-10-01-preview' = {
name: 'myapp'
properties: {
environment: environment
}
}
Reshrahim marked this conversation as resolved.
Show resolved Hide resolved

resource container 'Applications.Core/containers@2023-10-01-preview' = {
name: 'mycontainer'
properties: {
application: app.id
container: {
image: 'radius.azurecr.io/quickstarts/envvars:edge'
Reshrahim marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Reshrahim marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ 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
weight: 300
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
1. How to set environment variables manually on a container

## Prerequisites

Expand Down Expand Up @@ -51,37 +50,9 @@ Add an `env` property which will contain a list of environment variables to set.

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:

<img src="screenshot-all.jpg" alt="Screenshot of the app printing all the environment variables" width=1000px />

## Cleanup

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

```bash
rad app delete -a myapp
Expand Down
Loading