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

DNS clean up #55

Merged
merged 2 commits into from
Jun 7, 2024
Merged
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
6 changes: 1 addition & 5 deletions .github/workflows/continuous-delivery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ jobs:
name: Apply infrastructure
uses: ./.github/workflows/reusable-apply-infrastructure.yaml
with:
suffix: production
environment: production
cloudSubDomain: cloud
dotnetSubDomain: dotnet
deployDns: true
secrets: inherit

build-cloud-application:
Expand All @@ -35,7 +33,6 @@ jobs:
with:
application: cloud
storageAccount: ${{ needs.apply-infrastructure.outputs.cloudStorageAccount }}
resourceGroup: ${{ needs.apply-infrastructure.outputs.resourceGroup }}
environment: production
needs: [apply-infrastructure, build-cloud-application]
secrets: inherit
Expand All @@ -53,7 +50,6 @@ jobs:
with:
application: dotnet
storageAccount: ${{ needs.apply-infrastructure.outputs.dotnetStorageAccount }}
resourceGroup: ${{ needs.apply-infrastructure.outputs.resourceGroup }}
environment: production
needs: [apply-infrastructure, build-dotnet-application]
secrets: inherit
20 changes: 2 additions & 18 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,13 @@ permissions:
pull-requests: write

jobs:
create-subdomain-hash:
name: Create a deterministic subdomain hash based on the branch name
runs-on: ubuntu-latest
outputs:
subdomainHash: ${{ steps.generateHash.outputs.hash }}
steps:
- id: generateHash
run: |
branch_hash=($(sha1sum <<< ${{ github.head_ref }} | rev | cut -c 32- | rev))
echo -n "hash=$branch_hash" >> "$GITHUB_OUTPUT"

apply-infrastructure:
name: Apply infrastructure
if: github.event.action != 'closed'
uses: ./.github/workflows/reusable-apply-infrastructure.yaml
with:
environment: preview
cloudSubDomain: ${{ needs.create-subdomain-hash.outputs.subdomainHash }}.cloud
dotnetSubDomain: ${{ needs.create-subdomain-hash.outputs.subdomainHash }}.dotnet
needs: [create-subdomain-hash]
deployDns: false
secrets: inherit

build-cloud-application:
Expand All @@ -49,7 +37,6 @@ jobs:
with:
application: cloud
storageAccount: ${{ needs.apply-infrastructure.outputs.cloudStorageAccount }}
resourceGroup: ${{ needs.apply-infrastructure.outputs.resourceGroup }}
environment: preview
needs: [apply-infrastructure, build-cloud-application]
secrets: inherit
Expand All @@ -69,7 +56,6 @@ jobs:
with:
application: dotnet
storageAccount: ${{ needs.apply-infrastructure.outputs.dotnetStorageAccount }}
resourceGroup: ${{ needs.apply-infrastructure.outputs.resourceGroup }}
environment: preview
needs: [apply-infrastructure, build-dotnet-application]
secrets: inherit
Expand All @@ -80,6 +66,4 @@ jobs:
uses: ./.github/workflows/reusable-destroy-infrastructure.yaml
with:
environment: preview
resourcegroup: ${{ needs.apply-infrastructure.outputs.resourceGroup }}
needs: [apply-infrastructure]
secrets: inherit
9 changes: 3 additions & 6 deletions .github/workflows/reusable-apply-infrastructure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ on:
environment:
required: true
type: string
cloudSubDomain:
deployDns:
required: true
type: string
dotnetSubDomain:
required: true
type: string
type: boolean
outputs:
cloudStorageAccount:
value: ${{ jobs.apply-infrastructure.outputs.cloudStorageAccount }}
Expand Down Expand Up @@ -52,7 +49,7 @@ jobs:
scope: subscription
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
template: ./infrastructure/websiteDeploy.bicep
parameters: "resourceGroupSuffix=${{ env.GITHUB_REF_NAME_SLUG }} cloudSubDomain=${{ inputs.cloudSubDomain }} dotnetSubDomain=${{ inputs.dotnetSubDomain }}"
parameters: "resourceGroupSuffix=${{ env.GITHUB_REF_NAME_SLUG }} deployDns=${{ inputs.deployDns }}"
region: westeurope

- name: Comment Website FQDNs on Pull Requests
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/reusable-deploy-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ on:
storageAccount:
required: true
type: string
resourceGroup:
required: true
type: string

jobs:
deploy-application:
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/reusable-destroy-infrastructure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ on:
environment:
required: true
type: string
resourcegroup:
required: true
type: string

jobs:
destroy-infrastructure:
Expand All @@ -26,8 +23,13 @@ jobs:
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Slugify Github variables
uses: rlespinasse/github-slug-action@v4
with:
slug-maxlength: 50

