azure_create_workflow
Generate GitHub Actions workflows to automate Azure deployments, streamlining CI/CD pipelines for containerized applications.
Instructions
Generate GitHub Actions workflow for Azure deployment
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.js:1398-1541 (handler)Handler function that generates a GitHub Actions YAML workflow for building, pushing to ACR, and deploying to Azure Container Apps. Includes optional SonarCloud integration.async ({ app_name, resource_group, acr_name, include_sonar, sonar_org }) => { let sonarStep = ""; if (include_sonar) { sonarStep = ` - name: SonarCloud Scan uses: SonarSource/sonarcloud-github-action@master env: GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }} with: args: > -Dsonar.organization=${sonar_org} -Dsonar.projectKey=\${{ github.repository_owner }}_\${{ github.event.repository.name }} `; } const workflow = `name: Build and Deploy to Azure on: push: branches: [ main, master ] pull_request: branches: [ main, master ] env: ACR_NAME: ${acr_name} ACR_LOGIN_SERVER: ${acr_name}.azurecr.io APP_NAME: ${app_name} RESOURCE_GROUP: ${resource_group} jobs: build-and-test: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 ${sonarStep} build-and-push: needs: build-and-test runs-on: ubuntu-latest if: github.event_name != 'pull_request' steps: - name: Checkout code uses: actions/checkout@v4 - name: Login to Azure uses: azure/login@v2 with: creds: \${{ secrets.AZURE_CREDENTIALS }} - name: Login to ACR run: az acr login -n \${{ env.ACR_NAME }} - name: Build and push image uses: docker/build-push-action@v5 with: context: . push: true tags: | \${{ env.ACR_LOGIN_SERVER }}/\${{ env.APP_NAME }}:latest \${{ env.ACR_LOGIN_SERVER }}/\${{ env.APP_NAME }}:\${{ github.sha }} cache-from: type=gha cache-to: type=gha,mode=max deploy: needs: build-and-push runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' steps: - name: Login to Azure uses: azure/login@v2 with: creds: \${{ secrets.AZURE_CREDENTIALS }} - name: Deploy to Container Apps run: | az containerapp update \\ -n \${{ env.APP_NAME }} \\ -g \${{ env.RESOURCE_GROUP }} \\ --image \${{ env.ACR_LOGIN_SERVER }}/\${{ env.APP_NAME }}:\${{ github.sha }} - name: Get App URL run: | URL=$(az containerapp show -n \${{ env.APP_NAME }} -g \${{ env.RESOURCE_GROUP }} --query properties.configuration.ingress.fqdn -o tsv) echo "## Deployed to: https://$URL" >> $GITHUB_STEP_SUMMARY`; return { content: [{ type: "text", text: `AZURE DEPLOYMENT WORKFLOW ========================= Save to: .github/workflows/azure-deploy.yml ${workflow} REQUIRED SECRETS: ----------------- 1. AZURE_CREDENTIALS - Azure service principal credentials Create service principal: az ad sp create-for-rbac --name "github-actions" \\ --role contributor \\ --scopes /subscriptions/{subscription-id}/resourceGroups/${resource_group} \\ --json-auth Then: gh secret set AZURE_CREDENTIALS (paste the entire JSON output) ${include_sonar ? `2. SONAR_TOKEN - Get from sonarcloud.io/account/security gh secret set SONAR_TOKEN` : ""} FIRST-TIME SETUP: ----------------- Before the workflow runs, you need: 1. Resource group: ${resource_group} az group create -n ${resource_group} -l westus2 2. Container registry: ${acr_name} az acr create -n ${acr_name} -g ${resource_group} --sku Basic 3. Container app (first deployment): az containerapp create -n ${app_name} -g ${resource_group} \\ --environment ${app_name}-env \\ --image mcr.microsoft.com/azuredocs/containerapps-helloworld:latest \\ --target-port 8080 --ingress external 4. Grant ACR pull access: az role assignment create \\ --assignee $(az ad sp list --display-name "github-actions" --query [0].appId -o tsv) \\ --role AcrPush \\ --scope $(az acr show -n ${acr_name} --query id -o tsv)` }] }; }
- src/index.js:1391-1397 (schema)Input schema defining parameters for the azure_create_workflow tool.{ app_name: { type: "string", description: "Azure Container App name" }, resource_group: { type: "string", description: "Azure resource group" }, acr_name: { type: "string", description: "Azure Container Registry name" }, include_sonar: { type: "boolean", description: "Include SonarCloud analysis", default: false }, sonar_org: { type: "string", description: "SonarCloud organization", default: "" } },
- src/index.js:1389-1542 (registration)Registration of the 'azure_create_workflow' tool using McpServer.tool() method, specifying name, description, schema, and handler."azure_create_workflow", "Generate GitHub Actions workflow for Azure deployment", { app_name: { type: "string", description: "Azure Container App name" }, resource_group: { type: "string", description: "Azure resource group" }, acr_name: { type: "string", description: "Azure Container Registry name" }, include_sonar: { type: "boolean", description: "Include SonarCloud analysis", default: false }, sonar_org: { type: "string", description: "SonarCloud organization", default: "" } }, async ({ app_name, resource_group, acr_name, include_sonar, sonar_org }) => { let sonarStep = ""; if (include_sonar) { sonarStep = ` - name: SonarCloud Scan uses: SonarSource/sonarcloud-github-action@master env: GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }} with: args: > -Dsonar.organization=${sonar_org} -Dsonar.projectKey=\${{ github.repository_owner }}_\${{ github.event.repository.name }} `; } const workflow = `name: Build and Deploy to Azure on: push: branches: [ main, master ] pull_request: branches: [ main, master ] env: ACR_NAME: ${acr_name} ACR_LOGIN_SERVER: ${acr_name}.azurecr.io APP_NAME: ${app_name} RESOURCE_GROUP: ${resource_group} jobs: build-and-test: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 ${sonarStep} build-and-push: needs: build-and-test runs-on: ubuntu-latest if: github.event_name != 'pull_request' steps: - name: Checkout code uses: actions/checkout@v4 - name: Login to Azure uses: azure/login@v2 with: creds: \${{ secrets.AZURE_CREDENTIALS }} - name: Login to ACR run: az acr login -n \${{ env.ACR_NAME }} - name: Build and push image uses: docker/build-push-action@v5 with: context: . push: true tags: | \${{ env.ACR_LOGIN_SERVER }}/\${{ env.APP_NAME }}:latest \${{ env.ACR_LOGIN_SERVER }}/\${{ env.APP_NAME }}:\${{ github.sha }} cache-from: type=gha cache-to: type=gha,mode=max deploy: needs: build-and-push runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' steps: - name: Login to Azure uses: azure/login@v2 with: creds: \${{ secrets.AZURE_CREDENTIALS }} - name: Deploy to Container Apps run: | az containerapp update \\ -n \${{ env.APP_NAME }} \\ -g \${{ env.RESOURCE_GROUP }} \\ --image \${{ env.ACR_LOGIN_SERVER }}/\${{ env.APP_NAME }}:\${{ github.sha }} - name: Get App URL run: | URL=$(az containerapp show -n \${{ env.APP_NAME }} -g \${{ env.RESOURCE_GROUP }} --query properties.configuration.ingress.fqdn -o tsv) echo "## Deployed to: https://$URL" >> $GITHUB_STEP_SUMMARY`; return { content: [{ type: "text", text: `AZURE DEPLOYMENT WORKFLOW ========================= Save to: .github/workflows/azure-deploy.yml ${workflow} REQUIRED SECRETS: ----------------- 1. AZURE_CREDENTIALS - Azure service principal credentials Create service principal: az ad sp create-for-rbac --name "github-actions" \\ --role contributor \\ --scopes /subscriptions/{subscription-id}/resourceGroups/${resource_group} \\ --json-auth Then: gh secret set AZURE_CREDENTIALS (paste the entire JSON output) ${include_sonar ? `2. SONAR_TOKEN - Get from sonarcloud.io/account/security gh secret set SONAR_TOKEN` : ""} FIRST-TIME SETUP: ----------------- Before the workflow runs, you need: 1. Resource group: ${resource_group} az group create -n ${resource_group} -l westus2 2. Container registry: ${acr_name} az acr create -n ${acr_name} -g ${resource_group} --sku Basic 3. Container app (first deployment): az containerapp create -n ${app_name} -g ${resource_group} \\ --environment ${app_name}-env \\ --image mcr.microsoft.com/azuredocs/containerapps-helloworld:latest \\ --target-port 8080 --ingress external 4. Grant ACR pull access: az role assignment create \\ --assignee $(az ad sp list --display-name "github-actions" --query [0].appId -o tsv) \\ --role AcrPush \\ --scope $(az acr show -n ${acr_name} --query id -o tsv)` }] }; } );