Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ This repository contains comprehensive sample projects demonstrating how to deve
|-------------|-------------|
| [Function App and Storage](./samples/function-app-storage-http/dotnet/README.md) | Azure Functions App using Blob, Queue, and Table Storage |
| [Function App and Front Door](./samples/function-app-front-door/python/README.md) | Azure Functions App exposed via Front Door |
| [Function App and Managed Identities](./samples/function-app-managed-identity/python/README.md) | Azure Function App using Managed Identities |
| [Function App and Service Bus](./samples/function-app-service-bus/dotnet/README.md) | Azure Function App using Service Bus |
| [Web App and CosmosDB for MongoDB API ](./samples/web-app-cosmosdb-mongodb-api/python/README.md) | Azure Web App using CosmosDB for MongoDB API |
| [Web App and CosmosDB for NoSQL API ](./samples/web-app-cosmosdb-nosql-api/python/README.md) | Azure Web App using CosmosDB for NoSQL API |
| [Web App and Managed Identities](./samples/web-app-managed-identity/python/README.md) | Azure Web App using Managed Identities |
| [Web App and SQL Database ](./samples/web-app-sql-database/python/README.md) | Azure Web App using SQL Database |
| [ServiceBus ](./samples/servicebus/README.md) | Azure ServiceBus used by a Spring Boot application |
| [Function App and Managed Identities](./samples/function-app-managed-identity/python/README.md) | Azure Function App using Managed Identities |
| [Function App and Service Bus](./samples/function-app-service-bus/dotnet/README.md) | Azure Function App using Service Bus |
| [Web App and CosmosDB for MongoDB API ](./samples/web-app-cosmosdb-mongodb-api/python/README.md) | Azure Web App using CosmosDB for MongoDB API |
| [Web App and CosmosDB for NoSQL API ](./samples/web-app-cosmosdb-nosql-api/python/README.md) | Azure Web App using CosmosDB for NoSQL API |
| [Web App and Managed Identities](./samples/web-app-managed-identity/python/README.md) | Azure Web App using Managed Identities |
| [Web App and SQL Database ](./samples/web-app-sql-database/python/README.md) | Azure Web App using SQL Database |
| [ACI and Blob Storage](./samples/aci-blob-storage/python/README.md) | Azure Container Instances with ACR, Key Vault, and Blob Storage |
| [ServiceBus ](./samples/servicebus/README.md) | Azure ServiceBus used by a Spring Boot application |

## Sample Structure

Expand Down
6 changes: 6 additions & 0 deletions run-samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,36 @@ SAMPLES=(
"samples/servicebus/java|bash scripts/deploy.sh"
"samples/function-app-front-door/python|bash scripts/deploy_all.sh --name-prefix testafd --use-localstack|"
"samples/function-app-managed-identity/python|bash scripts/user-managed-identity.sh|bash scripts/validate.sh && bash scripts/test.sh"
"samples/function-app-service-bus/dotnet|bash scripts/deploy.sh|bash scripts/validate.sh && bash scripts/call-http-trigger.sh"
"samples/function-app-storage-http/dotnet|bash scripts/deploy.sh|bash scripts/validate.sh && bash scripts/call-http-triggers.sh"
"samples/web-app-cosmosdb-mongodb-api/python|bash scripts/deploy.sh|bash scripts/validate.sh && bash scripts/call-web-app.sh"
"samples/web-app-managed-identity/python|bash scripts/user-assigned.sh|bash scripts/validate.sh && bash scripts/call-web-app.sh"
"samples/web-app-sql-database/python|bash scripts/deploy.sh|bash scripts/validate.sh && bash scripts/get-web-app-url.sh"
"samples/aci-blob-storage/python|bash scripts/deploy.sh|bash scripts/validate.sh"
)

