8000 GitHub - jimbrig/azd-shiny: Azure Developer CLI Template for R Shiny Apps
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

jimbrig/azd-shiny

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Azure Developer CLI Template for R Shiny Web Apps

This repository contains a comprehensive Azure Developer CLI (azd) template for deploying R Shiny applications to Azure using Azure Container Apps and Terraform as Infrastructure as Code.

πŸš€ Features

  • Production-Ready Infrastructure: Azure Container Apps with auto-scaling
  • Security First: Managed identities, Key Vault integration, RBAC
  • Modern Architecture: Containerized deployment with private container registry
  • Monitoring: Integrated logging with Log Analytics
  • IaC: Complete Terraform infrastructure setup
  • Automated Deployment: One-command deployment with azd

πŸ—οΈ Architecture

The template deploys the following Azure resources:

  • Azure Container Apps: Serverless container hosting
  • Azure Container Registry: Private Docker registry
  • Azure Key Vault: Secure secret management
  • Log Analytics Workspace: Centralized logging
  • Managed Identity: Secure service-to-service authentication
  • RBAC Assignments: Least privilege access control

🎯 Quick Start

Prerequisites

Deploy to Azure

  1. Initialize the template:

    azd init --template <repository-url>
    cd <your-project-name>
  2. Configure variables (optional):

    cp infra/terraform.tfvars.example infra/terraform.tfvars
    # Edit terraform.tfvars with your preferred settings
  3. Deploy everything:

    azd up
  4. Access your app: After deployment, azd will output the URL of your running R Shiny application.

πŸ“ Project Structure

β”œβ”€β”€ src/                    # R Shiny application source
β”‚   β”œβ”€β”€ app.R              # Enhanced R Shiny app with Azure features
β”‚   └── Dockerfile         # Production-ready container definition
β”œβ”€β”€ infra/                 # Terraform infrastructure
β”‚   β”œβ”€β”€ main.tf           # Main infrastructure resources
β”‚   β”œβ”€β”€ variables.tf      # Input variables
β”‚   β”œβ”€β”€ outputs.tf        # Output values
β”‚   β”œβ”€β”€ provider.tf       # Terraform providers
β”‚   β”œβ”€β”€ terraform.tfvars.example  # Example configuration
β”‚   └── README.md         # Infrastructure documentation
β”œβ”€β”€ hooks/                 # Deployment hooks
β”‚   β”œβ”€β”€ predeploy.sh      # Pre-deployment validation
β”‚   └── postdeploy.sh     # Post-deployment verification
β”œβ”€β”€ azure.yaml            # azd configuration
└── README.md             # This file

πŸ”§ Configuration

Environment Variables

The R Shiny application can access these environment variables:

  • PORT: Application port (default: 3838)
  • APP_SECRET: Application secret from Key Vault

Terraform Variables

Configure these in infra/terraform.tfvars:

Variable Description Default
location Azure region -
environment_name Resource name prefix -
image_name Container image name shinyapp
app_secret_value Application secret default-secret-value
min_replicas Minimum container instances 1
max_replicas Maximum container instances 3

πŸ” Security Features

  • No hardcoded credentials: Uses managed identities
  • Private container registry: Secure image storage
  • Key Vault integration: Encrypted secret management
  • RBAC: Role-based access control
  • HTTPS only: Automatic TLS termination
  • Non-root containers: Enhanced security

πŸ“Š Monitoring & Logging

  • Container logs: Automatically sent to Log Analytics
  • Health checks: Built-in container health monitoring
  • Azure Monitor: Ready for alerts and dashboards
  • Application insights: Can be easily added

πŸ”„ Development Workflow

  1. Modify your R Shiny app in src/app.R
  2. Test locally with Docker:
    cd src
    docker build -t my-shiny-app .
    docker run -p 3838:3838 my-shiny-app
  3. Deploy changes:
    azd deploy

πŸ› οΈ Advanced Usage

Custom R Packages

Add package installations to src/Dockerfile:

RUN R -e "install.packages(c('plotly', 'dplyr'), repos='https://cran.rstudio.com/')"

Scaling Configuration

Modify scaling in infra/terraform.tfvars:

min_replicas = 2
max_replicas = 10

Additional Secrets

Add more secrets in infra/main.tf:

resource "azurerm_key_vault_secret" "additional_secret" {
  name         = "another-secret"
  value        = var.another_secret_value
  key_vault_id = azurerm_key_vault.kv.id
}

🚨 Troubleshooting

Common Issues

  1. Container fails to start:

    az containerapp logs show --name <app-name> --resource-group <rg-name>
  2. Authentication errors: Check managed identity role assignments in Azure Portal

  3. Build failures: Verify Dockerfile syntax and R package dependencies

Useful Commands

# View deployment status
azd show

# Check container app status
az containerapp show --name <app-name> --resource-group <rg-name>

# View logs
azd logs

# Redeploy application only
azd deploy

# Destroy all resources
azd down

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test the deployment
  5. Submit a pull request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

About

Azure Developer CLI Template for R Shiny Apps

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0