Skip to content

Commit 4d8fc4b

Browse files
Karacs PéterKaracs Péter
authored andcommitted
deploy infra
1 parent 2a816ef commit 4d8fc4b

9 files changed

Lines changed: 132 additions & 257 deletions

File tree

‎.github/workflows/deploy.yml‎

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,56 @@
1-
name: Deploy Infrastructure
1+
name: Build and Deploy Bicep Template
22

33
on:
44
push:
55
branches:
6-
- main
7-
workflow_dispatch:
6+
- main
87

98
jobs:
10-
deploy:
9+
build:
1110
runs-on: ubuntu-latest
1211

1312
steps:
1413
- name: Checkout code
15-
uses: actions/checkout@v4
14+
uses: actions/checkout@v2
15+
16+
- name: Set up Azure CLI
17+
uses: azure/cli@v1.0.7
18+
with:
19+
inlineScript: |
20+
az version
1621
17-
- name: Azure Login
22+
- name: Login to Azure
1823
uses: azure/login@v1
1924
with:
2025
creds: ${{ secrets.AZURE_CREDENTIALS }}
2126

22-
- name: Deploy Bicep
23-
uses: azure/arm-deploy@v1
27+
- name: Build Bicep Template
28+
run: |
29+
# Validate the Bicep template
30+
az bicep build --file main.bicep
31+
32+
deploy:
33+
runs-on: ubuntu-latest
34+
needs: build # Ensure this job runs after the build job
35+
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v2
39+
40+
- name: Set up Azure CLI
41+
uses: azure/cli@v1.0.7
2442
with:
25-
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
26-
resourceGroupName: BCSAI2024-DEVOPS-STUDENTS-A-DEV
27-
template: ./main.bicep
28-
parameters: ./main.parameters.json
29-
failOnStdErr: false
30-
deploymentName: "github-action-deployment-${{ github.run_number }}"
43+
inlineScript: |
44+
az version
45+
46+
- name: Login to Azure
47+
uses: azure/login@v1
48+
with:
49+
creds: ${{ secrets.AZURE_CREDENTIALS }}
50+
51+
- name: Deploy Bicep Template
52+
run: |
53+
az deployment group create \
54+
--resource-group BCSAI2024-DEVOPS-STUDENTS-A-DEV \
55+
--template-file main.bicep \
56+
--parameters main.parameters.json

‎main.bicep‎

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,69 +19,31 @@ param containerRegistryImageName string
1919
@description('The version/tag of the container image')
2020
param containerRegistryImageVersion string
2121

