Skip to content

Commit

Permalink
Merge branch 'main' into sg/remove-track-name
Browse files Browse the repository at this point in the history
  • Loading branch information
russdaygh authored Apr 25, 2024
2 parents d54fe8f + 238c6e4 commit d5ebc7c
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/DeployBranchPush.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
branches-ignore:
- 'main'


jobs:
deploy_to_test:
uses: ./.github/workflows/DeployEverything.yml
Expand All @@ -14,3 +13,5 @@ jobs:
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
AZURE_STATIC_WEB_APPS_API_TOKEN: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
TERRAFORM_STATE_ACCESS_KEY: ${{ secrets.TERRAFORM_STATE_ACCESS_KEY }}
CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
8 changes: 7 additions & 1 deletion .github/workflows/DeployEverything.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ on:
required: true
TERRAFORM_STATE_ACCESS_KEY:
required: true
CLOUDFLARE_TOKEN:
required: true
CLOUDFLARE_ACCOUNT_ID:
required: true

env:
AZURE_WEBAPP_PACKAGE_PATH: PocketDDD.Server.WebAPI/publish
Expand Down Expand Up @@ -40,9 +44,10 @@ jobs:
- run: |
terraform init -backend-config="key=${{ inputs.env }}.terraform.tfstate"
terraform apply -auto-approve --var-file ../tfvars/${{ inputs.env }}.tfvars
terraform apply -auto-approve -var-file ../tfvars/${{ inputs.env }}.tfvars -var 'cloudflare_account_id=${{ secrets.CLOUDFLARE_ACCOUNT_ID }}'
env:
ARM_ACCESS_KEY: ${{ secrets.TERRAFORM_STATE_ACCESS_KEY }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
build_api_server:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -104,6 +109,7 @@ jobs:

- run: |
cp PocketDDD.BlazorClient/PocketDDD.BlazorClient/wwwroot/appsettings.${{ inputs.env }}.json PocketDDD.BlazorClient/PocketDDD.BlazorClient/wwwroot/appsettings.Production.json
if: ${{ inputs.env != 'Production' }}
- run: |
apiToken=$(az staticwebapp secrets list --name pocketddd-${{ inputs.env }}-blazorclient --query "properties.apiKey" -o tsv)
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/DeployMainBranch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Deploy Main to Production
on:
push:
branches:
- 'main'
- 'fixProdDeployment'

jobs:
deploy_to_production:
uses: ./.github/workflows/DeployEverything.yml
with:
env: "Production"
secrets:
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
AZURE_STATIC_WEB_APPS_API_TOKEN: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
TERRAFORM_STATE_ACCESS_KEY: ${{ secrets.TERRAFORM_STATE_ACCESS_KEY }}
CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
Blazor.start({
environment: "Development"
});
} else if (window.location.hostname.includes("test2")) {
console.info("Env = Test2")
Blazor.start({
environment: "Test2"
});
} else if (window.location.hostname.includes("test")) {
console.info("Env = Test")
Blazor.start({
Expand Down
21 changes: 19 additions & 2 deletions terraform/blazor_client.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ resource "azurerm_static_web_app" "blazor-client" {
sku_size = var.client_sku_size

app_settings = {
"ASPNETCORE_ENVIRONMENT": "${ var.env }"
"DOTNET_ENVIRONMENT": "${ var.env }"
"apiUrl": "https://pocketddd-${ var.env }-api-server-web-app.azurewebsites.net/api/"
"fakeBackend": "false"
}
Expand All @@ -21,3 +19,22 @@ resource "azurerm_key_vault_secret" "blazor_client_deployment_token" {
value = azurerm_static_web_app.blazor-client.api_key
key_vault_id = azurerm_key_vault.key_vault.id
}

data "cloudflare_zone" "dns_zone" {
account_id = var.cloudflare_account_id
name = "dddsouthwest.com"
}

resource "cloudflare_record" "cname_record" {
zone_id = data.cloudflare_zone.dns_zone.id
name = local.subdomain
value = azurerm_static_web_app.blazor-client.default_host_name
type = "CNAME"
ttl = 3600
}

resource "azurerm_static_web_app_custom_domain" "custom_domain" {
static_web_app_id = azurerm_static_web_app.blazor-client.id
domain_name = "${cloudflare_record.cname_record.name}.${data.cloudflare_zone.dns_zone.name}"
validation_type = "cname-delegation"
}
1 change: 1 addition & 0 deletions terraform/locals.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
locals {
resource_prefix = "pocketddd-${var.env}"
sql_server_name = "${local.resource_prefix}-sql-server"
subdomain = var.env == "prod" ? "pocket" : "pocket-${var.env}"
}
4 changes: 4 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
output "api_server_url" {
value = "https://${azurerm_linux_web_app.api_server_web_app.default_hostname}/"
}

output "client_app_public_url" {
value = "https://${azurerm_static_web_app_custom_domain.custom_domain.domain_name}"
}
4 changes: 4 additions & 0 deletions terraform/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ terraform {
source = "hashicorp/random"
version = "3.6.1"
}
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 4.0"
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ variable "client_sku_size" {
nullable = false
type = string
}

variable "cloudflare_account_id" {
nullable = false
type = string
}
21 changes: 15 additions & 6 deletions tfvars/Production.tfvars
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
env = "prod"
sql_db_sku = "S0"
sql_max_storage = "10"
env = "production"
sql_db_sku = "Basic"
sql_max_storage = "2"
api_app_service_sku = "B1"
api_always_on = true
client_sku_tier = "Standard"
client_sku_size = "Standard"
api_always_on = false
client_sku_tier = "Free"
client_sku_size = "Free"

# Real prod values
# env = "prod"
# sql_db_sku = "S0"
# sql_max_storage = "10"
# api_app_service_sku = "B1"
# api_always_on = true
# client_sku_tier = "Standard"
# client_sku_size = "Standard"

0 comments on commit d5ebc7c

Please sign in to comment.