Skip to content

Commit 7b759ba

Browse files
authored
Merge pull request #4 from dddsw/feature/terraform
Terraform!
2 parents ac4fde0 + 7b2aa5e commit 7b759ba

22 files changed

Lines changed: 352 additions & 138 deletions

.github/workflows/azure-static-web-apps-nice-flower-068ad3503.yml renamed to .github/workflows/DeployBlazorClient.yml

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
name: Azure Static Web Apps CI/CD
1+
name: Build and deploy Pocket DDD Blazor Client
22

33
on:
4+
workflow_dispatch:
45
push:
5-
branches:
6-
- main
7-
pull_request:
8-
types: [opened, synchronize, reopened, closed]
9-
branches:
10-
- main
116

127
jobs:
138
build_and_deploy_job:
14-
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
159
runs-on: ubuntu-latest
10+
environment: dev
1611
name: Build and Deploy Job
1712
steps:
1813
- uses: actions/checkout@v2
@@ -22,24 +17,13 @@ jobs:
2217
id: builddeploy
2318
uses: Azure/static-web-apps-deploy@v1
2419
with:
25-
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_NICE_FLOWER_068AD3503 }}
20+
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
2621
repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
2722
action: "upload"
2823
###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
2924
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
25+
deployment_environment: Test
3026
app_location: "/PocketDDD.BlazorClient/PocketDDD.BlazorClient" # App source code path
3127
api_location: "" # Api source code path - optional
3228
output_location: "wwwroot" # Built app content directory - optional
3329
###### End of Repository/Build Configurations ######
34-
35-
close_pull_request_job:
36-
if: github.event_name == 'pull_request' && github.event.action == 'closed'
37-
runs-on: ubuntu-latest
38-
name: Close Pull Request Job
39-
steps:
40-
- name: Close Pull Request
41-
id: closepullrequest
42-
uses: Azure/static-web-apps-deploy@v1
43-
with:
44-
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_NICE_FLOWER_068AD3503 }}
45-
action: "close"

.github/workflows/PocketDDDServerWebAPI2024.yml renamed to .github/workflows/DeployServerWebAPI.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
name: Build and deploy Pocket DDD Server to Web App PocketDDDServerWebAPI2024
1+
name: Build and deploy Pocket DDD Server
22
on:
3-
push:
4-
branches:
5-
- main
63
workflow_dispatch:
4+
push:
75

86
env:
9-
AZURE_WEBAPP_PACKAGE_PATH: PocketDDD.Server.WebAPI\publish
7+
AZURE_WEBAPP_PACKAGE_PATH: PocketDDD.Server.WebAPI/publish
108
CONFIGURATION: Release
119
DOTNET_CORE_VERSION: 8.0.x
1210
WORKING_DIRECTORY: PocketDDD.Server/PocketDDD.Server.WebAPI
1311

1412
jobs:
1513
build:
16-
runs-on: windows-latest
14+
runs-on: ubuntu-latest
1715
steps:
1816
- uses: actions/checkout@v4
1917
- name: Setup .NET SDK
@@ -35,9 +33,14 @@ jobs:
3533
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
3634

3735
deploy:
38-
runs-on: windows-latest
36+
runs-on: ubuntu-latest
37+
environment: dev
3938
needs: build
4039
steps:
40+
- name: Log in with Azure
41+
uses: azure/login@v1
42+
with:
43+
creds: '${{ secrets.AZURE_CREDENTIALS }}'
4144
- name: Download artifact from build job
4245
uses: actions/download-artifact@v3
4346
with:
@@ -46,6 +49,5 @@ jobs:
4649
- name: Deploy to Azure WebApp
4750
uses: azure/webapps-deploy@v2
4851
with:
49-
app-name: ${{ secrets.AZURE_WEBAPP_NAME }}
50-
publish-profile: ${{ secrets.PocketDDDServerWebAPI2024_3A54 }}
52+
app-name: pocketddd-dev-api-server
5153
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}

.github/workflows/azure-static-web-apps-ashy-wave-054da7003.yml

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

.github/workflows/azure-static-web-apps-happy-tree-038f26503.yml

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

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,10 @@ MigrationBackup/
351351