22-
var acrUsernameSecretName = 'acr-admin-username'
23-
var acrPasswordSecretName = 'acr-admin-password1'
24-
var keyVaultName = '${name}-kv'
25-
26-
module keyVault 'modules/key-vault.bicep' = {
27-
name: 'keyVaultDeployment'
28-
params: {
29-
name: keyVaultName
30-
location: location
31-
enableVaultForDeployment: true
32-
roleAssignments: [
33-
{
34-
principalId: '7200f83e-ec45-4915-8c52-fb94147cfe5a'
35-
roleDefinitionIdOrName: 'Key Vault Secrets User'
36-
principalType: 'ServicePrincipal'
37-
}
38-
{
39-
principalId: 'f248a218-1ef9-47bf-9928-ae47093fd442' // ARM Service Principal
40-
roleDefinitionIdOrName: 'Key Vault Secrets User'
41-
principalType: 'ServicePrincipal'
42-
}
43-
{
44-
principalId: '25d8d697-c4a2-479f-96e0-15593a830ae5' // GitHub Actions Service Principal
45-
roleDefinitionIdOrName: 'Key Vault Secrets User'
46-
principalType: 'ServicePrincipal'
47-
}
48-
]
49-
}
50-
}
51-
52-
resource keyVaultResource 'Microsoft.KeyVault/vaults@2023-07-01' existing = {
53-
name: keyVaultName
54-
}
55-
56-
module containerRegistry 'modules/acr.bicep' = {
57-
name: 'registry-deployment'
22+
module containerRegistry 'modules/container-registry.bicep' = {
23+
name: 'containerRegistryDeployment'
5824
params: {
5925
name: name
6026
location: location
6127
acrAdminUserEnabled: acrAdminUserEnabled
62-
adminCredentialsKeyVaultResourceId: keyVault.outputs.id
63-
adminCredentialsKeyVaultSecretUserName: acrUsernameSecretName
64-
adminCredentialsKeyVaultSecretUserPassword1: acrPasswordSecretName
65-
adminCredentialsKeyVaultSecretUserPassword2: 'acr-admin-password2'
6628
}
6729
}
6830

69-
70-
module appServicePlan 'modules/webApp.bicep' = {
31+
module appServicePlan 'modules/app-service-plan.bicep' = {
7132
name: 'appServicePlanPeter'
7233
params: {
7334
name: 'appServicePlanPeter'
7435
location: location
7536
sku: {
7637
name: 'B1'
7738
capacity: 1
39+
family: 'B'
40+
size: 'B1'
7841
tier: 'Basic'
7942
}
8043
}
8144
}
8245

83-
84-
module appService 'modules/servicePlan.bicep' = {
46+
module appService 'modules/app-service.bicep' = {
8547
name: 'appServicePeter'
8648
params: {
8749
name: appServiceName
@@ -90,13 +52,9 @@ module appService 'modules/servicePlan.bicep' = {
9052
containerRegistryName: name
9153
containerRegistryImageName: containerRegistryImageName
9254
containerRegistryImageVersion: containerRegistryImageVersion
93-
dockerRegistryServerUrl: 'https://${containerRegistry.outputs.loginServer}'
94-
dockerRegistryServerUserName: keyVaultResource.getSecret(acrUsernameSecretName)
95-
dockerRegistryServerPassword: keyVaultResource.getSecret(acrPasswordSecretName)
9655
}
9756
}
9857

99-
10058
output containerRegistryLoginServer string = containerRegistry.outputs.loginServer
10159
output appServiceId string = appService.outputs.id
10260
output appServiceName string = appService.outputs.name

‎main.parameters.json‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
{
2-
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json",
33
"contentVersion": "1.0.0.0",
44
"parameters": {
55
"location": {
6-
"value": "westeurope"
6+
"value": "northeurope"
77
},
8-
"acrName": {
9-
"value": "demoacr${uniqueString(resourceGroup().id)}"
8+
"name": {
9+
"value": "PeterAppRegistry"
1010
},
11-
"servicePlanName": {
12-
"value": "myServicePlan"
13-
},
14-
"webAppName": {
15-
"value": "demo-webapp"
11+
"appServiceName": {
12+
"value": "PeterAppService"
1613
},
1714
"containerRegistryImageName": {
18-
"value": "demo-image"
15+
"value": "PeterAppRegistry"
1916
},
2017
"containerRegistryImageVersion": {
2118
"value": "latest"
2219
}
2320
}
24-
}
21+
}

‎modules/acr.bicep‎

Lines changed: 0 additions & 65 deletions
This file was deleted.

‎modules/app-service.bicep‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@description('The name of the App Service')
2+
param name string
3+
4+
@description('The location for the App Service')
5+
param location string
6+
7+
@description('The name of the App Service Plan')
8+
param appServicePlanName string
9+
10+
@description('The name of the Container Registry')
11+
param containerRegistryName string
12+
13+
@description('The name of the container image')
14+
param containerRegistryImageName string
15+
16+
@description('The version/tag of the container image')
17+
param containerRegistryImageVersion string
18+
19+
resource containerRegistry 'Microsoft.ContainerRegistry/registries@2023-07-01' existing = {
20+
name: containerRegistryName
21+
}
22+
23+
resource appService 'Microsoft.Web/sites@2022-03-01' = {
24+
name: name
25+
location: location
26+
kind: 'app'
27+
properties: {
28+
serverFarmId: resourceId('Microsoft.Web/serverfarms', appServicePlanName)
29+
siteConfig: {
30+
linuxFxVersion: 'DOCKER|${containerRegistry.properties.loginServer}/${containerRegistryImageName}:${containerRegistryImageVersion}'
31+
appCommandLine: ''
32+
appSettings: [
33+
{
34+
name: 'WEBSITES_ENABLE_APP_SERVICE_STORAGE'
35+
value: 'false'
36+
}
37+
{
38+
name: 'DOCKER_REGISTRY_SERVER_URL'
39+
value: 'https://${containerRegistry.properties.loginServer}/'
40+
}
41+
{
42+
name: 'DOCKER_REGISTRY_SERVER_USERNAME'
43+
value: containerRegistry.listCredentials().username
44+
}
45+
{
46+
name: 'DOCKER_REGISTRY_SERVER_PASSWORD'
47+
value: containerRegistry.listCredentials().passwords[0].value
48+
}
49+
]
50+
}
51+
}
52+
}
53+
54+
output id string = appService.id
55+
output name string = appService.name
56+
output defaultHostName string = appService.properties.defaultHostName

‎modules/container-registry.bicep‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
@description('The name of the Azure Container Registry')
3+
param name string
4+
5+
@description('The location for the Azure Container Registry')
6+
param location string
7+
8+
@description('Enable admin user for the Azure Container Registry')
9+
param acrAdminUserEnabled bool = true
10+
11+
resource containerRegistry 'Microsoft.ContainerRegistry/registries@2023-07-01' = {
12+
name: name
13+
location: location
14+
sku: {
15+
name: 'Basic'
16+
}
17+
properties: {
18+
adminUserEnabled: acrAdminUserEnabled
19+
}
20+
}
21+
22+
output loginServer string = containerRegistry.properties.loginServer

‎modules/key-vault.bicep‎

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)