-
Notifications
You must be signed in to change notification settings - Fork 6
241 lines (236 loc) · 7.79 KB
/
cdkactions_build-and-deploy.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# Generated by cdkactions. Do not modify
# Generated as part of the 'application' stack.
name: Build and Deploy
on: push
jobs:
django-check:
name: Django Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache
uses: actions/cache@v2
with:
path: ~/.local/share/virtualenvs
key: v0-${{ hashFiles('backend/Pipfile.lock') }}
- name: Install Dependencies
run: |-
cd backend
pip install pipenv
pipenv install --deploy --dev
- name: Lint (flake8)
run: |-
cd backend
pipenv run flake8 .
- name: Lint (black)
run: |-
cd backend
pipenv run black --check .
- name: Test (run in parallel)
run: |-
cd backend
pipenv run coverage run --concurrency=multiprocessing manage.py test --settings=pennclubs.settings.ci --parallel
pipenv run coverage combine
- name: Upload Code Coverage
run: |-
ROOT=$(pwd)
cd backend
pipenv run codecov --root $ROOT --flags backend
container:
image: python:3.8-buster
env:
DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres
services:
postgres:
image: postgres:12
env:
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
options: "--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5"
build-backend:
name: Build backend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: buildx-build-backend
- name: Build/Publish
uses: docker/build-push-action@v2
with:
context: backend
file: backend/Dockerfile
push: false
cache-from: type=local,src=/tmp/.buildx-cache,type=registry,ref=pennlabs/penn-clubs-backend:latest
cache-to: type=local,dest=/tmp/.buildx-cache
tags: pennlabs/penn-clubs-backend:latest,pennlabs/penn-clubs-backend:${{ github.sha }}
outputs: type=docker,dest=/tmp/image.tar
- uses: actions/upload-artifact@v2
with:
name: build-backend
path: /tmp/image.tar
needs: django-check
react-check:
name: React Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache
uses: actions/cache@v2
with:
path: "**/node_modules"
key: v0-${{ hashFiles('frontend/yarn.lock') }}
- name: Install Dependencies
run: |-
cd frontend
yarn install --frozen-lockfile
- name: Lint
run: |-
cd frontend
yarn lint
- name: Test
run: |-
cd frontend
yarn test
- name: Upload Code Coverage
run: |-
ROOT=$(pwd)
cd frontend
yarn run codecov -p $ROOT -F frontend
container:
image: node:14
build-frontend:
name: Build frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: buildx-build-frontend
- name: Build/Publish
uses: docker/build-push-action@v2
with:
context: frontend
file: frontend/Dockerfile
push: false
cache-from: type=local,src=/tmp/.buildx-cache,type=registry,ref=pennlabs/penn-clubs-frontend:latest
cache-to: type=local,dest=/tmp/.buildx-cache
tags: pennlabs/penn-clubs-frontend:latest,pennlabs/penn-clubs-frontend:${{ github.sha }}
outputs: type=docker,dest=/tmp/image.tar
- uses: actions/upload-artifact@v2
with:
name: build-frontend
path: /tmp/image.tar
needs: react-check
integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
- name: Load docker images
run: |-
docker load --input build-backend/image.tar
docker load --input build-frontend/image.tar
- name: Run docker compose
run: |-
mkdir -p /tmp/test-results
docker-compose -f docker-compose.test.yaml up -d
- name: Wait for backend
run: |-
for try in {1..20}; do
docker-compose -f docker-compose.test.yaml exec -T backend python manage.py migrate --check && break
sleep 5
done
- name: Populate backend
run: docker-compose -f docker-compose.test.yaml exec -T backend python manage.py populate
- name: Run integration tests
run: docker-compose -f docker-compose.test.yaml exec -T frontend yarn integration
- name: Delete artifacts when no longer needed
if: failure() || github.ref != 'refs/heads/master'
uses: geekyeggo/delete-artifact@v1
with:
name: |-
build-backend
build-frontend
- name: Print logs on failure
if: failure()
run: docker-compose -f docker-compose.test.yaml logs
- name: Upload artifacts on failure
if: failure()
uses: actions/upload-artifact@v2
with:
name: cypress-output
path: /tmp/test-results
env:
GIT_SHA: ${{ github.sha }}
needs:
- build-backend
- build-frontend
post-integration-publish:
name: Publish Images
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
- uses: geekyeggo/delete-artifact@v1
with:
name: |-
build-backend
build-frontend
- name: Load docker images
run: |-
docker load --input build-backend/image.tar
docker load --input build-frontend/image.tar
- uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push docker images
run: |-
docker push -a pennlabs/penn-clubs-backend
docker push -a pennlabs/penn-clubs-frontend
needs: integration-tests
deploy:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2
- id: synth
name: Synth cdk8s manifests
run: |-
cd k8s
yarn install --frozen-lockfile
# get repo name (by removing owner/organization)
export RELEASE_NAME=${REPOSITORY#*/}
# Export RELEASE_NAME as an output
echo "::set-output name=RELEASE_NAME::$RELEASE_NAME"
yarn build
env:
GIT_SHA: ${{ github.sha }}
REPOSITORY: ${{ github.repository }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
- name: Deploy
run: |-
aws eks --region us-east-1 update-kubeconfig --name production --role-arn arn:aws:iam::${AWS_ACCOUNT_ID}:role/kubectl
# get repo name from synth step
RELEASE_NAME=${{ steps.synth.outputs.RELEASE_NAME }}
# Deploy
kubectl apply -f k8s/dist/ -l app.kubernetes.io/component=certificate
kubectl apply -f k8s/dist/ --prune -l app.kubernetes.io/part-of=$RELEASE_NAME
env:
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_ACCESS_KEY_ID: ${{ secrets.GH_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.GH_AWS_SECRET_ACCESS_KEY }}
needs:
- post-integration-publish