-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (126 loc) · 4.86 KB
/
ci-cd.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
name: Workflow
on: [push]
env:
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: us-east-2
jobs:
ci:
name: CI
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20.x"
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 8
run_install: |
- recursive: true
- name: Format
run: pnpm run format:check
- name: Write frontend environment variables
run: printf "VITE_API_BASE_URL=%s\n" "${{ vars.VITE_API_BASE_URL }}" >> .env
working-directory: ./apps/frontend
- name: Write backend environment variables
run: |
printf "EXTERNAL_API_BASE_URL=%s\n" "${{ vars.API_FUNCTION_EXTERNAL_API_BASE_URL }}" >> .env
printf "RESTAURANT_SCRAPE_BASE_URL=%s\n" "${{ vars.API_FUNCTION_RESTAURANT_SCRAPE_BASE_URL }}" >> .env
printf "FLAVORS_SCRAPE_BASE_URL=%s\n" "${{ vars.API_FUNCTION_FLAVORS_SCRAPE_BASE_URL }}" >> .env
printf "FLAVOR_IMAGE_BASE_URL=%s\n" "${{ vars.API_FUNCTION_FLAVOR_IMAGE_BASE_URL }}" >> .env
printf "LOGO_SVG_URL=%s\n" "${{ vars.API_FUNCTION_LOGO_SVG_URL }}" >> .env
printf "CORS_ORIGIN=%s\n" "${{ vars.API_FUNCTION_CORS_ORIGIN }}" >> .env
working-directory: ./apps/backend
- name: Build
run: pnpm run build
- name: Lint
run: pnpm run lint
- name: Test
run: pnpm run test
cd:
name: CD
runs-on: ubuntu-22.04
needs: [ci]
env:
TF_VAR_root_domain_name: ${{ vars.ROOT_DOMAIN_NAME }}
TF_VAR_cloudflare_api_token: ${{ secrets.TERRAFORM_CLOUDFLARE_API_TOKEN }}
TF_VAR_cloudflare_zone_id: ${{ secrets.TERRAFORM_CLOUDFLARE_ZONE_ID }}
TF_VAR_api_function_external_api_base_url: ${{ vars.API_FUNCTION_EXTERNAL_API_BASE_URL }}
TF_VAR_api_function_restaurant_scrape_base_url: ${{ vars.API_FUNCTION_RESTAURANT_SCRAPE_BASE_URL }}
TF_VAR_api_function_flavors_scrape_base_url: ${{ vars.API_FUNCTION_FLAVORS_SCRAPE_BASE_URL }}
TF_VAR_api_function_flavor_image_base_url: ${{ vars.API_FUNCTION_FLAVOR_IMAGE_BASE_URL }}
TF_VAR_api_function_logo_svg_url: ${{ vars.API_FUNCTION_LOGO_SVG_URL }}
TF_VAR_api_function_cors_origin: ${{ vars.API_FUNCTION_CORS_ORIGIN }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20.x"
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 8
run_install: |
- recursive: true
- name: Write frontend environment variables
run: printf "VITE_API_BASE_URL=%s\n" "${{ vars.VITE_API_BASE_URL }}" >> .env
working-directory: ./apps/frontend
- name: Build
run: pnpm run build
- name: Download LLRT
run: curl -L -o llrt.zip https://github.com/awslabs/llrt/releases/latest/download/llrt-lambda-arm64.zip
working-directory: ./apps/backend
- name: Unzip LLRT
run: unzip llrt.zip
working-directory: ./apps/backend
- name: Copy bootstrap
run: cp bootstrap ./lambda/
working-directory: ./apps/backend
- name: Zip lambda
run: pnpm run zip
working-directory: ./apps/backend
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: Terraform Init
run: terraform init
working-directory: ./infra
- name: Terraform Validate
run: terraform validate
working-directory: ./infra
- name: Terraform Format
run: terraform fmt -check
working-directory: ./infra
- name: Terraform Plan
run: terraform plan -input=false
working-directory: ./infra
- name: Terraform Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: terraform apply -auto-approve -input=false
working-directory: ./infra
- name: Download AWS CLI
if: ${{ env.ACT }}
run: curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- name: Unzip AWS CLI
if: ${{ env.ACT }}
run: unzip -q awscliv2.zip
- name: Install AWS CLI
if: ${{ env.ACT }}
run: ./aws/install
- name: AWS CLI version
run: aws --version
- name: AWS CLI Configure
run: |
aws configure set aws_access_key_id $(echo $AWS_ACCESS_KEY)
aws configure set aws_secret_access_key $(echo $AWS_SECRET_ACCESS_KEY)
aws configure set region $(echo $AWS_REGION)
- name: Deploy
run: pnpm run deploy
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
env:
AWS_PAGER: ""