Skip to content

Commit fa1fa99

Browse files
authored
Aci sampleapp (#59)
* add draft aci sample app * implemented azure container instance sample app * updated readme * remove tail call * added terraform and biceps scripts for sample app * terraform fix * bicep fix * terraform keyvault fix * add and updates readmes * added fn-app+servicebus to run-samples.sh
1 parent f3c5716 commit fa1fa99

69 files changed

Lines changed: 62645 additions & 7 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ This repository contains comprehensive sample projects demonstrating how to deve
2828
|-------------|-------------|
2929
| [Function App and Storage](./samples/function-app-storage-http/dotnet/README.md) | Azure Functions App using Blob, Queue, and Table Storage |
3030
| [Function App and Front Door](./samples/function-app-front-door/python/README.md) | Azure Functions App exposed via Front Door |
31-
| [Function App and Managed Identities](./samples/function-app-managed-identity/python/README.md) | Azure Function App using Managed Identities |
32-
| [Function App and Service Bus](./samples/function-app-service-bus/dotnet/README.md) | Azure Function App using Service Bus |
33-
| [Web App and CosmosDB for MongoDB API ](./samples/web-app-cosmosdb-mongodb-api/python/README.md) | Azure Web App using CosmosDB for MongoDB API |
34-
| [Web App and CosmosDB for NoSQL API ](./samples/web-app-cosmosdb-nosql-api/python/README.md) | Azure Web App using CosmosDB for NoSQL API |
35-
| [Web App and Managed Identities](./samples/web-app-managed-identity/python/README.md) | Azure Web App using Managed Identities |
36-
| [Web App and SQL Database ](./samples/web-app-sql-database/python/README.md) | Azure Web App using SQL Database |
37-
| [ServiceBus ](./samples/servicebus/README.md) | Azure ServiceBus used by a Spring Boot application |
31+
| [Function App and Managed Identities](./samples/function-app-managed-identity/python/README.md) | Azure Function App using Managed Identities |
32+
| [Function App and Service Bus](./samples/function-app-service-bus/dotnet/README.md) | Azure Function App using Service Bus |
33+
| [Web App and CosmosDB for MongoDB API ](./samples/web-app-cosmosdb-mongodb-api/python/README.md) | Azure Web App using CosmosDB for MongoDB API |
34+
| [Web App and CosmosDB for NoSQL API ](./samples/web-app-cosmosdb-nosql-api/python/README.md) | Azure Web App using CosmosDB for NoSQL API |
35+
| [Web App and Managed Identities](./samples/web-app-managed-identity/python/README.md) | Azure Web App using Managed Identities |
36+
| [Web App and SQL Database ](./samples/web-app-sql-database/python/README.md) | Azure Web App using SQL Database |
37+
| [ACI and Blob Storage](./samples/aci-blob-storage/python/README.md) | Azure Container Instances with ACR, Key Vault, and Blob Storage |
38+
| [ServiceBus ](./samples/servicebus/README.md) | Azure ServiceBus used by a Spring Boot application |
3839

3940
## Sample Structure
4041

run-samples.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,36 @@ SAMPLES=(
3232
"samples/servicebus/java|bash scripts/deploy.sh"
3333
"samples/function-app-front-door/python|bash scripts/deploy_all.sh --name-prefix testafd --use-localstack|"
3434
"samples/function-app-managed-identity/python|bash scripts/user-managed-identity.sh|bash scripts/validate.sh && bash scripts/test.sh"
35+
"samples/function-app-service-bus/dotnet|bash scripts/deploy.sh|bash scripts/validate.sh && bash scripts/call-http-trigger.sh"
3536
"samples/function-app-storage-http/dotnet|bash scripts/deploy.sh|bash scripts/validate.sh && bash scripts/call-http-triggers.sh"
3637
"samples/web-app-cosmosdb-mongodb-api/python|bash scripts/deploy.sh|bash scripts/validate.sh && bash scripts/call-web-app.sh"
3738
"samples/web-app-managed-identity/python|bash scripts/user-assigned.sh|bash scripts/validate.sh && bash scripts/call-web-app.sh"
3839
"samples/web-app-sql-database/python|bash scripts/deploy.sh|bash scripts/validate.sh && bash scripts/get-web-app-url.sh"
40+
"samples/aci-blob-storage/python|bash scripts/deploy.sh|bash scripts/validate.sh"
3941
)
4042

4143
# 1a. Define Terraform Samples
4244
TERRAFORM_SAMPLES=(
4345
"samples/servicebus/java/terraform|bash deploy.sh"
4446
"samples/function-app-managed-identity/python/terraform|bash deploy.sh"
47+
"samples/function-app-service-bus/dotnet/terraform|bash deploy.sh"
4548
"samples/function-app-storage-http/dotnet/terraform|bash deploy.sh"
4649
"samples/web-app-cosmosdb-mongodb-api/python/terraform|bash deploy.sh"
4750
"samples/web-app-managed-identity/python/terraform|bash deploy.sh"
4851
"samples/web-app-sql-database/python/terraform|bash deploy.sh"
52+
"samples/aci-blob-storage/python/terraform|bash deploy.sh"
4953
)
5054

5155
# 1b. Define Bicep Samples
5256
BICEP_SAMPLES=(
5357
"samples/servicebus/java/bicep|bash deploy.sh"
5458
#"samples/web-app-sql-database/python/bicep|bash deploy.sh"
5559
"samples/function-app-managed-identity/python/bicep|bash deploy.sh"
60+
"samples/function-app-service-bus/dotnet/bicep|bash deploy.sh"
5661
"samples/function-app-storage-http/dotnet/bicep|bash deploy.sh"
5762
"samples/web-app-cosmosdb-mongodb-api/python/bicep|bash deploy.sh"
5863
"samples/web-app-managed-identity/python/bicep|bash deploy.sh"
64+
"samples/aci-blob-storage/python/bicep|bash deploy.sh"
5965
)
6066

6167
# Combine script-based, Terraform, and Bicep samples into one array
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Vacation Planner on Azure Container Instances
2+
3+
A sample application demonstrating how to deploy a containerized Flask web app using four Azure services:
4+
5+
- **Azure Blob Storage** — Stores vacation activities as JSON blobs
6+
- **Azure Key Vault** — Stores the storage connection string as a secret
7+
- **Azure Container Registry (ACR)** — Hosts the Docker container image
8+
- **Azure Container Instances (ACI)** — Runs the containerized application
9+
10+
## Architecture
11+
12+
```
13+
┌──────────────┐ store conn ┌──────────────┐ env vars ┌──────────────┐
14+
│ Storage │ ──── string ────► │ KeyVault │ ─────────► │ ACI │
15+
│ Account │ │ (secrets) │ │ (container │
16+
└──────────────┘ └──────────────┘ │ group) │
17+
▲ │ │
18+
│ read/write activities │ │
19+
└────────────────────────────────────────────────────────┤ │
20+
│ │
21+
┌──────────────┐ image pull │ │
22+
│ ACR │ ────────────────────────────────────────────► │ │
23+
│ (registry) │ (registry credentials) └──────────────┘
24+
└──────────────┘
25+
```
26+
27+
**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.
28+
29+
**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).
30+
31+
## Prerequisites
32+
33+
- [LocalStack](https://docs.localstack.cloud/getting-started/installation/)
34+
- [Docker](https://docs.docker.com/get-docker/)
35+
- [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)
36+
- [azlocal](https://pypi.org/project/azlocal/) (`pip install azlocal`)
37+
- [Terraform](https://developer.hashicorp.com/terraform/downloads) (optional, for Terraform deployment)
38+
39+
## Quick Start
40+
41+
```bash
42+
# Start LocalStack Azure
43+
IMAGE_NAME=localstack/localstack-azure-alpha localstack start -d
44+
localstack wait -t 60
45+
46+
# Login
47+
azlocal login
48+
azlocal start_interception
49+
50+
# Deploy all services
51+
cd python
52+
bash scripts/deploy.sh
53+
54+
# Validate the deployment (includes stop/start/restart lifecycle tests)
55+
bash scripts/validate.sh
56+
```
57+
58+
## Alternative Deployments
59+
60+
### Bicep
61+
62+
```bash
63+
cd python
64+
bash bicep/deploy.sh
65+
```
66+
67+
### Terraform
68+
69+
```bash
70+
cd python
71+
bash terraform/deploy.sh
72+
```
73+
74+
## Cleanup
75+
76+
```bash
77+
# Removes all resources created by deploy.sh
78+
bash scripts/cleanup.sh
79+
```
80+
81+
## Application
82+
83+
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.
84+
85+
### Endpoints
86+
87+
| Route | Method | Description |
88+
|-------|--------|-------------|
89+
| `/` | GET | View all activities |
90+
| `/` | POST | Add or update an activity |
91+
| `/delete/<id>` | POST | Delete an activity |
92+
| `/update/<id>` | GET | Edit an activity |
93+
| `/health` | GET | Health check |
94+
95+
### Environment Variables
96+
97+
| Variable | Description |
98+
|----------|-------------|
99+
| `AZURE_STORAGE_CONNECTION_STRING` | Blob Storage connection string (from Key Vault) |
100+
| `BLOB_CONTAINER_NAME` | Name of the blob container for activities |
101+
| `LOGIN_NAME` | Username for the activity list (default: "paolo") |
102+
103+
## Scripts
104+
105+
| Script | Description |
106+
|--------|-------------|
107+
| `scripts/deploy.sh` | Deploys Storage, Key Vault, ACR, and ACI with env vars and DNS label |
108+
| `scripts/validate.sh` | Validates all resources and exercises ACI lifecycle (get, list, logs, exec, stop, start, restart) |
109+
| `scripts/cleanup.sh` | Removes all resources created by deploy.sh |
110+
| `bicep/deploy.sh` | Deploys all resources using a Bicep template |
111+
| `terraform/deploy.sh` | Deploys all resources using Terraform |
112+
113+
## ACI Features Demonstrated
114+
115+
| Feature | Script |
116+
|---------|--------|
117+
| Container group create | deploy.sh |
118+
| Public IP + ports | deploy.sh |
119+
| Environment variables | deploy.sh |
120+
| Registry credentials (ACR) | deploy.sh |
121+
| CPU / memory resources | deploy.sh |
122+
| DNS name label / FQDN | deploy.sh |
123+
| Container get / list | validate.sh |
124+
| Container logs | validate.sh |
125+
| Container exec | validate.sh |
126+
| Stop / Start / Restart | validate.sh |
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Bicep Deployment
2+
3+
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.
4+
5+
## Prerequisites
6+
7+
- [LocalStack for Azure](https://azure.localstack.cloud/): Local Azure cloud emulator for development and testing
8+
- [Docker](https://docs.docker.com/get-docker/): Container runtime required for LocalStack
9+
- [Azure CLI](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli): Azure command-line interface
10+
- [Bicep extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep): VS Code extension for Bicep language support
11+
- [azlocal CLI](https://azure.localstack.cloud/user-guides/sdks/az/): LocalStack Azure CLI wrapper
12+
- [jq](https://jqlang.org/): JSON processor for scripting
13+
14+
### Installing azlocal CLI
15+
16+
```bash
17+
pip install azlocal
18+
```
19+
20+
## Architecture Overview
21+
22+
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:
23+
24+
1. [Azure Storage Account](https://learn.microsoft.com/en-us/azure/storage/common/storage-account-overview): Provides blob storage for vacation activity data.
25+
2. [Azure Key Vault](https://learn.microsoft.com/en-us/azure/key-vault/general/overview): Stores the storage connection string as a secret.
26+
3. [Azure Container Registry](https://learn.microsoft.com/en-us/azure/container-registry/container-registry-intro): Hosts the Docker container image.
27+
4. [Azure Container Instances](https://learn.microsoft.com/en-us/azure/container-instances/container-instances-overview): Runs the containerized Flask application.
28+
29+
For more information on the sample application, see [ACI Blob Storage](../README.md).
30+
31+
## Configuration
32+
33+
Update the `main.bicepparam` file with your specific values:
34+
35+
```bicep
36+
using 'main.bicep'
37+
38+
param prefix = 'local'
39+
param suffix = 'test'
40+
param imageName = 'vacation-planner'
41+
param imageTag = 'v1'
42+
param loginName = 'paolo'
43+
```
44+
45+
## Deployment
46+
47+
```bash
48+
cd samples/aci-blob-storage/python
49+
bash bicep/deploy.sh
50+
```
51+
52+
## Cleanup
53+
54+
```bash
55+
bash scripts/cleanup.sh
56+
```
57+
58+
## Related Documentation
59+
60+
- [Azure Bicep Documentation](https://docs.microsoft.com/en-us/azure/azure-resource-manager/bicep/)
61+
- [Bicep Language Reference](https://docs.microsoft.com/en-us/azure/azure-resource-manager/bicep/bicep-functions)
62+
- [LocalStack for Azure Documentation](https://azure.localstack.cloud/)

0 commit comments

Comments
 (0)