-
Notifications
You must be signed in to change notification settings - Fork 1
218 lines (191 loc) · 10.5 KB
/
fulfill-terraform.yaml
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
211
212
213
214
215
216
217
218
name: Fulfill Terrafrom
on:
workflow_dispatch:
jobs:
fulfill_terraform:
name: Fulfill Terraform
runs-on: ubuntu-latest
if: github.actor == 'tal-rofe'
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TF_VAR_frontend_s3_bucket_name: ${{ secrets.FRONTEND_AWS_S3_BUCKET }}
TF_VAR_docs_s3_bucket_name: ${{ secrets.DOCS_AWS_S3_BUCKET }}
TF_VAR_landing_page_s3_bucket_name: ${{ secrets.LANDING_PAGE_AWS_S3_BUCKET }}
TF_VAR_backend_repository: dashboard-backend
TF_VAR_cli_backend_repository: dashboard-cli-backend
TF_VAR_database_url: mongodb+srv://${{ secrets.MONGODB_USERNAME }}:${{ secrets.MONGODB_PASSWORD }}@dashboard.elge3qb.mongodb.net/dashboard?retryWrites=true&w=majority
TF_VAR_access_token_jwt_key: ${{ secrets.ACCESS_TOKEN_JWT_KEY }}
TF_VAR_refresh_token_jwt_key: ${{ secrets.REFRESH_TOKEN_JWT_KEY }}
TF_VAR_google_oauth_client_id: ${{ secrets.GOOGLE_OAUTH_CLIENT_ID }}
TF_VAR_google_oauth_client_secret: ${{ secrets.GOOGLE_OAUTH_CLIENT_SECRET }}
TF_VAR_google_oauth_redirect_uri: "https://api.exlint.io/user/auth/google-redirect"
TF_VAR_gh_oauth_client_id: ${{ secrets.GH_OAUTH_CLIENT_ID }}
TF_VAR_gh_oauth_client_secret: ${{ secrets.GH_OAUTH_CLIENT_SECRET }}
TF_VAR_gh_oauth_redirect_uri: "https://api.exlint.io/user/auth/github-redirect"
TF_VAR_mixpanel_token: ${{ secrets.MIXPANEL_TOKEN }}
TF_VAR_frontend_url: "https://app.exlint.io"
TF_VAR_cli_token_jwt_key: ${{ secrets.CLI_TOKEN_JWT_KEY }}
steps:
- name: Setup Node environment
uses: Exlint/[email protected]
with:
should-cache: false
node-version: 20.18.1
package-manager: pnpm
package-manager-version: 8.14.1
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Terraform setup
uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false
- name: Terraform core init
working-directory: terraform/core
env:
TERRAFORM_BACKEND_S3_BUCKET: ${{ secrets.TERRAFORM_BACKEND_S3_BUCKET }}
TERRAFORM_BACKEND_DYNAMODB_TABLE: ${{ secrets.TERRAFORM_BACKEND_DYNAMODB_TABLE }}
run: |
terraform init \
-backend-config="bucket=$TERRAFORM_BACKEND_S3_BUCKET" \
-backend-config="dynamodb_table=$TERRAFORM_BACKEND_DYNAMODB_TABLE" \
-backend-config="region=$AWS_REGION"
- name: Terraform core plan
working-directory: terraform/core
run: terraform plan -no-color -out state.tfplan
- name: Terraform core apply
working-directory: terraform/k8s
run: terraform apply state.tfplan
- name: Get Terraform core outputs
id: terraform-outputs
working-directory: terraform/core
run: |
frontend_cloudfront_distribution_id=$(terraform output -raw frontend_cloudfront_distribution_id)
docs_cloudfront_distribution_id=$(terraform output -raw docs_cloudfront_distribution_id)
landing_page_cloudfront_distribution_id=$(terraform output -raw landing_page_cloudfront_distribution_id)
eks_kubeconfig=$(terraform output -raw eks_kubeconfig | base64)
echo "FRONTEND_CLOUDFRONT_DISTRIBUTION_ID=$frontend_cloudfront_distribution_id" >> $GITHUB_OUTPUT
echo "DOCS_CLOUDFRONT_DISTRIBUTION_ID=$docs_cloudfront_distribution_id" >> $GITHUB_OUTPUT
echo "LANDING_PAGE_CLOUDFRONT_DISTRIBUTION_ID=$landing_page_cloudfront_distribution_id" >> $GITHUB_OUTPUT
echo "KUBE_CONFIG_B64<<EOF" >> $GITHUB_OUTPUT
echo "$eks_kubeconfig" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Set frontend Cloudfront distribution ID secret
uses: hmanzur/[email protected]
with:
name: FRONTEND_AWS_CLOUDFRONT_DISTRIBUTION_ID
value: ${{ steps.terraform-outputs.outputs.FRONTEND_CLOUDFRONT_DISTRIBUTION_ID }}
repository: Exlint/dashboard
token: ${{ secrets.SET_SECRETS_GH_TOKEN }}
- name: Set docs Cloudfront distribution ID secret
uses: hmanzur/[email protected]
with:
name: DOCS_AWS_CLOUDFRONT_DISTRIBUTION_ID
value: ${{ steps.terraform-outputs.outputs.DOCS_CLOUDFRONT_DISTRIBUTION_ID }}
repository: Exlint/dashboard
token: ${{ secrets.SET_SECRETS_GH_TOKEN }}
- name: Set landing-page Cloudfront distribution ID secret
uses: hmanzur/[email protected]
with:
name: LANDING_PAGE_AWS_CLOUDFRONT_DISTRIBUTION_ID
value: ${{ steps.terraform-outputs.outputs.LANDING_PAGE_CLOUDFRONT_DISTRIBUTION_ID }}
repository: Exlint/dashboard
token: ${{ secrets.SET_SECRETS_GH_TOKEN }}
- name: Set k8s kube config secret
uses: hmanzur/[email protected]
with:
name: KUBE_CONFIG_DATA
value: ${{ steps.terraform-outputs.outputs.KUBE_CONFIG_B64 }}
repository: Exlint/dashboard
token: ${{ secrets.SET_SECRETS_GH_TOKEN }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Get package.json version
id: package-version
uses: martinbeentjes/npm-get-version-action@main
- name: Build, tag, and push image of backend to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ steps.package-version.outputs.current-version }}-${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$TF_VAR_backend_repository:$IMAGE_TAG -f ./docker/Dockerfile.backend-prod .
docker push $ECR_REGISTRY/$TF_VAR_backend_repository:$IMAGE_TAG
- name: Build, tag, and push image of cli-backend to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ steps.package-version.outputs.current-version }}-${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$TF_VAR_cli_backend_repository:$IMAGE_TAG -f ./docker/Dockerfile.cli-backend-prod .
docker push $ECR_REGISTRY/$TF_VAR_cli_backend_repository:$IMAGE_TAG
- name: Terraform k8s init
working-directory: terraform/k8s
env:
TERRAFORM_BACKEND_S3_BUCKET: ${{ secrets.TERRAFORM_BACKEND_S3_BUCKET }}
TERRAFORM_BACKEND_DYNAMODB_TABLE: ${{ secrets.TERRAFORM_BACKEND_DYNAMODB_TABLE }}
run: |
terraform init \
-backend-config="bucket=$TERRAFORM_BACKEND_S3_BUCKET" \
-backend-config="dynamodb_table=$TERRAFORM_BACKEND_DYNAMODB_TABLE" \
-backend-config="region=$AWS_REGION"
- name: Terraform k8s plan
working-directory: terraform/k8s
env:
TF_VAR_api_image_tag: ${{ steps.package-version.outputs.current-version }}-${{ github.sha }}
run: terraform plan -no-color -out state.tfplan
- name: Terraform k8s apply
working-directory: terraform/k8s
run: terraform apply state.tfplan
- name: Build frontend
run: pnpm exec nx build @exlint.io/frontend
- name: Deploy to S3 and invalidate Cloudfront
uses: reggionick/s3-deploy@v4
with:
folder: ./apps/frontend/dist
bucket: ${{ secrets.FRONTEND_AWS_S3_BUCKET }}
bucket-region: ${{ secrets.AWS_REGION }}
dist-id: ${{ steps.terraform-outputs.outputs.FRONTEND_CLOUDFRONT_DISTRIBUTION_ID }}
invalidation: /
delete-removed: true
private: true
filesToInclude: '**/*'
- name: Build docs
run: pnpm exec nx build @exlint.io/docs
- name: Deploy to S3 and invalidate Cloudfront
uses: reggionick/s3-deploy@v4
with:
folder: ./apps/docs/build
bucket: ${{ secrets.DOCS_AWS_S3_BUCKET }}
bucket-region: ${{ secrets.AWS_REGION }}
dist-id: ${{ steps.terraform-outputs.outputs.DOCS_CLOUDFRONT_DISTRIBUTION_ID }}
invalidation: /
delete-removed: true
private: true
filesToInclude: '**/*'
- name: Build landing-page
run: pnpm exec nx build @exlint.io/landing-page
- name: Deploy to S3 and invalidate Cloudfront
uses: reggionick/s3-deploy@v4
with:
folder: ./apps/landing-page/out
bucket: ${{ secrets.LANDING_PAGE_AWS_S3_BUCKET }}
bucket-region: ${{ secrets.AWS_REGION }}
dist-id: ${{ steps.terraform-outputs.outputs.LANDING_PAGE_CLOUDFRONT_DISTRIBUTION_ID }}
invalidation: /
delete-removed: true
private: true
filesToInclude: '**/*'
- name: Slack notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: dashboard-deployment
SLACK_MESSAGE: 'Just fulfilled Terraform'
SLACK_TITLE: 'Deployment'
SLACK_USERNAME: 'Yazif Deployer'
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL_DASHBOARD_DEPLOYMENT }}
MSG_MINIMAL: true