Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added infra and slot deployments #5

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
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
54 changes: 54 additions & 0 deletions .github/workflows/infraworkflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: workflow to deploy an ARM Template to a Subscription Scope
on:
push:
paths:
- 'ARM/**'
- '.github/workflows/infraworkflow.yml'

env:
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} # set this to your Azure Subscription Id
AZURE_RESOURCEGROUP_NAME: demo-webapp-gh-actions # set this to your preferred resource group name
AZURE_WEBAPP_NAME: demo-webapp-gh-actions # set this to your preferred resource group name
ASP_NAME: demo-webapp-gh-actions # set this to your preferred resource group name

jobs:
build-and-deploy-to-dev:
runs-on: ubuntu-latest
steps:

# Please refer to https://github.com/Azure/login#configure-deployment-credentials for help on the Azure login action and setting up your secrets
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

# Checkout
- name: Checkout
uses: actions/checkout@v2
with:
path: repo

# Deployment of template
- name: Deploy ARM Template resourcegroup
uses: azure/arm-deploy@v1
with:
# You can change these environment variables for your configuration: AZURE_SUBSCRIPTION_ID
scope: subscription
subscriptionId: ${{ env.AZURE_SUBSCRIPTION_ID }}
region: centralus # Set this to your target region
template: repo/ARM/azuredeploy.resourcegroup.json # Set this to the location of your template file
parameters: rgName=${{env.AZURE_RESOURCEGROUP_NAME}} rgLocation=centralus #override rgName in parameters file

# Deployment of template
- name: Deploy ARM Template resources
uses: azure/arm-deploy@v1
with:
# You can change these environment variables for your configuration: AZURE_SUBSCRIPTION_ID
scope: resourcegroup
subscriptionId: ${{ env.AZURE_SUBSCRIPTION_ID }}
resourceGroupName: ${{env.AZURE_RESOURCEGROUP_NAME}}
region: centralus # Set this to your target region
template: repo/ARM/azuredeploy.json # Set this to the location of your template file
parameters: webappName=${{env.AZURE_WEBAPP_NAME}} aspName=${{env.ASP_NAME}} # Set this to the location of your parameters file

#TODO: download web app publish profile and add it as a secret to the repo
20 changes: 15 additions & 5 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ on:
push:
branches:
- master
pull_request:
branches:
- '*'
- vermegi/infra
# CONFIGURATION
# For help, go to https://github.com/Azure/Actions
#
Expand All @@ -15,9 +13,10 @@ on:
#
# 2. Change these variables for your configuration:
env:
AZURE_WEBAPP_NAME: dotnetcoreLinux # set this to your application's name
AZURE_WEBAPP_NAME: demo-webapp-gh-actions # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '2.2.402' # set this to the dot net version to use
AZURE_RESOURCEGROUP_NAME: demo-webapp-gh-actions # set this to your preferred resource group name

jobs:
build-and-deploy:
Expand All @@ -39,12 +38,23 @@ jobs:
dotnet build --configuration Release
dotnet publish -c Release -o myapp

# Deploy to Azure Web apps
# Deploy to Azure Web apps staging slot
- name: 'Run Azure webapp deploy action using publish profile credentials'
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} # Define secret variable in repository settings as per action documentation
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
slot-name: staging

- name: Login for az cli commands
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Swap to production slot
run: |
az webapp deployment slot swap --resource-group ${{ env.AZURE_RESOURCEGROUP_NAME }} --name ${{ env.AZURE_WEBAPP_NAME }} --slot staging --target-slot production
echo "Swap finished. App Service Application URL: https://$(az webapp show --resource-group ${{ env.AZURE_RESOURCEGROUP_NAME }} --name ${{ env.AZURE_WEBAPP_NAME }} --query hostNames[0] -o tsv)"

# For more samples to get started with GitHub Action workflows to deploy to Azure, refer to https://github.com/Azure/actions-workflow-samples
80 changes: 80 additions & 0 deletions ARM/azuredeploy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"webappName": {
"type": "string",
"metadata": {
"description": "Name of your web app"
}
},
"aspName": {
"type": "string",
"metadata": {
"description": "Name of your app service plan"
}
},
"aspSKU": {
"type": "string",
"metadata": {
"description": "description"
},
"defaultValue": "S1"
}
},
"functions": [],
"variables": {},
"resources": [
{
"name": "[parameters('webappName')]",
"type": "Microsoft.Web/sites",
"apiVersion": "2018-11-01",
"location": "[resourceGroup().location]",
"tags": {
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('aspName'))]": "Resource",
"displayName": "[parameters('webappName')]"
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', parameters('aspName'))]"
],
"properties": {
"name": "[parameters('webappName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('aspName'))]"
}
},
{
"name": "[parameters('aspName')]",
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2018-02-01",
"location": "[resourceGroup().location]",
"sku": {
"name": "[parameters('aspSKU')]",
"capacity": 1
},
"tags": {
"displayName": "[parameters('aspName')]"
},
"properties": {
"name": "[parameters('aspName')]"
}
},
{
"apiVersion": "2020-06-01",
"type": "Microsoft.Web/sites/slots",
"name": "[concat(parameters('webappName'), '/', 'staging')]",
"kind": "app",
"location": "[resourceGroup().location]",
"comments": "This specifies the web app slots.",
"tags": {
"displayName": "WebAppSlots"
},
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('aspName'))]"
},
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('webappName'))]"
]
}
],
"outputs": {}
}
12 changes: 12 additions & 0 deletions ARM/azuredeploy.parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"webappName":{
"value": "GEN-UNIQUE"
} ,
"aspName": {
"value": "GEN-UNIQUE"
}
}
}
31 changes: 31 additions & 0 deletions ARM/azuredeploy.resourcegroup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"rgName": {
"type": "string",
"metadata": {
"description": "Name of the resourceGroup to create"
}
},
"rgLocation": {
"type": "string",
"metadata": {
"description": "Location for the resourceGroup"
}
}
},
"variables": { },
"resources": [
{
"type": "Microsoft.Resources/resourceGroups",
"apiVersion": "2019-10-01",
"name": "[parameters('rgName')]",
"location": "[parameters('rgLocation')]",
"tags": {
"Note": "subscription level deployment"
},
"properties": {}
}
]
}
12 changes: 12 additions & 0 deletions ARM/azuredeploy.resourcegroup.parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"rgName": {
"value": "GEN-UNIQUE"
},
"rgLocation": {
"value": "southcentralus"
}
}
}