Repository navigation
240 lines (214 loc) · 8.7 KB
/
Copy pathdeploy-control-plane.yml
File metadata and controls
240 lines (214 loc) · 8.7 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
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
# SPDX-License-Identifier: MIT
name: Build and Deploy Control Plane
on:
push:
branches:
- main
paths:
- '.github/workflows/deploy-control-plane.yml'
- 'control-plane/**'
pull_request:
branches:
- main
paths:
- '.github/workflows/deploy-control-plane.yml'
- 'control-plane/**'
workflow_dispatch:
permissions:
contents: write
packages: write
env:
PROD_URL: https://riseriscvrunnerappqdvknz9s-ghfe.functions.fnc.fr-par.scw.cloud
STAGING_URL: https://riseriscvrunnerappst73ndwr0w-ghfe.functions.fnc.fr-par.scw.cloud
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: control-plane
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
sparse-checkout: control-plane
- name: Setup Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: control-plane/go.mod
cache-dependency-path: control-plane/go.sum
- name: go vet
run: go vet ./...
- name: gofmt check
run: |
out=$(gofmt -l .)
if [ -n "$out" ]; then
echo "::error::gofmt diff:"
echo "$out"
exit 1
fi
- name: go test
run: go test -race ./... -coverprofile=coverage.out
build:
needs: [test]
runs-on: ubuntu-latest
defaults:
run:
working-directory: control-plane
env:
# Dependabot runs read the (empty) Dependabot secret store, so SCW_SECRET_KEY
# is unavailable and a registry login would fail. Build without publishing.
PUSH_IMAGES: ${{ github.repository_owner == 'riseproject-dev' && github.actor != 'dependabot[bot]' }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
sparse-checkout: control-plane
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Login to Container Registry
if: env.PUSH_IMAGES == 'true'
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
- name: Build ghfe image
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
platforms: linux/amd64
context: control-plane
file: control-plane/Dockerfile
target: ghfe
tags: ghcr.io/${{ github.repository }}/ghfe:sha-${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=gha,scope=docker
cache-to: |
${{ github.ref_name == github.event.repository.default_branch && 'type=gha,scope=docker' || '' }}
push: ${{ env.PUSH_IMAGES == 'true' }}
- name: Build scheduler image
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
platforms: linux/amd64
context: control-plane
file: control-plane/Dockerfile
target: scheduler
tags: ghcr.io/${{ github.repository }}/scheduler:sha-${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=gha,scope=docker
cache-to: |
${{ github.ref_name == github.event.repository.default_branch && 'type=gha,scope=docker' || '' }}
push: ${{ env.PUSH_IMAGES == 'true' }}
deploy-staging:
if: github.repository_owner == 'riseproject-dev' && github.ref_name == github.event.repository.default_branch
name: "deploy to staging"
needs: [build]
runs-on: ubuntu-latest
environment: staging
concurrency:
group: ${{ github.workflow_ref }}-deploy-staging
cancel-in-progress: false
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
sparse-checkout: |
control-plane
bin/check-health.py
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Login to Container Registry
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Tag ghfe image for staging
run: >-
docker buildx imagetools create \
-t ghcr.io/${{ github.repository }}/ghfe:staging \
ghcr.io/${{ github.repository }}/ghfe:sha-${{ github.sha }}
- name: Tag scheduler image for staging
run: >-
docker buildx imagetools create \
-t ghcr.io/${{ github.repository }}/scheduler:staging \
ghcr.io/${{ github.repository }}/scheduler:sha-${{ github.sha }}
- name: Deploy to Scaleway
working-directory: control-plane
run: npm ci && npx serverless deploy --stage=staging
env:
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
GHAPP_WEBHOOK_SECRET: ${{ secrets.GHAPP_WEBHOOK_SECRET }}
GHAPP_ORG_PRIVATE_KEY: ${{ secrets.GHAPP_ORG_PRIVATE_KEY }}
GHAPP_PERSONAL_PRIVATE_KEY: ${{ secrets.GHAPP_PERSONAL_PRIVATE_KEY }}
K8S_KUBECONFIG: ${{ secrets.K8S_KUBECONFIG_GH_APP }}
POSTGRES_URL: ${{ secrets.POSTGRES_URL }}
TRACE_API_SECRET: ${{ secrets.TRACE_API_SECRET }}
- name: Health check
working-directory: control-plane
run: python3 ./bin/check-health.py
- name: Trigger sample workflow
env:
GH_TOKEN: ${{ secrets.RISCV_RUNNER_SAMPLE_STAGING_ACCESS_TOKEN }}
GH_REPO: riseproject-staging/riscv-runner-sample
GH_WORKFLOW: hello.yml
run: |
gh workflow run ${GH_WORKFLOW} --repo ${GH_REPO}
sleep 5
gh run watch $(gh run list --repo ${GH_REPO} --workflow ${GH_WORKFLOW} --limit 1 --json databaseId --jq '.[0].databaseId') --repo ${GH_REPO} --interval 15 --exit-status
deploy-prod:
if: github.repository_owner == 'riseproject-dev' && github.ref_name == github.event.repository.default_branch
name: "deploy to prod"
needs: [build]
runs-on: ubuntu-latest
environment: prod
concurrency:
group: ${{ github.workflow_ref }}-deploy-prod
cancel-in-progress: false
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
sparse-checkout: control-plane
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Login to Container Registry
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Tag ghfe image for prod
run: >-
docker buildx imagetools create \
-t ghcr.io/${{ github.repository }}/ghfe:prod \
ghcr.io/${{ github.repository }}/ghfe:sha-${{ github.sha }}
- name: Tag scheduler image for prod
run: >-
docker buildx imagetools create \
-t ghcr.io/${{ github.repository }}/scheduler:prod \
ghcr.io/${{ github.repository }}/scheduler:sha-${{ github.sha }}
- name: Deploy to Scaleway
working-directory: control-plane
run: npm ci && npx serverless@3 deploy --stage=main
env:
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
GHAPP_WEBHOOK_SECRET: ${{ secrets.GHAPP_WEBHOOK_SECRET }}
GHAPP_ORG_PRIVATE_KEY: ${{ secrets.GHAPP_ORG_PRIVATE_KEY }}
GHAPP_PERSONAL_PRIVATE_KEY: ${{ secrets.GHAPP_PERSONAL_PRIVATE_KEY }}
K8S_KUBECONFIG: ${{ secrets.K8S_KUBECONFIG_GH_APP }}
POSTGRES_URL: ${{ secrets.POSTGRES_URL }}
TRACE_API_SECRET: ${{ secrets.TRACE_API_SECRET }}
- name: Health check
working-directory: control-plane
run: python3 ./bin/check-health.py
- name: Trigger sample workflow
env:
GH_TOKEN: ${{ secrets.RISCV_RUNNER_SAMPLE_ACCESS_TOKEN }}
GH_REPO: riseproject-dev/riscv-runner-sample
GH_WORKFLOW: hello.yml
run: |
gh workflow run ${GH_WORKFLOW} --repo ${GH_REPO}
sleep 5
gh run watch $(gh run list --repo ${GH_REPO} --workflow ${GH_WORKFLOW} --limit 1 --json databaseId --jq '.[0].databaseId') --repo ${GH_REPO} --interval 15 --exit-status