-
Notifications
You must be signed in to change notification settings - Fork 4
172 lines (153 loc) · 6.37 KB
/
web-develop.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
name: Push Web app to GHCR and deploy to EKS
on:
workflow_dispatch:
push:
branches: ["develop"]
paths:
- app/**
- k8s/cc-migrate.yml
- k8s/cc-web-deploy.yml
- k8s/cc-web.yml
- .github/workflows/web-develop.yml
pull_request:
paths:
- app/**
- k8s/cc-migrate.yml
- k8s/cc-web-deploy.yml
- k8s/cc-web.yml
- .github/workflows/web-develop.yml
jobs:
runTests:
runs-on: ubuntu-latest
env:
NODE_ENV: test
NEXTAUTH_SECRET: "diTMz/XLX4edSmmfzwJtmzKjCJGRt81Gf0PdjO3IPs8="
NEXTAUTH_URL: "http://localhost:3000"
CDP_API_KEY: ${{ secrets.CDP_API_KEY_TEST }}
CDP_MODE: "test"
defaults:
run:
working-directory: ./app
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
cache-dependency-path: app/package-lock.json
- name: Install dependencies
run: npm ci
- name: Set up database
run: |
docker run --name github_action_postgresql -d -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust -e POSTGRES_PASSWORD="" postgres
sleep 10
createuser -w -h localhost -p 5432 -U postgres citycatalyst
createdb -w -h localhost -p 5432 -U postgres citycatalyst -O citycatalyst
cp env.example .env
npm run db:migrate
npm run db:seed
- uses: actions/cache@v4
with:
# See here for caching with `yarn` https://github.com/actions/cache/blob/main/examples.md#node---yarn or you can leverage caching with actions/setup-node https://github.com/actions/setup-node
path: |
~/.npm
${{ github.workspace }}/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
- name: Run NextJS build
run: npm run build
# - name: Run Cypress tests
# run: npm run cy:test
- name: Run tests and generate coverage file
run: npm run api:test
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
- name: Upload coverage reports to Codecov
continue-on-error: true
uses: codecov/[email protected]
with:
fail_ci_if_error: false
flags: unittests
name: citycatalyst-backend
token: ${{ secrets.CODECOV_TOKEN }}
slug: Open-Earth-Foundation/CityCatalyst
- name: Shut down database
run: docker stop github_action_postgresql
pushToGHCR:
needs: runTests
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop'
steps:
- uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pushing CC Web to GHCR
env:
VERSION: ${{ github.sha }}
IMAGE: ghcr.io/open-earth-foundation/citycatalyst
run: |
docker build -t $IMAGE:$VERSION app
docker tag $IMAGE:$VERSION $IMAGE:latest
docker push $IMAGE:$VERSION
docker push $IMAGE:latest
deployToEKS:
needs: pushToGHCR
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_EKS_DEV_USER }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_EKS_DEV_USER }}
EKS_DEV_NAME: ${{ secrets.EKS_DEV_NAME }}
steps:
- uses: actions/checkout@v4
- name: Creating kubeconfig file
run: aws eks update-kubeconfig --name ${{secrets.EKS_DEV_NAME}} --region us-east-1
- name: Testing connection to EKS
run: kubectl get pods -n default
- name: Deploying service
run: |
kubectl create -f k8s/cc-migrate.yml -n default
kubectl create -f k8s/cc-seed.yml -n default
kubectl apply -f k8s/cc-web-deploy.yml -n default
kubectl set env deployment/cc-web-deploy \
SMTP_USER=${{secrets.SMTP_USER}} \
SMTP_PASSWORD=${{secrets.SMTP_PASSWORD}} \
NEXTAUTH_SECRET=${{secrets.NEXTAUTH_SECRET}} \
RESET_TOKEN_SECRET=${{secrets.RESET_TOKEN_SECRET}} \
VERIFICATION_TOKEN_SECRET=${{secrets.VERIFICATION_TOKEN_SECRET}} \
OPENAI_API_KEY=${{secrets.OPENAI_API_KEY_DEV}} \
"OPENAI_ASSISTANT_ID=asst_saoKNCVqCX7adTMoLqPxPHvB" \
HUGGINGFACE_API_KEY=${{secrets.HUGGINGFACE_API_KEY}} \
"ADMIN_EMAILS=${{secrets.ADMIN_EMAILS}}" \
"ADMIN_NAMES=${{secrets.ADMIN_NAMES}}" \
"DEFAULT_ADMIN_EMAIL=${{secrets.DEFAULT_ADMIN_EMAIL}}" \
"DEFAULT_ADMIN_PASSWORD=${{secrets.DEFAULT_ADMIN_PASSWORD}}" \
"HOST=https://citycatalyst.openearth.dev" \
"NEXTAUTH_URL=https://citycatalyst.openearth.dev" \
"NEXT_PUBLIC_API_URL=https://citycatalyst.openearth.dev" \
"GLOBAL_API_URL=https://ccglobal.openearth.dev" \
"NEXT_PUBLIC_OPENCLIMATE_API_URL=https://openclimate.openearth.dev" \
"OPENCLIMATE_API_URL=https://openclimate.openearth.dev" \
CDP_API_KEY=${{secrets.CDP_API_KEY_TEST}}
kubectl apply -f k8s/cc-sync-catalogue.yml -n default # cronjob
kubectl create -f k8s/cc-sync-catalogue-manual.yml -n default # on deployment
# TODO this (running cronjob on deploy) doesn't work since it can't randomize names. Needs own randomness source
# once it works cc-sync-catalogue-manual.yml can be removed
# kubectl create job --from=cronjob/cc-sync-catalogue cc-sync-catalogue-manual -n default
kubectl create -f k8s/cc-create-admin.yml -n default
kubectl rollout restart deployment cc-web-deploy -n default