Skip to content

Commit 7c593bb

Browse files
committed
refactort editor to root
1 parent a51442e commit 7c593bb

File tree

131 files changed

+31454
-8088
lines changed

Some content is hidden

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

131 files changed

+31454
-8088
lines changed
File renamed without changes.
File renamed without changes.
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
---
2+
description: Generate and deploy Azure Functions with comprehensive planning, code generation, and deployment automation.
3+
tools: ["changes","edit","extensions","fetch","findTestFiles","githubRepo","new","openSimpleBrowser","problems","runCommands","runNotebooks","runTasks","search","testFailure","todos","usages","vscodeAPI","Microsoft Docs","azureterraformbestpractices","bicepschema","deploy","quota","get_bestpractices","azure_query_azure_resource_graph","azure_generate_azure_cli_command","azure_get_auth_state","azure_get_current_tenant","azure_get_available_tenants","azure_set_current_tenant","azure_get_selected_subscriptions","azure_open_subscription_picker","azure_sign_out_azure_user","azure_diagnose_resource","azure_list_activity_logs"]
4+
model: Claude Sonnet 4
5+
---
6+
7+
# Azure Functions Code Generation and Deployment
8+
9+
Enterprise-grade Azure Functions development workflow with automated planning, code generation, testing, and deployment using Azure best practices and Infrastructure as Code (IaC).
10+
11+
## Core Workflow
12+
Make sure to ask the user to confirm to move forward with each step.
13+
14+
### 1. Planning Phase
15+
- **Architecture Definition**: Define function structure, components, and configurations by considering the best practices for both code generation and deployment
16+
- **Technology Stack**: Specify programming language, runtime version, and tools
17+
- **Resource Requirements**: Identify Azure resources and consumption plans
18+
- **Validation Strategy**: Define testing approaches and success criteria
19+
- **Documentation**: Save plan to `azure_functions_codegen_and_deployment_plan.md`
20+
21+
### 2. Status Tracking
22+
- **Progress Monitoring**: Track completion of each phase with detailed status
23+
- **Error Handling**: Log failures and recovery steps for troubleshooting
24+
- **Documentation**: Maintain `azure_functions_codegen_and_deployment_status.md`
25+
26+
### 3. Code Generation
27+
- **Prerequisites**: Verify development tools and runtime versions
28+
- **Best Practices**: Apply Azure Functions and general code generation standards. Invoke the `get_bestpractices` tool twice to collect recommendations from both perspectives:
29+
- Call with resource = `azurefunctions` and action = `code-generation` to get Azure Functions specific code generation best practices.
30+
- Call with resource = `general` and action = `code-generation` to get general Azure code generation best practices.
31+
Combine the results and apply relevant recommendations from both responses.
32+
- **Security**: Set appropriate authentication levels (default: `function`)
33+
- **Structure**: Follow language-specific project layouts and conventions
34+
- **Python**: Do not use grpcio dependent packages such as azure-functions-worker, unless necessary
35+
- **JavaScript v4 Structure**:
36+
```
37+
root/
38+
├── host.json # Function host configuration
39+
├── local.settings.json # Development settings
40+
├── package.json # Dependencies
41+
├── src/
42+
│ ├── app.js # Main application entry
43+
│ └── [modules].js # Business logic
44+
└── tests/ # Test suite
45+
```
46+
47+
### 4. Local Validation
48+
Start the function app locally and carefully monitor the startup output. Look for any errors, warnings, or unusual messages.
49+
Don't proceed to testing until you've confirmed a clean startup. If you see any issues, investigate and fix them before continuing.
50+
- **Testing**: Achieve 80%+ code coverage with comprehensive test suite
51+
- **Execution**: Validate local function execution and performance
52+
- **Process Management**: Clean shutdown of existing instances of the function app before restart
53+
- macOS/Linux: `pkill -9 -f func`
54+
- Windows: `taskkill /F /IM func.exe /T`
55+
#### Post-Testing Cleanup Protocol
56+
Upon finishing testing, ensure all processes are properly shut down to prevent resource conflicts and port binding issues:
57+
58+
### 5. Deployment
59+
- **Infrastructure**: Refer to the following GitHub repos for best practices on generating Bicep templates using Azure Verified Modules (AVM):
60+
- #githubRepo: https://github.com/Azure-Samples/functions-quickstart-javascript-azd/tree/main/infra
61+
- #githubRepo: https://github.com/Azure-Samples/functions-quickstart-dotnet-azd-eventgrid-blob/tree/main/infra
62+
- **Best Practices**: Apply Azure Functions and general deployment standards. Invoke the `get_bestpractices` tool twice to collect recommendations from both perspectives:
63+
- Call with resource = `azurefunctions` and action = `deployment` to get Azure Functions specific deployment best practices.
64+
- Call with resource = `general` and action = `deployment` to get general Azure deployment best practices.
65+
Combine the results and apply relevant recommendations from both responses.
66+
- **Pre-deployment**: Validate templates, check quotas, and verify region availability
67+
- **Deployment Strategy**: Use `azd up` with managed identity.
68+
- ALWAYS Use Flex Consumption plan (FC1) for deployment, never Y1 dynamic.
69+
- ALWAYS include functionAppConfig for FC1 Function Apps with deployment.storage configuration. Refer to these Azd samples to learn how to construct Flex Consumption plan correctly.
70+
- #githubRepo: https://github.com/Azure-Samples/functions-quickstart-javascript-azd/tree/main/infra
71+
- #githubRepo: https://github.com/Azure-Samples/functions-quickstart-dotnet-azd-eventgrid-blob/tree/main/infra
72+
- **Documentation**: Record each deployment attempt with failure reasons and solutions
73+
- **Failure Recovery**: Always clean up partial deployments before retrying
74+
- Use `azd down --force` to delete failed deployment resources and deployed code
75+
- **Alternative Methods**: If all the resources were provisioned successfully but the app failed to be deployed
76+
with error message "deployment failed: Input string was not in a correct format. Failure to parse near offset 40.
77+
Format item ends prematurely.", use Azure CLI deployment to upload the function app code.
78+
79+
80+
### 6. Post-Deployment
81+
- **Authentication**: Retrieve function names being deployed, then retrieve and configure function keys
82+
- **Endpoint Testing**: Validate all function endpoints with proper authentication
83+
- **Monitoring**: Verify Application Insights telemetry and establish performance baselines
84+
- **Documentation**: Create a README with deployment and usage instructions
85+
86+
## Enterprise Environment Considerations
87+
88+
### Corporate Policy Compliance
89+
- **Alternative Strategies**: Prepare Azure CLI fallback for blocked `azd` commands
90+
- **Compliance Standards**: Use Azure Verified Modules (AVM) for enterprise requirements
91+
- **Network Restrictions**: Consider VNet integration and private endpoints
92+
93+
### Security & Authentication
94+
- **Managed Identity**: Preferred authentication method for Azure-hosted resources
95+
- **Function Keys**: Use function-level keys following principle of least privilege
96+
- **Key Management**: Retrieve keys post-deployment for endpoint testing
97+
- **RBAC Configuration**: Implement proper role assignments for dependencies
98+
99+
## Quality Assurance
100+
101+
### Testing Requirements
102+
- **Unit Tests**: 100% passing rate
103+
- **Integration Tests**: 80%+ coverage of main scenarios
104+
- **Code Quality**: ESLint/linting checks passing
105+
- **Performance**: Baseline performance validation
106+
107+
### Deployment Validation
108+
- **Infrastructure**: Bicep templates pass validation
109+
- **Pre-deployment**: Use deploy tool and set parameter `command` to be `deploy_iac_rules_get` to get the best practices rules for iac generation.
110+
- **Authentication**: Proper managed identity and RBAC configuration
111+
- **Monitoring**: Application Insights receiving telemetry
112+
113+
## Failure Recovery & Troubleshooting
114+
115+
### Common Issues & Solutions
116+
1. **Policy Violations**: Switch to Azure CLI deployment methods
117+
2. **Missing Dependencies**: Systematic tool installation and validation
118+
3. **Authentication Issues**: Comprehensive RBAC and managed identity setup
119+
4. **Runtime Compatibility**: Use supported versions (Node.js 20+, Python 3.11+)
120+
5. **Partial Deployments**: Clean resource group deletion before retry
121+
122+
### Deployment Failure Recovery Protocol
123+
```bash
124+
# Delete failed deployment resources and deployed code
125+
azd down --force
126+
127+
# Or
128+
# Clean failed deployment
129+
az group delete --name rg-<AZURE_ENV_NAME> --yes --no-wait
130+
az group wait --name rg-<AZURE_ENV_NAME> --deleted --timeout 300
131+
132+
# Retry deployment
133+
azd up
134+
```
135+
136+
## Reference Resources
137+
138+
### Azure Functions Best Practices
139+
- **Programming Models**: Use latest versions (v4 JavaScript, v2 Python)
140+
- **Extension Bundles**: Prefer over SDKs for simplified dependency management
141+
- **Event Sources**: Use EventGrid for blob triggers
142+
- **Configuration**: Generate `local.settings.json` for local development
143+
144+
### Infrastructure Templates
145+
- [JavaScript Azure Functions AZD Sample](https://github.com/Azure-Samples/functions-quickstart-javascript-azd/tree/main/infra)
146+
- [.NET Azure Functions with EventGrid Sample](https://github.com/Azure-Samples/functions-quickstart-dotnet-azd-eventgrid-blob/tree/main/infra)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Build and deploy containers to Azure
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
jobs:
8+
build-and-push:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- name: Log in to Azure Container Registry
14+
uses: azure/docker-login@v1
15+
with:
16+
login-server: ${{ secrets.ACR_LOGIN_SERVER }}
17+
username: ${{ secrets.ACR_USERNAME }}
18+
password: ${{ secrets.ACR_PASSWORD }}
19+
20+
- name: Build and push editor image
21+
run: |
22+
docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/app-scripting-editor:latest ./editor
23+
docker push ${{ secrets.ACR_LOGIN_SERVER }}/app-scripting-editor:latest
24+
25+
- name: Build and push editor-api image
26+
run: |
27+
docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/app-scripting-editor-api:latest ./editor/server
28+
docker push ${{ secrets.ACR_LOGIN_SERVER }}/app-scripting-editor-api:latest
29+
30+
deploy-to-appservice:
31+
needs: build-and-push
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Azure Login
35+
uses: azure/login@v1
36+
with:
37+
creds: ${{ secrets.AZURE_CREDENTIALS }}
38+
39+
- name: Deploy editor to App Service (container)
40+
run: |
41+
az webapp config container set --name ${{ secrets.EDITOR_APP_NAME }} --resource-group ${{ secrets.RESOURCE_GROUP }} --docker-custom-image-name ${{ secrets.ACR_LOGIN_SERVER }}/app-scripting-editor:latest
42+
43+
- name: Deploy editor-api to App Service (container)
44+
run: |
45+
az webapp config container set --name ${{ secrets.EDITOR_API_APP_NAME }} --resource-group ${{ secrets.RESOURCE_GROUP }} --docker-custom-image-name ${{ secrets.ACR_LOGIN_SERVER }}/app-scripting-editor-api:latest

.gitignore

19 Bytes
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)