352352
# Rider (.NET IDE by JetBrains) working folder
353353
.idea/
354+
355+
.terraform/
356+
357+
*.tfstate
358+
*.tfstate.backup
359+
terraform/.terraform.lock.hcl
360+
terraform/.terraform.tfstate.lock.info
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"apiUrl": "https://dddsw2023pocketdddserverwebapitest.azurewebsites.net/api/",
2+
"apiUrl": "https://pocketddd-dev-api-server.azurewebsites.net/api/",
33
"fakeBackend": false
44
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
delete [UserSessionFeedback]
2+
delete [UserEventFeedback]
3+
delete [Sessions]
4+
delete TimeSlots
5+
delete Tracks
6+
delete EventDetail
7+
8+
9+
GO
10+
11+
DBCC CHECKIDENT ('[EventDetail]', RESEED, 0);
12+
DBCC CHECKIDENT ('[Tracks]', RESEED, 0);
13+
DBCC CHECKIDENT ('[TimeSlots]', RESEED, 0);
14+
DBCC CHECKIDENT ('[Sessions]', RESEED, 0);
15+
16+
GO
17+
18+
Insert into EventDetail values (1, 'kn91wz1x')
19+
20+
Insert into Tracks values (1, 'Track 1','The Junction 🚉', 0)
21+
Insert into Tracks values (1, 'Track 2','Brunel''s Boardroom 🎩🛹', 1)
22+
Insert into Tracks values (1, 'Track 3','Brunel''s Breakout room 🎩☕', 2)
23+
Insert into Tracks values (1, 'Track 4','Clock tower room ⏲', 3)
24+
25+
GO

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,34 @@
1-
# PocketDDD
1+
# PocketDDD
2+
3+
# Populating Sessionize data
4+
Auto-populating the session data from Sessionize requires a basic set of seed data. An example of this can be found in [2024_SeedData.sql](PocketDDD.Server/PocketDDD.Server.DB/Migrations/2024_SeedData.sql)
5+
6+
Once this script has been run against the DB you can call the admin endpoint to refresh the data. This requires the Admin API key which can be retrieved from Azure key vault secret `pocketddd-<env>-admin-api-key`
7+
```
8+
POST /api/eventdata/RefreshFromSessionize HTTP/1.1
9+
Host: pocketddd-dev-api-server.azurewebsites.net
10+
Authorization: <insert-admin-key>
11+
```
12+
13+
# Running terraform locally
14+
Ensure the Azure, GitHub, and terraform CLIs are installed
15+
```
16+
brew install azure-cli
17+
bre install gh
18+
brew install terraform
19+
```
20+
21+
Login to Azure and GitHub
22+
```
23+
az login
24+
gh auth login
25+
```
26+
27+
From the `terraform` directory run init, plan, then apply if happy with the changes.
28+
```
29+
cd ./terraform
30+
31+
terraform init
32+
terraform plan -var-file ../tfvars/dev.tfvars
33+
terraform apply -var-file ../tfvars/dev.tfvars
34+
```

terraform/api_server.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
resource "azurerm_service_plan" "api_server_service_plan" {
2+
name = "${local.resource_prefix}-api-server-serviceplan"
3+
resource_group_name = azurerm_resource_group.rg.name
4+
location = azurerm_resource_group.rg.location
5+
os_type = "Linux"
6+
sku_name = var.api_app_service_sku
7+
}
8+
9+
10+
resource "azurerm_linux_web_app" "api_server_web_app" {
11+
name = "${local.resource_prefix}-api-server"
12+
resource_group_name = azurerm_resource_group.rg.name
13+
location = azurerm_service_plan.api_server_service_plan.location
14+
service_plan_id = azurerm_service_plan.api_server_service_plan.id
15+
16+
site_config {
17+
application_stack {
18+
dotnet_version = "8.0"
19+
}
20+
always_on = var.api_always_on
21+
}
22+
23+
connection_string {
24+
name = "PocketDDDContext"
25+
type = "SQLAzure"
26+
value = local.db_connection_string
27+
}
28+
29+
app_settings = {
30+
"AdminKey" = random_password.admin_api_key.result
31+
}
32+
}

terraform/blazor_client.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
resource "azurerm_static_web_app" "blazor-client" {
2+
name = "${local.resource_prefix}-blazorclient"
3+
location = "westeurope"
4+
resource_group_name = azurerm_resource_group.rg.name
5+
6+
sku_tier = var.client_sku_tier
7+
sku_size = var.client_sku_size
8+
}
9+
10+
resource "github_actions_environment_secret" "test_secret" {
11+
repository = data.github_repository.repo.name
12+
environment = github_repository_environment.repo_environment.environment
13+
secret_name = "AZURE_STATIC_WEB_APPS_API_TOKEN"
14+
plaintext_value = azurerm_static_web_app.blazor-client.api_key
15+
}

0 commit comments

Comments
 (0)