Repository navigation
179 lines (155 loc) · 4.96 KB
/
Copy pathci.yml
File metadata and controls
179 lines (155 loc) · 4.96 KB
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
name: CI
on: push
jobs:
build-module:
name: Build & test npm module
runs-on: ubuntu-latest
defaults:
run:
working-directory: module
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
- run: npm install
- run: npm run build
- run: npx playwright install chromium
- run: npm test
build-api:
name: Build & test API
runs-on: ubuntu-latest
defaults:
run:
working-directory: api
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
- run: npm ci
- run: npm test
build-dashboard:
name: Build & test dashboard
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
- name: Dashboard NPM CI
run: npm ci
working-directory: ui
- run: npm run build:ui
env:
ACCOUNTS_API: '/api' # UI always uses the matching-origin API
VERSION: ${{ github.sha }}
NODE_ENV: production
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
- uses: actions/upload-artifact@v4
with:
name: dashboard-dist
path: dist/*
if-no-files-found: error
build-completed:
name: Build completed
runs-on: ubuntu-latest
needs:
- build-module
- build-api
- build-dashboard
steps:
- run: echo 'Build completed'
deploy-api:
name: Deploy API to production
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
environment: production
needs: build-completed
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # Required to publish containers to GHCR
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: |
ghcr.io/httptoolkit/accounts-api
tags: |
type=raw,value=prod,enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
type=sha
- name: Build & publish API image to registry
uses: docker/build-push-action@v5
with:
context: api/
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: VERSION=${{ github.sha }}
- name: Configure Kubectl
run: |
kubectl config set-cluster scw-cluster \
--server="${{ vars.K8S_SERVER_ADDRESS }}" \
--certificate-authority=<(echo "${{ vars.K8S_CA_CERT }}" | base64 -d) \
--embed-certs=true
kubectl config set-credentials deployer --token="${{ secrets.K8S_DEPLOY_TOKEN }}"
kubectl config set-context default --cluster=scw-cluster --user=deployer
kubectl config use-context default
- name: Deploy to Kubernetes
run: |
sed "s|/accounts-api:latest|/accounts-api:sha-${GITHUB_SHA::7}|g" api/deploy/deployment.yaml | \
kubectl apply -f - \
-f api/deploy/service.yaml \
-f api/deploy/routes.yaml
kubectl rollout status deployment/accounts-api -n accounts-api
deploy-dashboard:
name: Deploy Dashboard to production
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
environment: production
needs: build-completed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: dashboard-dist
path: dashboard-dist
- name: Publish to Bunny.net FTP
uses: SamKirkland/FTP-Deploy-Action@v4.3.5
with:
local-dir: ./dashboard-dist/
server-dir: /${{ vars.FTP_USERNAME }}/
protocol: ftps
log-level: verbose
server: ${{ vars.FTP_HOSTNAME }}
username: ${{ vars.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
timeout: 60000
post-deploy:
name: Update CDN after deploy
environment: production
needs:
- deploy-api
- deploy-dashboard
runs-on: ubuntu-latest
steps:
- name: Flush CDN cache
run: |
# Clear CDN cache to re-request content:
curl -f --request POST \
--url https://api.bunny.net/pullzone/$BUNNY_PULL_ZONE_ID/purgeCache \
--header "AccessKey: $BUNNY_SITE_API_KEY"
env:
BUNNY_PULL_ZONE_ID: ${{ vars.BUNNY_PULL_ZONE_ID }}
BUNNY_SITE_API_KEY: ${{ secrets.BUNNY_SITE_API_KEY }}