-
Notifications
You must be signed in to change notification settings - Fork 0
210 lines (183 loc) · 7.66 KB
/
deploy-terraform.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
name: Deploy
on:
push:
branches: [terraform]
paths-ignore:
- LICENSE
- README.md
concurrency: ${{ github.ref }}
env:
tf_version: "1.4.5" # must match value in terraform-iac/*/app/main.tf
node_version: "16.x" # must match value in log-analyzer/sorter-lambda/package.json
jobs:
env:
name: Set Env Vars
runs-on: ubuntu-latest
steps:
- name: Set up DEV Environment Variables
if: github.ref == 'refs/heads/terraform'
run: |
matrix='{
"env":[
{
"aws_account":"863362256468",
"aws_gha_role":"web-cdn-dev-gha",
"rfc_key_name":"standard_change_sandbox_client_key",
"rfc_secret_name":"standard_change_sandbox_client_secret",
"rfc_template_id":"Codepipeline-Standard-Change",
"cdn_name": "web-community-cdn",
"account_stack_name": "web-community-cdn-account",
"config_repo": "byu-oit/web-cdn",
"extra_tags": "data-sensitivity=public repo=https://github.com/byu-oit/web-cdn",
"env" : "dev",
"root_dns" : "cdn-dev.byu.edu",
"config_branch": "terraform",
"certificate_arn" : "arn:aws:acm:us-east-1:632558792265:certificate/1bc2f81c-2f79-46b3-9d3b-54ce672ba8be",
"assembler_ecr_repo_name" : "cdn-terraform-assembler",
"tf_working_dir":"./iac/dev/app"
}
]
}'
echo matrix=`echo $matrix | jq -c .` >> $GITHUB_ENV
# TODO: Update for prd
- name: Set up PRD Environment Variables
if: github.ref == 'refs/heads/master'
run: |
matrix='{
"env":[
{
"aws_account":"204581410681",
"aws_gha_role":"web-cdn-prd-gha",
"rfc_key_name":"standard_change_production_client_key",
"rfc_secret_name":"standard_change_production_client_secret",
"rfc_template_id":"Codepipeline-Standard-Change",
"cdn_name": "web-community-cdn",
"account_stack_name": "web-community-cdn-account",
"config_repo": "byu-oit/web-cdn",
"extra_tags": "data-sensitivity=public repo=https://github.com/byu-oit/web-cdn",
"env" : "prd",
"root_dns" : "cdn.byu.edu",
"config_branch": "master",
"certificate_arn" : "arn:aws:acm:us-east-1:204581410681:certificate/18c1b547-de51-43d3-afa5-2bd05493c41c"
"assembler_ecr_repo_name": "web-cdn-prd-assembler",
"tf_working_dir":"./iac/prd/app"
}
]
}'
echo matrix=`echo $matrix | jq -c .` >> $GITHUB_ENV
outputs:
matrix: ${{ env.matrix }}
build_and_deploy:
name: Build CDN pipeline
runs-on: ubuntu-latest
needs: env
strategy:
matrix: ${{ fromJson(needs.env.outputs.matrix) }}
permissions: write-all
steps:
- name: Check out
uses: actions/checkout@v3
- name: Disallow Concurrent Runs
uses: byu-oit/github-action-disallow-concurrent-runs@v2
with:
token: ${{ github.token }}
- name: Configure AWS Credentials
id: awscreds
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: "arn:aws:iam::${{ matrix.env.aws_account }}:role/${{ matrix.env.aws_gha_role }}"
role-session-name: ${{ github.sha }}
aws-region: us-east-1
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ env.node_version }}
- name: Setup
run: .codebuild/setup.sh
- name: Install AWSCLI
run: pip install awscli --upgrade --user
- name: Lerna Boostrap
run: lerna bootstrap
- name: Echo ROOT_DNS
env:
root_dns: ${{ matrix.env.root_dns }}
run: echo $root_dns
# - name: Lerna Exec
# env:
# ENV: ${{ matrix.env.env }}
# AWS_ACCOUNT_ID: ${{ steps.awscreds.outputs.aws-account-id }}
# ROOT_DNS: ${{ matrix.env.root_dns }}
# run: lerna exec -- ./codebuild.sh
- name: find
run: find ./* -mtime +10950 -exec touch {} \;
- name: Log into Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Get Current Timestamp
id: date
run: echo "timestamp=$(date +'%Y-%m-%d_%H-%M-%S')" >> $GITHUB_OUTPUT
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push the Assembler Docker image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPO: ${{ matrix.env.assembler_ecr_repo_name }}
IMAGE_TAG: ${{ steps.date.outputs.timestamp }}
uses: docker/build-push-action@v3
with:
context: assembler
push: true
tags: ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPO}}:${{ env.IMAGE_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Terraform Setup
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ env.tf_version }}
terraform_wrapper: false
- name: Terraform Init
working-directory: ${{ matrix.env.tf_working_dir }}
run: terraform init
- name: Terraform Format
working-directory: "./"
run: terraform fmt -check -recursive
- name: Terraform Plan
working-directory: ${{ matrix.env.tf_working_dir }}
run: terraform plan -var 'image_tag=${{ steps.date.outputs.timestamp }}' -input=false -out=plan
- name: Analyze Terraform Plan
uses: byu-oit/github-action-tf-plan-analyzer@v2
with:
working-directory: ${{ matrix.env.tf_working_dir }}
terraform-plan-file: plan
divvycloud-username: ${{ secrets.DIVVYCLOUD_USERNAME }}
divvycloud-password: ${{ secrets.DIVVYCLOUD_PASSWORD }}
- name: Start Standard Change
uses: byu-oit/github-action-start-standard-change@v1
id: start-standard-change
with:
client-key: ${{ secrets[matrix.env.rfc_key_name] }}
client-secret: ${{ secrets[matrix.env.rfc_secret_name] }}
template-id: ${{ matrix.env.rfc_template_id }}
- name: Terraform Apply
working-directory: ${{ matrix.env.tf_working_dir }}
run: terraform apply plan
# - name: deploy
# env:
# cdn_name: ${{ matrix.env.cdn_name }}
# env: ${{ matrix.env.env }}
# root_dns: ${{ matrix.env.root_dns }}
# account_stack_name: ${{ matrix.env.account_stack_name }}
# certificate_arn: ${{ matrix.env.certificate_arn }}
# config_repo: ${{ matrix.env.config_repo }}
# config_branch: ${{ matrix.env.config_branch }}
# extra_tags: ${{ matrix.env.extra_tags }}
# run: .aws-infrastructure/deploy-environment.sh $cdn_name $env $root_dns $account_stack_name $certificate_arn $config_repo $config_branch "$extra_tags"
- name: End Standard Change
uses: byu-oit/github-action-end-standard-change@v1
if: always() && steps.start-standard-change.outcome == 'success' # Run if RFC started, even if the deploy failed
with:
client-key: ${{ secrets[matrix.env.rfc_key_name] }}
client-secret: ${{ secrets[matrix.env.rfc_secret_name] }}
change-sys-id: ${{ steps.start-standard-change.outputs.change-sys-id }}
work-start: ${{ steps.start-standard-change.outputs.work-start }}
success: ${{ job.status == 'success' }}