# 1a. Define Terraform Samples
TERRAFORM_SAMPLES=(
"samples/servicebus/java/terraform|bash deploy.sh"
"samples/function-app-managed-identity/python/terraform|bash deploy.sh"
"samples/function-app-service-bus/dotnet/terraform|bash deploy.sh"
"samples/function-app-storage-http/dotnet/terraform|bash deploy.sh"
"samples/web-app-cosmosdb-mongodb-api/python/terraform|bash deploy.sh"
"samples/web-app-managed-identity/python/terraform|bash deploy.sh"
"samples/web-app-sql-database/python/terraform|bash deploy.sh"
"samples/aci-blob-storage/python/terraform|bash deploy.sh"
)

# 1b. Define Bicep Samples
BICEP_SAMPLES=(
"samples/servicebus/java/bicep|bash deploy.sh"
#"samples/web-app-sql-database/python/bicep|bash deploy.sh"
"samples/function-app-managed-identity/python/bicep|bash deploy.sh"
"samples/function-app-service-bus/dotnet/bicep|bash deploy.sh"
"samples/function-app-storage-http/dotnet/bicep|bash deploy.sh"
"samples/web-app-cosmosdb-mongodb-api/python/bicep|bash deploy.sh"
"samples/web-app-managed-identity/python/bicep|bash deploy.sh"
"samples/aci-blob-storage/python/bicep|bash deploy.sh"
)

# Combine script-based, Terraform, and Bicep samples into one array
Expand Down
126 changes: 126 additions & 0 deletions samples/aci-blob-storage/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Vacation Planner on Azure Container Instances

A sample application demonstrating how to deploy a containerized Flask web app using four Azure services:

- **Azure Blob Storage** — Stores vacation activities as JSON blobs
- **Azure Key Vault** — Stores the storage connection string as a secret
- **Azure Container Registry (ACR)** — Hosts the Docker container image
- **Azure Container Instances (ACI)** — Runs the containerized application

## Architecture

```
┌──────────────┐ store conn ┌──────────────┐ env vars ┌──────────────┐
│ Storage │ ──── string ────► │ KeyVault │ ─────────► │ ACI │
│ Account │ │ (secrets) │ │ (container │
└──────────────┘ └──────────────┘ │ group) │
▲ │ │
│ read/write activities │ │
└────────────────────────────────────────────────────────┤ │
│ │
┌──────────────┐ image pull │ │
│ ACR │ ────────────────────────────────────────────► │ │
│ (registry) │ (registry credentials) └──────────────┘
└──────────────┘
```

**Deployment flow:** The deploy script creates Storage and Key Vault first, stores the storage connection string as a secret, creates ACR and pushes the container image, then creates an ACI container group that pulls from ACR with the secrets injected as environment variables.

**At runtime:** The Flask app reads the storage connection string from its environment, connects to Blob Storage, and provides a web UI for managing vacation activities (add, edit, delete).

## Prerequisites

