-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathconfig.yml
More file actions
237 lines (218 loc) · 7.44 KB
/
config.yml
File metadata and controls
237 lines (218 loc) · 7.44 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
version: 2.1
executors:
node:
docker:
- image: cimg/node:22.14
environment:
IMAGE_NAME: mozilla/profiler-server
# This executor is used for the python jobs (obviously). We want `pip` so that
# we can install `flake8`. We use the node flavor so that we have `yarn`
# preinstalled, but otherwise the exact version for node isn't important.
python:
docker:
- image: cimg/python:3.13-node
orbs:
shellcheck: circleci/shellcheck@3.0.0
gcp-cli: circleci/gcp-cli@3.3.0
gcp-gcr: circleci/gcp-gcr@0.16.3
commands:
checkout-and-dependencies:
description: 'Checkout and install dependencies, managing a cache'
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}-{{ checksum "yarn.lock" }}
- v1-dependencies-{{ checksum "package.json" }}
- v1-dependencies-
# With --frozen-lockfile, the installation will fail if the lockfile is
# outdated compared to package.json.
- run: yarn install --frozen-lockfile
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}-{{ checksum "yarn.lock" }}
workflows:
version: 2
# This is the main workflow, triggered for every push and PR.
# Only docker-publish is triggered for push on the master and production
# banches only.
main:
jobs:
- tests
- python
- lint
- build
- yarn_lock
- typescript
- license-check
- shellcheck/check:
name: 'Shellcheck'
- docker
- docker-publish:
requires:
- docker
filters:
branches:
only:
- master
- production
- deploy-gar:
requires:
- docker
context:
- gcpv2-workload-identity
# filters:
# branches:
# only:
# - master
# - production
# This is a weekly workflow, just to deploy new versions of the docker images,
# so that updates to the underlying images are used and deployed.
# This is configured to run on Thursdays (4th day in the week, Sunday is 0).
weekly:
triggers:
- schedule:
cron: '0 0 * * 4'
filters:
branches:
only:
- master
- production
jobs:
- docker
- docker-publish:
requires:
- docker
jobs:
lint:
executor: node
steps:
- checkout-and-dependencies
- run: yarn lint-js
- run: yarn prettier-run
tests:
executor: node
steps:
- checkout-and-dependencies
- run: yarn test --runInBand
python:
executor: python
steps:
- checkout
# This job needs flake8 to lint python code, let's install it here only
# It's fairly quick (2s) so we won't try to cache it.
- run: pip install --user flake8
- run: yarn test-python
- run: yarn lint-python
typescript:
executor: node
steps:
- checkout-and-dependencies
- run: yarn ts
yarn_lock:
executor: node
steps:
- checkout-and-dependencies
- run: yarn test-lockfile
build:
executor: node
steps:
- checkout-and-dependencies
- run: |
yarn build:clean
yarn build
license-check:
executor: node
steps:
- checkout-and-dependencies
- run: yarn license-check
docker:
executor: node
steps:
- checkout-and-dependencies
# This sets up a remote environment that's necessary to run docker commands.
- setup_remote_docker
- run:
name: 'Build the Docker image'
command: yarn docker:build --pull --build-arg circle_build_url=$CIRCLE_BUILD_URL
- run:
name: "Start the docker image in a container and check it's running"
command: |
cp .env.example .env
yarn docker:run:detached
# Wait up to 10 seconds that the server is launched.
timeout 10s sh \<<'EOF'
while ! docker exec profiler-server curl -i --silent --show-error --fail http://localhost:8000/__version__ ; do
sleep 1
done
EOF
yarn docker:stop
- run:
name: Archive Docker image
command: docker save -o image.tar profiler-server:dev
# This makes it possible to load this image from subsequent jobs.
- persist_to_workspace:
root: .
paths:
- ./image.tar
docker-publish:
executor: node
steps:
# Let's attach the workspace so that we can reload the saved image later.
- attach_workspace:
at: /tmp/workspace
# This sets up a remote environment that's necessary to run docker commands.
- setup_remote_docker
- run:
name: Load archived Docker image
command: docker load -i /tmp/workspace/image.tar
- run:
name: Publish Docker Image to Docker Hub
command: |
# Use both a version tag depending on the circle's build number
# and a latest tag that's depending on the branch name.
# Please keep the version in sync with the version file generated in
# bin/generate-version-file.js.
IMAGE_VERSION_TAG="0.0.${CIRCLE_BUILD_NUM}"
IMAGE_LATEST_TAG="${CIRCLE_BRANCH}-latest"
docker tag profiler-server:dev $IMAGE_NAME:$IMAGE_LATEST_TAG
docker tag profiler-server:dev $IMAGE_NAME:$IMAGE_VERSION_TAG
# Deploy to docker hub using the environment variables passed from
# CircleCI configuration.
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
docker push $IMAGE_NAME:$IMAGE_LATEST_TAG
docker push $IMAGE_NAME:$IMAGE_VERSION_TAG
deploy-gar:
executor: gcp-gcr/default
parameters:
build_tag:
type: string
default: build
image:
type: string
default: firefoxprofiler
registry-url:
type: string
default: us-docker.pkg.dev
steps:
- checkout
- gcp-cli/setup:
use_oidc: true
- run:
name: Prepare environment variables for OIDC authentication and Deploy to Google Artifact Registry
command: |
echo 'export GOOGLE_PROJECT_ID="moz-fx-profiler-prod"' >> "$BASH_ENV"
echo "export OIDC_WIP_ID=$GCPV2_WORKLOAD_IDENTITY_POOL_ID" >> "$BASH_ENV"
echo "export OIDC_WIP_PROVIDER_ID=$GCPV2_CIRCLECI_WORKLOAD_IDENTITY_PROVIDER" >> "$BASH_ENV"
echo "export GOOGLE_PROJECT_NUMBER=$GCPV2_WORKLOAD_IDENTITY_POOL_PROJECT_NUMBER" >> "$BASH_ENV"
echo "export OIDC_SERVICE_ACCOUNT_EMAIL=$GCP_SERVICE_ACCOUNT_EMAIL" >> "$BASH_ENV"
echo 'export GCP_GAR_REPO="profiler-prod"' >> "$BASH_ENV"
echo "export GAR_IMAGE=\"<<parameters.registry-url>>/${GOOGLE_PROJECT_ID}/${GCP_GAR_REPO}/<<parameters.image>>\"" >> $BASH_ENV
gcloud auth configure-docker us-docker.pkg.dev --quiet
IMAGE_VERSION_TAG="0.0.${CIRCLE_BUILD_NUM}"
IMAGE_LATEST_TAG="${CIRCLE_BRANCH}-latest"
docker tag <<parameters.image>> $GAR_IMAGE:$IMAGE_VERSION_TAG
docker tag <<parameters.image>> $GAR_IMAGE:$IMAGE_LATEST_TAG
docker push $GAR_IMAGE:$IMAGE_VERSION_TAG
docker push $GAR_IMAGE:$IMAGE_LATEST_TAG