-
Notifications
You must be signed in to change notification settings - Fork 1
155 lines (150 loc) · 6.26 KB
/
instance-deploy-test.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: "Instance - deploy test"
on:
pull_request:
branches: [main]
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-test:
needs: [build-api, build-website]
environment: test
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: Login via Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- 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-test" -backend-config="key=terraform.tfstate.${{ github.head_ref }}"
- 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: ${{ github.head_ref }}
TF_VAR_acr_username: ${{ secrets.ACR_USERNAME }}
TF_VAR_acr_password: ${{ secrets.ACR_TOKEN }}
TF_VAR_website_dns_subdomain: ${{ github.head_ref }}-website
TF_VAR_api_dns_subdomain: ${{ github.head_ref }}-api
TF_VAR_monitoring_dns_subdomain: ${{ github.head_ref }}-monitoring
- name: Terraform Apply
id: apply
run: terraform -chdir=instance apply -auto-approve
env:
TF_VAR_location: "East US"
TF_VAR_environment: ${{ github.head_ref }}
TF_VAR_acr_username: ${{ secrets.ACR_USERNAME }}
TF_VAR_acr_password: ${{ secrets.ACR_TOKEN }}
TF_VAR_website_dns_subdomain: ${{ github.head_ref }}-website
TF_VAR_api_dns_subdomain: ${{ github.head_ref }}-api
TF_VAR_monitoring_dns_subdomain: ${{ github.head_ref }}-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-test:
needs: [deploy-terraform-test]
environment: test
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: ${{ github.head_ref }}-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://${{ github.head_ref }}-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: ${{ github.head_ref }}-onlinestore-website
imageToDeploy: onlinestorecontainerregistry.azurecr.io/onlinestore-website:${{ github.sha }}
location: 'East US'
resourceGroup: onlinestore-shared-rg
targetPort: 80
environmentVariables: "API__BASEPATH=https://${{ github.head_ref }}-api.rockpal.co.uk"
- name: Find Comment
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: "### Test environment information"
- name: Create or update comment
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
### Test environment information
#### 🔗 [Company Website](https://${{ github.head_ref }}-website.rockpal.co.uk/)
#### 🔗 [Company API](https://${{ github.head_ref }}-api.rockpal.co.uk/swagger/)
#### 🔗 [Monitoring Dashboard](https://${{ github.head_ref }}-monitoring.rockpal.co.uk/)
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*