- name: Remove resource group
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: az group delete --name ${{ inputs.resourcegroup }} --yes
inlineScript: az group delete --name rg-xprtzbv-website-${{ env.GITHUB_REF_NAME_SLUG }} --yes
1 change: 1 addition & 0 deletions infrastructure/modules/storageAccount.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ resource websiteStorageAccount 'Microsoft.Storage/storageAccounts@2023-04-01' =
}
}
output storageAccountName string = websiteStorageAccount.name
output storageAccountFqdn string = websiteStorageAccount.properties.primaryEndpoints.web
output storageAccountHost string = split(websiteStorageAccount.properties.primaryEndpoints.web, '/')[2]

resource websiteStorageBlobServices 'Microsoft.Storage/storageAccounts/blobServices@2023-04-01' existing = {
Expand Down
31 changes: 17 additions & 14 deletions infrastructure/websiteDeploy.bicep
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
targetScope = 'subscription'

param resourceGroupSuffix string
param deployDns bool
param frontDoorProfileName string = 'afd-xprtzbv-websites'
param rootDomain string = 'xprtz.dev'
param dotnetSubDomain string
param cloudSubDomain string

var resourceGroupPrefix = 'rg-xprtzbv-website'
var resourceGroupName = endsWith(resourceGroupSuffix, 'main')
Expand All @@ -29,29 +28,29 @@ module cloudStorageAccountModule 'modules/storageAccount.bicep' = {
scope: websiteResourceGroup
name: 'cloudStorageAccountDeploy'
params: {
app: 'cloud'
app: cloudApplicationName
}
}

module cloudFrontDoorSettings 'modules/frontdoor.bicep' = {
module cloudFrontDoorSettings 'modules/frontdoor.bicep' = if (deployDns) {
scope: infrastructureResourceGroup
name: 'cloudFrontDoorSettingsDeploy'
params: {
frontDoorOriginHost: cloudStorageAccountModule.outputs.storageAccountHost
frontDoorProfileName: frontDoorProfileName
application: cloudApplicationName
rootDomain: rootDomain
subDomain: cloudSubDomain
subDomain: cloudApplicationName
}
}

module cloudDnsSettings 'modules/dns.bicep' = {
module cloudDnsSettings 'modules/dns.bicep' = if (deployDns) {
scope: managementResourceGroup
name: 'cloudDnsSettingsDeploy'
params: {
origin: cloudFrontDoorSettings.outputs.frontDoorCustomDomainHost
rootDomain: rootDomain
subDomain: cloudSubDomain
subDomain: cloudApplicationName
validationToken: cloudFrontDoorSettings.outputs.frontDoorCustomDomainValidationToken
}
}
Expand All @@ -60,35 +59,39 @@ module dotnetStorageAccountModule 'modules/storageAccount.bicep' = {
scope: websiteResourceGroup
name: 'dotnetStorageAccountDeploy'
params: {
app: 'dotnet'
app: dotnetApplicationName
}
}

module dotnetFrontDoorSettings 'modules/frontdoor.bicep' = {
module dotnetFrontDoorSettings 'modules/frontdoor.bicep' = if (deployDns) {
scope: infrastructureResourceGroup
name: 'dotnetFrontDoorSettingsDeploy'
params: {
frontDoorOriginHost: dotnetStorageAccountModule.outputs.storageAccountHost
frontDoorProfileName: frontDoorProfileName
application: dotnetApplicationName
rootDomain: rootDomain
subDomain: dotnetSubDomain
subDomain: dotnetApplicationName
}
}

module dotnetDnsSettings 'modules/dns.bicep' = {
module dotnetDnsSettings 'modules/dns.bicep' = if (deployDns) {
scope: managementResourceGroup
name: 'dotnetDnsSettingsDeploy'
params: {
origin: dotnetFrontDoorSettings.outputs.frontDoorCustomDomainHost
rootDomain: rootDomain
subDomain: dotnetSubDomain
subDomain: dotnetApplicationName
validationToken: dotnetFrontDoorSettings.outputs.frontDoorCustomDomainValidationToken
}
}

output cloudStorageAccountName string = cloudStorageAccountModule.outputs.storageAccountName
output dotnetStorageAccountName string = dotnetStorageAccountModule.outputs.storageAccountName
output resourceGroupName string = websiteResourceGroup.name
output cloudFqdn string = 'https://${cloudSubDomain}.${rootDomain}/'
output dotnetFqdn string = 'https://${dotnetSubDomain}.${rootDomain}/'
output cloudFqdn string = deployDns
? 'https://${cloudApplicationName}.${rootDomain}/'
: cloudStorageAccountModule.outputs.storageAccountFqdn
output dotnetFqdn string = deployDns
? 'https://${dotnetApplicationName}.${rootDomain}/'
: dotnetStorageAccountModule.outputs.storageAccountFqdn