-
Notifications
You must be signed in to change notification settings - Fork 3
195 lines (175 loc) · 6.03 KB
/
ci-cd.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: CI/CD
on:
workflow_dispatch:
push:
branches:
- main
tags:
- 'v*'
pull_request:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
branches:
- main
types:
- opened # default
- reopened # default
- synchronize # default
- ready_for_review
release:
types:
- released
env:
REGISTRY: ghcr.io/${{ github.repository_owner }}
jobs:
test:
name: Test
runs-on: ubuntu-latest
env:
PORT: 3000
URL: http://localhost
DB_CONNECTION_STRING: mongodb://localhost:4000
DB_NAME: test_registry
SMTP_HOST: placeholder
SMTP_PORT: 0000
SMTP_USER: placeholder
SMTP_PASSWORD: placeholder
AUTH_JWT_SECRET_KEY: abcdefgh123456
AUTH_ADMIN_PASSWORD_HASH: $2b$10$9ScWBY1SuA0a2nZbjvAOWeshe1XqchHKeI18NgWSs.TS4zbZsds3C
FRONTEND_URL: http://localhost:3001
concurrency:
group: ${{ github.workflow }}-test-${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
- name: Start MongoDB (with replica set)
uses: supercharge/[email protected]
with:
mongodb-version: 7.0
mongodb-replica-set: rs0
mongodb-port: 4000
- run: yarn global add node-gyp
- run: yarn install --frozen-lockfile
- run: yarn build
- run: yarn test
build:
name: Docker build and push
needs: test
permissions:
packages: write
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-build-${{ github.ref }}
cancel-in-progress: true
outputs:
version: ${{ steps.meta.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}
- uses: docker/metadata-action@v5
id: meta
with:
images: ${{ env.REGISTRY }}/ssi-trust-registry
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=sha,prefix=pr-${{ github.event.pull_request.number }}-,priority=601,enable=${{ github.event_name == 'pull_request' }}
type=sha,prefix={{branch}}-,priority=601,enable=${{ github.event_name != 'pull_request' && github.ref_type == 'branch' }}
type=ref,event=branch,priority=600
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64 # linux/arm64/v8 is too slow to build (right now)
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=gha
type=registry,ref=${{ env.REGISTRY }}/ssi-trust-registry:latest
cache-to: type=gha,mode=max
compose:
name: Compose Test
needs: build
permissions:
packages: read
runs-on: ubuntu-latest
env:
IMAGE_TAG: ${{ needs.build.outputs.version }}
concurrency:
group: ${{ github.workflow }}-compose-${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
- run: docker compose pull
- run: docker compose up -d
# Run a few tests
- run: curl --silent --show-error --fail http://localhost:3000/health
- run: curl --silent --show-error --fail http://localhost:3000/api/registry
- name: MongoDB logs
if: always()
run: docker logs mongo
- name: Trust Registry logs
if: always()
run: docker logs trust-registry
deploy:
name: Deploy to EKS
needs: [compose, build]
permissions:
id-token: write
contents: read
checks: read
runs-on: ubuntu-latest
env:
TAILSCALE_VERSION: 1.58.2
HELMFILE_VERSION: v0.161.0
HELM_VERSION: v3.14.0
concurrency:
group: ${{ github.workflow }}-deploy-${{ github.event_name == 'release' && 'prod' || 'dev' }}
cancel-in-progress: false
environment:
name: ${{ github.event_name == 'release' && 'prod' || 'dev' }}
url: ${{ vars.PUBLIC_URL }}
# Don't deploy if triggering actor is dependabot
# Only deploy if PR is Ready for Review
if: github.actor != 'dependabot[bot]' && github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v4
- uses: unfor19/install-aws-cli-action@v1
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
role-session-name: github-cicd
- run: aws eks update-kubeconfig --name ${{ secrets.CLUSTER }}
- uses: tailscale/github-action@main
with:
authkey: ${{ secrets.TAILSCALE_AUTHKEY }}
version: ${{ env.TAILSCALE_VERSION }}
- name: Helmfile Apply/Diff
uses: helmfile/[email protected]
with:
helmfile-args: |
${{ github.event_name != 'pull_request' && 'apply' || 'diff' }} \
--environment ${{ vars.ENVIRONMENT }} \
-f ./helm/trust-registry.yaml \
--set image.tag=${{ needs.build.outputs.version }} \
--set config.authJwtSecretKey=${{ secrets.AUTH_JWT_SECRET_KEY }} \
--set config.authAdminPasswordHash=${{ secrets.AUTH_ADMIN_PASSWORD_HASH }}
helmfile-version: ${{ env.HELMFILE_VERSION }}
helm-version: ${{ env.HELM_VERSION }}
- name: Test Health
if: github.event_name != 'pull_request'
run: curl --silent --show-error --fail ${{ vars.PUBLIC_URL }}/health
- name: Test Registry
if: github.event_name != 'pull_request'
run: curl --silent --show-error --fail ${{ vars.PUBLIC_URL }}/api/registry