Skip to content

Commit a6e58d7

Browse files
authored
Deploy terraform from GitHub (#8)
Automate deployment of terraform and apps
1 parent 7b12655 commit a6e58d7

21 files changed

Lines changed: 268 additions & 109 deletions

.github/workflows/DeployBlazorClient.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: Build and deploy Pocket DDD Blazor Client
22

33
on:
44
workflow_dispatch:
5-
push:
65

76
jobs:
87
build_and_deploy_job:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Deploy Branch Push
2+
on:
3+
push:
4+
branches-ignore:
5+
- 'main'
6+
7+
8+
jobs:
9+
deploy_to_test:
10+
uses: ./.github/workflows/DeployEverything.yml
11+
with:
12+
env: "Test2"
13+
secrets:
14+
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
15+
AZURE_STATIC_WEB_APPS_API_TOKEN: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
16+
TERRAFORM_STATE_ACCESS_KEY: ${{ secrets.TERRAFORM_STATE_ACCESS_KEY }}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Deploy Everything
2+
on:
3+
workflow_call:
4+
inputs:
5+
env:
6+
required: true
7+
default: "Test"
8+
type: string
9+
secrets:
10+
AZURE_CREDENTIALS:
11+
required: true
12+
AZURE_STATIC_WEB_APPS_API_TOKEN:
13+
required: true
14+
TERRAFORM_STATE_ACCESS_KEY:
15+
required: true
16+
17+
env:
18+
AZURE_WEBAPP_PACKAGE_PATH: PocketDDD.Server.WebAPI/publish
19+
CONFIGURATION: Release
20+
DOTNET_CORE_VERSION: 8.0.x
21+
WORKING_DIRECTORY: PocketDDD.Server/PocketDDD.Server.WebAPI
22+
23+
jobs:
24+
deploy_terraform:
25+
runs-on: ubuntu-latest
26+
name: Deploy terraform
27+
environment: ${{ inputs.env }}
28+
defaults:
29+
run:
30+
working-directory: ./terraform
31+
32+
steps:
33+
- uses: actions/checkout@v4
34+
- name: Log in with Azure
35+
uses: azure/login@v1
36+
with:
37+
creds: '${{ secrets.AZURE_CREDENTIALS }}'
38+
- name: Setup terraform
39+
uses: hashicorp/setup-terraform@v3
40+
- run: |
41+
terraform init -backend-config="key=${{ inputs.env }}.terraform.tfstate"
42+
43+
terraform apply -auto-approve --var-file ../tfvars/${{ inputs.env }}.tfvars
44+
env:
45+
ARM_ACCESS_KEY: ${{ secrets.TERRAFORM_STATE_ACCESS_KEY }}
46+
47+
build_api_server:
48+
runs-on: ubuntu-latest
49+
name: Build API Server
50+
steps:
51+
- uses: actions/checkout@v4
52+
- name: Setup .NET SDK
53+
uses: actions/setup-dotnet@v4
54+
with:
55+
dotnet-version: ${{ env.DOTNET_CORE_VERSION }}
56+
- name: Restore
57+
run: dotnet restore "${{ env.WORKING_DIRECTORY }}"
58+
- name: Build
59+
run: dotnet build "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-restore
60+
- name: Test
61+
run: dotnet test "${{ env.WORKING_DIRECTORY }}" --no-build
62+
- name: Publish
63+
run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.AZURE_WEBAPP_PACKAGE_PATH }}"
64+
- name: Publish Artifacts
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: webapp
68+
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
69+
70+
deploy_api_server:
71+
name: Deploy API Server
72+
runs-on: ubuntu-latest
73+
environment: ${{ inputs.env }}
74+
needs: [deploy_terraform, build_api_server]
75+
steps:
76+
- name: Log in with Azure
77+
uses: azure/login@v1
78+
with:
79+
creds: '${{ secrets.AZURE_CREDENTIALS }}'
80+
- name: Download artifact from build job
81+
uses: actions/download-artifact@v4
82+
with:
83+
name: webapp
84+
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
85+
- name: Deploy to Azure WebApp
86+
uses: azure/webapps-deploy@v2
87+
with:
88+
app-name: pocketddd-${{ inputs.env }}-api-server-web-app
89+
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
90+
91+
build_and_deploy_blazor_client:
92+
runs-on: ubuntu-latest
93+
environment: ${{ inputs.env }}
94+
name: Build and Deploy Blazor Client
95+
needs: deploy_terraform
96+
steps:
97+
- uses: actions/checkout@v2
98+
with:
99+
submodules: true
100+
- name: Log in with Azure
101+
uses: azure/login@v1
102+
with:
103+
creds: '${{ secrets.AZURE_CREDENTIALS }}'
104+
105+
- run: |
106+
cp PocketDDD.BlazorClient/PocketDDD.BlazorClient/wwwroot/appsettings.${{ inputs.env }}.json PocketDDD.BlazorClient/PocketDDD.BlazorClient/wwwroot/appsettings.Production.json
107+
108+
- run: |
109+
apiToken=$(az staticwebapp secrets list --name pocketddd-${{ inputs.env }}-blazorclient --query "properties.apiKey" -o tsv)
110+
echo "WEB_APP_API_TOKEN=$apiToken" >> "$GITHUB_ENV"
111+
112+
- name: Build And Deploy
113+
id: builddeploy
114+
uses: Azure/static-web-apps-deploy@v1
115+
with:
116+
azure_static_web_apps_api_token: ${{ env.WEB_APP_API_TOKEN }}
117+
repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
118+
action: "upload"
119+
###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
120+
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
121+
app_location: "/PocketDDD.BlazorClient/PocketDDD.BlazorClient" # App source code path
122+
api_location: "" # Api source code path - optional
123+
output_location: "wwwroot" # Built app content directory - optional
124+
###### End of Repository/Build Configurations ######

