-
Notifications
You must be signed in to change notification settings - Fork 1
132 lines (128 loc) · 4.8 KB
/
instance-deploy-prod.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: "Instance - deploy prod"
on:
push:
branches: [main]
workflow_dispatch:
jobs:
build-api:
uses: benchiverton/OnlineStore/.github/workflows/workflow-build-test-publish-dotnet.yml@main
with:
solution_file: "src/Api/Company.Api.sln"
project_file: "src/Api/Company.Api/Company.Api.csproj"
dotnet_version: 8.0.203
dockerfile_name: "src/Api/Company.Api/dockerfile"
image_name: "onlinestore-api"
secrets: inherit
build-website:
uses: benchiverton/OnlineStore/.github/workflows/workflow-build-test-publish-dotnet.yml@main
with:
solution_file: "src/Website/Company.Website.sln"
project_file: "src/Website/Company.Website/Company.Website.csproj"
dotnet_version: 8.0.203
dockerfile_name: "src/Website/Company.Website/dockerfile"
image_name: "onlinestore-website"
secrets: inherit
deploy-terraform-prod:
needs: [build-api, build-website]
environment: prod
env:
ARM_CLIENT_ID: ${{ secrets.TF_VAR_AGENT_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.TF_VAR_AGENT_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.TF_VAR_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.TF_VAR_TENANT_ID }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: "./terraform"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_wrapper: false
- name: Terraform Format
id: fmt
run: terraform -chdir=instance fmt
- name: Terraform Init
id: init
run: terraform -chdir=instance init -backend-config="container_name=onlinestoretfstate-prod"
- name: Terraform Validate
id: validate
run: terraform -chdir=instance validate -no-color
- name: Terraform Plan
id: plan
run: terraform -chdir=instance plan -no-color
env:
TF_VAR_location: "East US"
TF_VAR_environment: prod
TF_VAR_acr_username: ${{ secrets.ACR_USERNAME }}
TF_VAR_acr_password: ${{ secrets.ACR_TOKEN }}
TF_VAR_website_dns_subdomain: www
TF_VAR_api_dns_subdomain: api
TF_VAR_monitoring_dns_subdomain: monitoring
- name: Terraform Apply
id: apply
run: terraform -chdir=instance apply -auto-approve
env:
TF_VAR_location: "East US"
TF_VAR_environment: prod
TF_VAR_acr_username: ${{ secrets.ACR_USERNAME }}
TF_VAR_acr_password: ${{ secrets.ACR_TOKEN }}
TF_VAR_website_dns_subdomain: www
TF_VAR_api_dns_subdomain: api
TF_VAR_monitoring_dns_subdomain: monitoring
- name: Save terraform outputs
shell: bash
run: |
mkdir terraform-outputs
terraform -chdir=instance output -raw resource_group_name > terraform-outputs/resource_group_name.txt
- name: Upload terraform outputs for deploy job
uses: actions/upload-artifact@v3
with:
name: terraform-outputs
path: terraform/terraform-outputs/
deploy-app-prod:
needs: [deploy-terraform-prod]
environment: prod
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download terraform outputs
uses: actions/download-artifact@v3
with:
name: terraform-outputs
- name: Set terraform outputs as env variables
id: vars
shell: bash
run: |
echo "resource_group_name=$(cat resource_group_name.txt)" >> $GITHUB_ENV
- name: Login via Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Deploy api
uses: azure/container-apps-deploy-action@v1
with:
acrName: onlinestorecontainerregistry
acrUsername: ${{ secrets.ACR_USERNAME }}
acrPassword: ${{ secrets.ACR_TOKEN }}
containerAppName: prod-onlinestore-api
imageToDeploy: onlinestorecontainerregistry.azurecr.io/onlinestore-api:${{ github.sha }}
location: 'East US'
resourceGroup: onlinestore-shared-rg
targetPort: 8080
environmentVariables: OTEL_EXPORTER_OTLP_ENDPOINT=http://prod-onlinestore-monitoring:18889
- name: Deploy website
uses: azure/container-apps-deploy-action@v1
with:
acrName: onlinestorecontainerregistry
acrUsername: ${{ secrets.ACR_USERNAME }}
acrPassword: ${{ secrets.ACR_TOKEN }}
containerAppName: prod-onlinestore-website
imageToDeploy: onlinestorecontainerregistry.azurecr.io/onlinestore-website:${{ github.sha }}
location: 'East US'
resourceGroup: onlinestore-shared-rg
targetPort: 80
environmentVariables: "API__BASEPATH=https://api.rockpal.co.uk"