- [LocalStack](https://docs.localstack.cloud/getting-started/installation/)
- [Docker](https://docs.docker.com/get-docker/)
- [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)
- [azlocal](https://pypi.org/project/azlocal/) (`pip install azlocal`)
- [Terraform](https://developer.hashicorp.com/terraform/downloads) (optional, for Terraform deployment)

## Quick Start

```bash
# Start LocalStack Azure
IMAGE_NAME=localstack/localstack-azure-alpha localstack start -d
localstack wait -t 60

# Login
azlocal login
azlocal start_interception

# Deploy all services
cd python
bash scripts/deploy.sh

# Validate the deployment (includes stop/start/restart lifecycle tests)
bash scripts/validate.sh
```

## Alternative Deployments

### Bicep

```bash
cd python
bash bicep/deploy.sh
```

### Terraform

```bash
cd python
bash terraform/deploy.sh
```

## Cleanup

```bash
# Removes all resources created by deploy.sh
bash scripts/cleanup.sh
```

## Application

The Vacation Planner is a Flask web application with a Bootstrap UI that lets users manage vacation activities. Activities are stored as JSON blobs in Azure Blob Storage, organized by username.

### Endpoints

| Route | Method | Description |
|-------|--------|-------------|
| `/` | GET | View all activities |
| `/` | POST | Add or update an activity |
| `/delete/<id>` | POST | Delete an activity |
| `/update/<id>` | GET | Edit an activity |
| `/health` | GET | Health check |

### Environment Variables

| Variable | Description |
|----------|-------------|
| `AZURE_STORAGE_CONNECTION_STRING` | Blob Storage connection string (from Key Vault) |
| `BLOB_CONTAINER_NAME` | Name of the blob container for activities |
| `LOGIN_NAME` | Username for the activity list (default: "paolo") |

## Scripts

| Script | Description |
|--------|-------------|
| `scripts/deploy.sh` | Deploys Storage, Key Vault, ACR, and ACI with env vars and DNS label |
| `scripts/validate.sh` | Validates all resources and exercises ACI lifecycle (get, list, logs, exec, stop, start, restart) |
| `scripts/cleanup.sh` | Removes all resources created by deploy.sh |
| `bicep/deploy.sh` | Deploys all resources using a Bicep template |
| `terraform/deploy.sh` | Deploys all resources using Terraform |

## ACI Features Demonstrated

| Feature | Script |
|---------|--------|
| Container group create | deploy.sh |
| Public IP + ports | deploy.sh |
| Environment variables | deploy.sh |
| Registry credentials (ACR) | deploy.sh |
| CPU / memory resources | deploy.sh |
| DNS name label / FQDN | deploy.sh |
| Container get / list | validate.sh |
| Container logs | validate.sh |
| Container exec | validate.sh |
| Stop / Start / Restart | validate.sh |
62 changes: 62 additions & 0 deletions samples/aci-blob-storage/python/bicep/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Bicep Deployment

This directory contains the Bicep template and a deployment script for provisioning Azure services in LocalStack for Azure. Refer to the [ACI Blob Storage](../README.md) guide for details about the sample application.

## Prerequisites

- [LocalStack for Azure](https://azure.localstack.cloud/): Local Azure cloud emulator for development and testing
- [Docker](https://docs.docker.com/get-docker/): Container runtime required for LocalStack
- [Azure CLI](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli): Azure command-line interface
- [Bicep extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep): VS Code extension for Bicep language support
- [azlocal CLI](https://azure.localstack.cloud/user-guides/sdks/az/): LocalStack Azure CLI wrapper
- [jq](https://jqlang.org/): JSON processor for scripting

### Installing azlocal CLI

```bash
pip install azlocal
```

## Architecture Overview

The [deploy.sh](deploy.sh) script first builds and pushes the Docker image to ACR, then the [main.bicep](main.bicep) template creates the following Azure resources:

1. [Azure Storage Account](https://learn.microsoft.com/en-us/azure/storage/common/storage-account-overview): Provides blob storage for vacation activity data.
2. [Azure Key Vault](https://learn.microsoft.com/en-us/azure/key-vault/general/overview): Stores the storage connection string as a secret.
3. [Azure Container Registry](https://learn.microsoft.com/en-us/azure/container-registry/container-registry-intro): Hosts the Docker container image.
4. [Azure Container Instances](https://learn.microsoft.com/en-us/azure/container-instances/container-instances-overview): Runs the containerized Flask application.

For more information on the sample application, see [ACI Blob Storage](../README.md).

## Configuration

Update the `main.bicepparam` file with your specific values:

```bicep
using 'main.bicep'

param prefix = 'local'
param suffix = 'test'
param imageName = 'vacation-planner'
param imageTag = 'v1'
param loginName = 'paolo'
```

## Deployment

```bash
cd samples/aci-blob-storage/python
bash bicep/deploy.sh
```

## Cleanup

```bash
bash scripts/cleanup.sh
```

## Related Documentation

- [Azure Bicep Documentation](https://docs.microsoft.com/en-us/azure/azure-resource-manager/bicep/)
- [Bicep Language Reference](https://docs.microsoft.com/en-us/azure/azure-resource-manager/bicep/bicep-functions)
- [LocalStack for Azure Documentation](https://azure.localstack.cloud/)
Loading
Loading