.github/workflows/DeployServerWebAPI.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: Build and deploy Pocket DDD Server
22
on:
33
workflow_dispatch:
4-
push:
54

65
env:
76
AZURE_WEBAPP_PACKAGE_PATH: PocketDDD.Server.WebAPI/publish
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"apiUrl": "https://dddsw2023pocketdddserverwebapi.azurewebsites.net/api/",
2+
"apiUrl": "https://pocketddd-production-api-server-web-app.azurewebsites.net/api/",
33
"fakeBackend": false
44
}

PocketDDD.BlazorClient/PocketDDD.BlazorClient/wwwroot/appsettings.Test.json

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"apiUrl": "https://pocketddd-test2-api-server-web-app.azurewebsites.net/api/",
3+
"fakeBackend": false
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"apiUrl": "https://pocketddd-test-api-server-web-app.azurewebsites.net/api/",
3+
"fakeBackend": false
4+
}

PocketDDD.Server/PocketDDD.Server.DB/Migrations/2024_SeedData.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ delete EventDetail
88

99
GO
1010

11-
DBCC CHECKIDENT ('[EventDetail]', RESEED, 0);
11+
DBCC CHECKIDENT ('[EventDetail]', RESEED, 1);
1212
DBCC CHECKIDENT ('[Tracks]', RESEED, 0);
1313
DBCC CHECKIDENT ('[TimeSlots]', RESEED, 0);
1414
DBCC CHECKIDENT ('[Sessions]', RESEED, 0);

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Authorization: <insert-admin-key>
1414
Ensure the Azure, GitHub, and terraform CLIs are installed
1515
```
1616
brew install azure-cli
17-
bre install gh
17+
brew install gh
1818
brew install terraform
1919
```
2020

@@ -24,11 +24,16 @@ az login
2424
gh auth login
2525
```
2626

27+
Retrieve the access key for the terraform state storage account
28+
```
29+
export ARM_ACCESS_KEY=$(az storage account keys list -g pocketddd-terraform-state -n pocketdddterraformstate --query [0].value -o tsv)
30+
```
31+
2732
From the `terraform` directory run init, plan, then apply if happy with the changes.
2833
```
2934
cd ./terraform
3035
31-
terraform init
36+
terraform init -backend-config="dev.terraform.tfstate"
3237
terraform plan -var-file ../tfvars/dev.tfvars
3338
terraform apply -var-file ../tfvars/dev.tfvars
3439
```

0 commit comments

Comments
 (0)