How-To: Use local-dev Recipes

Learn how to use the pre-defined Recipes that makes it easy to run dependencies in your application.

Local development environments created by the rad init command include a set of pre-defined Recipes called local-dev Recipes, to get lightweight containerized infrastructure up and running quickly. This guide teaches how to use a local dev recipe to deploy a Redis container to a Kubernetes cluster.

Prerequisites

Step 1: Initialize a Radius environment

  1. Begin in a new directory for your application:

    mkdir recipes
    cd recipes
    
  2. Initialize a new dev environment:

    rad init
    

    Select ‘No’ when prompted to create an application.

  3. Use rad recipe list to view the Recipes in your environment:

    rad recipe list 
    

    You should see a table of available Recipes:

    NAME      TYPE                                    TEMPLATE KIND  TEMPLATE VERSION  TEMPLATE
    default   Applications.Datastores/sqlDatabases    bicep                            ghcr.io/radius-project/recipes/local-dev/sqldatabases:latest
    default   Applications.Messaging/rabbitMQQueues   bicep                            ghcr.io/radius-project/recipes/local-dev/rabbitmqqueues:latest
    default   Applications.Dapr/pubSubBrokers         bicep                            ghcr.io/radius-project/recipes/local-dev/pubsubbrokers:latest
    default   Applications.Dapr/secretStores          bicep                            ghcr.io/radius-project/recipes/local-dev/secretstores:latest
    default   Applications.Dapr/stateStores           bicep                            ghcr.io/radius-project/recipes/local-dev/statestores:latest
    default   Applications.Datastores/mongoDatabases  bicep                            ghcr.io/radius-project/recipes/local-dev/mongodatabases:latest
    default   Applications.Datastores/redisCaches     bicep                            ghcr.io/radius-project/recipes/local-dev/rediscaches:latest
    

    Visit the Recipes repo to learn more about the definition of these local-dev recipe templates.

    When a Recipe is named “default” it will be used automatically when a resource doesn’t specify a Recipe name. This makes it easy for applications to fully defer to the Environment for how to manage infrastructure.

Step 2: Create a bicepconfig.json in your application’s directory

  1. Create a bicepconfig.json in your application’s directory. release-version should correspond to the current release version in the form of major.minor (e.g. 0.36).
{
	"experimentalFeaturesEnabled": {
		"extensibility": true,
		"extensionRegistry": true,
		"dynamicTypeLoading": true
	},
	"extensions": {
		"radius": "br:biceptypes.azurecr.io/radius:<release-version>",
		"aws": "br:biceptypes.azurecr.io/aws:<release-version>"
	}
}

More information on how to setup a bicepconfig.json can be found here

Step 3: Define your application

Create a file named app.bicep with the following set of resources:

extension radius

@description('The ID of your Radius environment. Automatically injected by the rad CLI.')
param environment string

@description('The ID of your Radius application. Automatically injected by the rad CLI.')
param application string

resource frontend 'Applications.Core/containers@2023-10-01-preview' = {
  name: 'frontend'
  properties: {
    application: application
    container: {
      image: 'ghcr.io/radius-project/samples/demo:latest'
    }
    connections: {
      // Define a connection to the redis container
      // Automatically injects conneciton information into the container
      redis: {
        source: db.id
      }
    }
  }
}

resource db 'Applications.Datastores/redisCaches@2023-10-01-preview' = {
  name: 'db'
  properties: {
    environment: environment
    application: application
    // recipe is not specified, so it uses 'default' if present
  }
}

Note that no Recipe name is specified within ‘db’, so it will be using the default Recipe for Redis in your environment.

Step 4: Deploy your application

  1. Run rad run to deploy your application:

    rad run ./app.bicep -a local-dev-app
    

    You should see the following output:

    Building app.bicep...
    Deploying template './app.bicep' for application 'local-dev-app' and environment 'default' from workspace 'default'...
    
    Deployment In Progress...
    
    Completed            db              Applications.Datastores/redisCaches
    Completed            frontend        Applications.Core/containers
    
    Deployment Complete
    
    Resources:
       frontend        Applications.Core/containers
       db              Applications.Datastores/redisCaches
    
     Starting log stream...
    

    Your application is now deployed and running in your Kubernetes cluster.

Step 5: Verify Redis containers are deployed

  1. Visit http://localhost:3000 in your browser.

    You can now see both the environment variables of your container under Radius Connections as well as interact with the Todo App and add/remove items in it as wanted:

  2. List your Kubernetes Pods to see the infrastructure containers deployed by the Recipe:

    kubectl get pods -n default-local-dev-app
    

    You will see your ‘frontend’ container, along with the Redis cache that was automatically created by the default local-dev Recipe:

    NAME                                   READY   STATUS    RESTARTS   AGE
    frontend-6d447f5994-pnmzv              1/1     Running   0          13m
    redis-ymbjcqyjzwkpg-66fdbf8bb6-brb6q   2/2     Running   0          13m