Skip to content

About

An example of reading/writing to Redis from a Container Instance in Locally

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

ooooo                                      oooo  oooo              
`888'                                      `888  `888              
 888          .ooooo.   .ooooo.   .oooo.    888   888  oooo    ooo 
 888         d88' `88b d88' `"Y8 `P  )88b   888   888   `88.  .8'
 888         888   888 888        .oP"888   888   888    `88..8'
 888       o 888   888 888   .o8 d8(  888   888   888     `888'
o888ooooood8 `Y8bod8P' `Y8bod8P' `Y888""8o o888o o888o     .8'
                                                       .o..P'
                                                       `Y8P'

Example: Deploy a Redis-backed app to Container Instances within Locally

This example shows how to deploy a sample Redis app - tombuildsstuff/builder-app to Azure Container Instances, backed by Azure Cache for Redis, on Locally Build.

The application is a small demo that reads from and writes to Redis - it stores a value in the cache and serves it back over HTTP. It's a plain 12-factor service: one image, configured entirely through environment variables. The image is built and published from the application repository; this repository is just the infrastructure that runs it.

The app authenticates to Redis with the cache's access key, passed to the container as a secure environment variable - that's what the builder-app image is written to use. (Azure Cache for Redis also supports Microsoft Entra authentication, via access-policy assignments, on every tier; Locally implements that path too. This example just uses the access key.) It connects over TLS, reading the cache host and SSL port from REDIS_HOST and REDIS_PORT. On Azure the SSL port is always 6380; on Locally the cache is served on a dynamically-allocated port, which is why the app reads it rather than assuming 6380.

Requirements

  • Locally Build.
  • Either HashiCorp Terraform or OpenTofu.
  • Either Docker or Podman (recommended).
  • The Locally Plugin for Microsoft.Cache installed (locally plugin install --name Microsoft.Cache).
  • The Locally Plugin for Microsoft.ContainerInstance installed (locally plugin install --name Microsoft.ContainerInstance).

Running the example

First up, we need to ensure our container runtime (Docker or Podman) is running, then launch Locally:

locally build

With Locally running, in another terminal we can initialise Terraform, which both downloads the providers we need and configures the module for use:

cd environments/locally
terraform init

Note

It's possible to use OpenTofu here by substituting terraform for tofu.

With Terraform initialised, we can then provision the example by running:

locally run terraform apply

Once you approve the plan and the resources have been deployed, the application is running at the URL in the outputs:

http://locally-example-redis-group-berlin.gondola.locally:8080

Open that URL in a browser and you'll see the value the app has stored in Redis.


The container's logs (including each read/write against Redis) can be followed with:

locally logs

Tearing it down

cd environments/locally
locally run terraform destroy

About

An example of reading/writing to Redis from a Container Instance in Locally

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages