Skip to content

Commit 5cf973e

Browse files
authored
Deploy DNS (#9)
Deploy DNS records to Cloudflare Enable Production deployment
1 parent a6e58d7 commit 5cf973e

10 files changed

Lines changed: 77 additions & 9 deletions

File tree

.github/workflows/DeployBranchPush.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
branches-ignore:
55
- 'main'
66

7-
87
jobs:
98
deploy_to_test:
109
uses: ./.github/workflows/DeployEverything.yml
@@ -14,3 +13,5 @@ jobs:
1413
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
1514
AZURE_STATIC_WEB_APPS_API_TOKEN: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
1615
TERRAFORM_STATE_ACCESS_KEY: ${{ secrets.TERRAFORM_STATE_ACCESS_KEY }}
16+
CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
17+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

.github/workflows/DeployEverything.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ on:
1313
required: true
1414
TERRAFORM_STATE_ACCESS_KEY:
1515
required: true
16+
CLOUDFLARE_TOKEN:
17+
required: true
18+
CLOUDFLARE_ACCOUNT_ID:
19+
required: true
1620

1721
env:
1822
AZURE_WEBAPP_PACKAGE_PATH: PocketDDD.Server.WebAPI/publish
@@ -40,9 +44,10 @@ jobs:
4044
- run: |
4145
terraform init -backend-config="key=${{ inputs.env }}.terraform.tfstate"
4246
43-
terraform apply -auto-approve --var-file ../tfvars/${{ inputs.env }}.tfvars
47+
terraform apply -auto-approve -var-file ../tfvars/${{ inputs.env }}.tfvars -var 'cloudflare_account_id=${{ secrets.CLOUDFLARE_ACCOUNT_ID }}'
4448
env:
4549
ARM_ACCESS_KEY: ${{ secrets.TERRAFORM_STATE_ACCESS_KEY }}
50+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
4651
4752
build_api_server:
4853
runs-on: ubuntu-latest
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Deploy Branch Push
2+
on:
3+
push:
4+
branches:
5+
- 'main'
6+
7+
jobs:
8+
deploy_to_test:
9+
uses: ./.github/workflows/DeployEverything.yml
10+
with:
11+
env: "Production"
12+
secrets:
13+
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
14+
AZURE_STATIC_WEB_APPS_API_TOKEN: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
15+
TERRAFORM_STATE_ACCESS_KEY: ${{ secrets.TERRAFORM_STATE_ACCESS_KEY }}
16+
CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
17+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

PocketDDD.BlazorClient/PocketDDD.BlazorClient/wwwroot/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
Blazor.start({
2828
environment: "Development"
2929
});
30+
} else if (window.location.hostname.includes("test2")) {
31+
console.info("Env = Test2")
32+
Blazor.start({
33+
environment: "Test2"
34+
});
3035
} else if (window.location.hostname.includes("test")) {
3136
console.info("Env = Test")
3237
Blazor.start({

terraform/blazor_client.tf

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ resource "azurerm_static_web_app" "blazor-client" {
77
sku_size = var.client_sku_size
88

99
app_settings = {
10-
"ASPNETCORE_ENVIRONMENT": "${ var.env }"
11-
"DOTNET_ENVIRONMENT": "${ var.env }"
1210
"apiUrl": "https://pocketddd-${ var.env }-api-server-web-app.azurewebsites.net/api/"
1311
"fakeBackend": "false"
1412
}
@@ -21,3 +19,22 @@ resource "azurerm_key_vault_secret" "blazor_client_deployment_token" {
2119
value = azurerm_static_web_app.blazor-client.api_key
2220
key_vault_id = azurerm_key_vault.key_vault.id
2321
}
22+
23+
data "cloudflare_zone" "dns_zone" {
24+
account_id = var.cloudflare_account_id
25+
name = "dddsouthwest.com"
26+
}
27+
28+
resource "cloudflare_record" "cname_record" {
29+
zone_id = data.cloudflare_zone.dns_zone.id
30+
name = local.subdomain
31+
value = azurerm_static_web_app.blazor-client.default_host_name
32+
type = "CNAME"
33+
ttl = 3600
34+
}
35+
36+
resource "azurerm_static_web_app_custom_domain" "custom_domain" {
37+
static_web_app_id = azurerm_static_web_app.blazor-client.id
38+
domain_name = "${cloudflare_record.cname_record.name}.${data.cloudflare_zone.dns_zone.name}"
39+
validation_type = "cname-delegation"
40+
}

terraform/locals.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
locals {
22
resource_prefix = "pocketddd-${var.env}"
33
sql_server_name = "${local.resource_prefix}-sql-server"
4+
subdomain = var.env == "prod" ? "pocket" : "pocket-${var.env}"
45
}

terraform/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
output "api_server_url" {
22
value = "https://${azurerm_linux_web_app.api_server_web_app.default_hostname}/"
33
}
4+
5+
# output "client_app_public_url" {
6+
# value =
7+
# }

terraform/terraform.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ terraform {
1313
source = "hashicorp/random"
1414
version = "3.6.1"
1515
}
16+
cloudflare = {
17+
source = "cloudflare/cloudflare"
18+
version = "~> 4.0"
19+
}
1620
}
1721
}
1822

terraform/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,8 @@ variable "client_sku_size" {
3939
nullable = false
4040
type = string
4141
}
42+
43+
variable "cloudflare_account_id" {
44+
nullable = false
45+
type = string
46+
}

tfvars/Production.tfvars

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
env = "prod"
2-
sql_db_sku = "S0"
3-
sql_max_storage = "10"
2+
sql_db_sku = "Basic"
3+
sql_max_storage = "2"
44
api_app_service_sku = "B1"
5-
api_always_on = true
6-
client_sku_tier = "Standard"
7-
client_sku_size = "Standard"
5+
api_always_on = false
6+
client_sku_tier = "Free"
7+
client_sku_size = "Free"
8+
9+
# Real prod values
10+
# env = "prod"
11+
# sql_db_sku = "S0"
12+
# sql_max_storage = "10"
13+
# api_app_service_sku = "B1"
14+
# api_always_on = true
15+
# client_sku_tier = "Standard"
16+
# client_sku_size = "Standard"

0 commit comments

Comments
 (0)