Skip to content

Commit f8b87f1

Browse files
committed
Add GitHub Actions workflows for Azure Bicep deployment and .NET CI issue #1
1 parent 46e99c4 commit f8b87f1

File tree

4 files changed

+274
-2
lines changed

4 files changed

+274
-2
lines changed

.github/workflows/deploy.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Azure Bicep
2+
3+
on:
4+
workflow_dispatch
5+
6+
env:
7+
targetEnv: dev
8+
9+
jobs:
10+
build-and-deploy:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
steps:
17+
# Checkout code
18+
- uses: actions/checkout@main
19+
20+
# Log into Azure
21+
- uses: azure/[email protected]
22+
with:
23+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
24+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
25+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
26+
enable-AzPSSession: true
27+
28+
# Deploy ARM template
29+
- name: Run ARM deploy
30+
uses: azure/arm-deploy@v1
31+
with:
32+
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
33+
resourceGroupName: ${{ secrets.AZURE_RG }}
34+
template: ./src/InfrastructureAsCode/main.bicep
35+
parameters: environment=${{ env.targetEnv }}

.github/workflows/dotnet-deploy.yml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
name: .NET CI
2+
3+
env:
4+
registryName: {your_registry_name}.azurecr.io
5+
repositoryName: techexcel/dotnetcoreapp
6+
dockerFolderPath: ./src/Application/src/RazorPagesTestSample
7+
tag: ${{github.run_number}}
8+
9+
on:
10+
push:
11+
branches:
12+
- main
13+
paths:
14+
- src/Application/**
15+
pull_request:
16+
branches:
17+
- main
18+
paths:
19+
- src/Application/**
20+
# Allows you to run this workflow manually from the Actions tab
21+
workflow_dispatch:
22+
jobs:
23+
build:
24+
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- uses: actions/checkout@v3
29+
- name: Setup .NET
30+
uses: actions/setup-dotnet@v3
31+
with:
32+
dotnet-version: 8.0
33+
34+
- name: Restore dependencies
35+
run: dotnet restore ./src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj
36+
- name: Build
37+
run: dotnet build --no-restore ./src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj
38+
- name: Test
39+
run: dotnet test --no-build --verbosity normal ./src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj
40+
- uses: actions/github-script@v6
41+
if: failure()
42+
with:
43+
github-token: ${{secrets.GITHUB_TOKEN}}
44+
script: |
45+
let body = "${{ env.build_name }} Workflow Failure \n Build Number: ${{ github.run_number }} \n Build Log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \n SHA: [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) \n";
46+
github.issues.create({
47+
owner: context.repo.owner,
48+
repo: context.repo.repo,
49+
title: "${{ env.build_name }} Workflow ${{ github.run_number }} Failed! ",
50+
body: body
51+
});
52+
53+
dockerBuildPush:
54+
runs-on: ubuntu-latest
55+
needs: build
56+
57+
steps:
58+
- uses: actions/checkout@v3
59+
60+
- name: Docker Login
61+
# You may pin to the exact commit or the version.
62+
# uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
63+
uses: docker/[email protected]
64+
with:
65+
# Server address of Docker registry. If not set then will default to Docker Hub
66+
registry: ${{ secrets.ACR_LOGIN_SERVER }}
67+
# Username used to log against the Docker registry
68+
username: ${{ secrets.ACR_USERNAME }}
69+
# Password or personal access token used to log against the Docker registry
70+
password: ${{ secrets.ACR_PASSWORD }}
71+
# Log out from the Docker registry at the end of a job
72+
logout: true
73+
74+
- name: Docker Build
75+
run: docker build -t $registryName/$repositoryName:$tag --build-arg build_version=$tag $dockerFolderPath
76+
77+
- name: Docker Push
78+
run: docker push $registryName/$repositoryName:$tag
79+
80+
deploy-to-dev:
81+
82+
runs-on: ubuntu-latest
83+
needs: dockerBuildPush
84+
environment:
85+
name: dev
86+
url: https://{your_prefix}-dev.azurewebsites.net/
87+
88+
steps:
89+
- name: 'Login via Azure CLI'
90+
uses: azure/[email protected]
91+
with:
92+
creds: ${{ secrets.AZURE_CREDENTIALS }}
93+
94+
- uses: azure/webapps-deploy@v2
95+
with:
96+
app-name: '{your_prefix}-dev'
97+
images: {your_registry_name}.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}
98+
99+
deploy-to-test:
100+
101+
runs-on: ubuntu-latest
102+
needs: deploy-to-dev
103+
environment:
104+
name: test
105+
url: https://{your_prefix}-test.azurewebsites.net/
106+
107+
steps:
108+
- uses: actions/checkout@v3
109+
110+
- name: 'Login via Azure CLI'
111+
uses: azure/[email protected]
112+
with:
113+
creds: ${{ secrets.AZURE_CREDENTIALS }}
114+
115+
- uses: azure/webapps-deploy@v2
116+
with:
117+
app-name: '{your_prefix}-test'
118+
images: {your_registry_name}.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}
119+
120+
deploy-to-prod:
121+
122+
runs-on: ubuntu-latest
123+
needs: deploy-to-test
124+
environment:
125+
name: prod
126+
url: https://{your_prefix}-prod.azurewebsites.net/
127+
128+
steps:
129+
- uses: actions/checkout@v3
130+
131+
- name: 'Login via Azure CLI'
132+
uses: azure/[email protected]
133+
with:
134+
creds: ${{ secrets.AZURE_CREDENTIALS }}
135+
136+
- uses: azure/webapps-deploy@v2
137+
with:
138+
app-name: '{your_prefix}-prod'
139+
images: {your_registry_name}.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "GitHubDevOpsCredential",
3+
"issuer": "https://token.actions.githubusercontent.com",
4+
"subject": "repo:raffaeu/TechExcel-Accelerate-developer-productivity-with-GitHub-Copilot-and-Dev-Box:ref:refs/heads/main",
5+
"description": "Deploy Azure resources from the TechExcel DevOps practices GitHub repo",
6+
"audiences": [
7+
"api://AzureADTokenExchange"
8+
]
9+
}
10+

src/InfrastructureAsCode/main.bicep

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,98 @@ var webAppName = '${uniqueString(resourceGroup().id)}-${environment}'
88
var appServicePlanName = '${uniqueString(resourceGroup().id)}-mpnp-asp'
99
var logAnalyticsName = '${uniqueString(resourceGroup().id)}-mpnp-la'
1010
var appInsightsName = '${uniqueString(resourceGroup().id)}-mpnp-ai'
11-
var sku = 'S1'
11+
var sku = 'P0V3'
1212
var registryName = '${uniqueString(resourceGroup().id)}mpnpreg'
1313
var registrySku = 'Standard'
1414
var imageName = 'techexcel/dotnetcoreapp'
1515
var startupCommand = ''
1616

17-
// TODO: complete this script
17+
18+
resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2021-12-01-preview' = {
19+
name: logAnalyticsName
20+
location: location
21+
properties: {
22+
sku: {
23+
name: 'PerGB2018'
24+
}
25+
retentionInDays: 90
26+
workspaceCapping: {
27+
dailyQuotaGb: 1
28+
}
29+
}
30+
}
31+
32+
resource appInsights 'Microsoft.Insights/components@2020-02-02-preview' = {
33+
name: appInsightsName
34+
location: location
35+
kind: 'web'
36+
properties: {
37+
Application_Type: 'web'
38+
WorkspaceResourceId: logAnalyticsWorkspace.id
39+
}
40+
}
41+
42+
resource containerRegistry 'Microsoft.ContainerRegistry/registries@2020-11-01-preview' = {
43+
name: registryName
44+
location: location
45+
sku: {
46+
name: registrySku
47+
}
48+
properties: {
49+
adminUserEnabled: true
50+
}
51+
}
52+
53+
resource appServicePlan 'Microsoft.Web/serverFarms@2022-09-01' = {
54+
name: appServicePlanName
55+
location: location
56+
kind: 'linux'
57+
properties: {
58+
reserved: true
59+
}
60+
sku: {
61+
name: sku
62+
}
63+
}
64+
65+
resource appServiceApp 'Microsoft.Web/sites@2020-12-01' = {
66+
name: webAppName
67+
location: location
68+
properties: {
69+
serverFarmId: appServicePlan.id
70+
httpsOnly: true
71+
clientAffinityEnabled: false
72+
siteConfig: {
73+
linuxFxVersion: 'DOCKER|${containerRegistry.name}.azurecr.io/${uniqueString(resourceGroup().id)}/${imageName}'
74+
http20Enabled: true
75+
minTlsVersion: '1.2'
76+
appCommandLine: startupCommand
77+
appSettings: [
78+
{
79+
name: 'WEBSITES_ENABLE_APP_SERVICE_STORAGE'
80+
value: 'false'
81+
}
82+
{
83+
name: 'DOCKER_REGISTRY_SERVER_URL'
84+
value: 'https://${containerRegistry.name}.azurecr.io'
85+
}
86+
{
87+
name: 'DOCKER_REGISTRY_SERVER_USERNAME'
88+
value: containerRegistry.name
89+
}
90+
{
91+
name: 'DOCKER_REGISTRY_SERVER_PASSWORD'
92+
value: containerRegistry.listCredentials().passwords[0].value
93+
}
94+
{
95+
name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
96+
value: appInsights.properties.InstrumentationKey
97+
}
98+
]
99+
}
100+
}
101+
}
102+
103+
output application_name string = appServiceApp.name
104+
output application_url string = appServiceApp.properties.hostNames[0]
105+
output container_registry_name string = containerRegistry.name

0 commit comments

Comments
 (0)