Skip to content

Commit 24b0abd

Browse files
workflows fix (#185)
* workflows fix * grafana build * suggested changes * fix * working_directory path fix * using orbs * rolled back to docker and new images * build fix * go build fix * go backend run cmd * removed go build in circleci
1 parent 68b353a commit 24b0abd

6 files changed

+48
-764
lines changed

.circleci/config.yml

+37-255
Original file line numberDiff line numberDiff line change
@@ -1,276 +1,58 @@
11
version: 2.1
22

3-
# this allows to use CircleCI's dynamic configuration feature
4-
setup: true
5-
6-
orbs:
7-
gcp-gcr: circleci/[email protected]
8-
93
executors:
10-
base-cimg-executor:
4+
go-executor:
115
docker:
12-
- image: cimg/base:2022.07
13-
python-cimg-executor:
6+
- image: cimg/go:1.22.6
7+
working_directory: ~/github.com/grafana
8+
9+
node-executor:
1410
docker:
15-
- image: cimg/python:3.10.4
11+
- image: cimg/node:22.7.0
12+
working_directory: ~/frontend
1613

17-
commands:
18-
asdf_install:
19-
description: "Install tools using ASDF"
20-
parameters:
21-
tools:
22-
type: string
23-
description:
24-
"Newline separated list of tools to install. If empty, will install
25-
everything."
26-
default: ""
27-
cache_name:
28-
type: string
29-
description: "Name of asdf cache"
30-
default: "default"
14+
jobs:
15+
go-mod-install:
16+
executor: go-executor
3117
steps:
32-
- run:
33-
name: Install ASDF
34-
command: |
35-
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.2
36-
printf '\nsource "${HOME}/.asdf/asdf.sh"\n' >> "${BASH_ENV}"
37-
date +%m > ~/month
38-
date +%d > ~/day
39-
# We need to restore ASDF cache after installing, otherwise we will try to clone it to non-empty dir
18+
- checkout
4019
- restore_cache:
41-
name: Restore ASDF cache
4220
keys:
43-
- grafana-asdf-cache-v7-{{ checksum "~/month" }}-<<
44-
parameters.cache_name >>-{{ checksum ".tool-versions" }}
45-
- grafana-asdf-cache-v7-{{ checksum "~/month" }}-<<
46-
parameters.cache_name >>-
21+
- go-mod-cache-{{ checksum "go.sum" }}
22+
- go-mod-cache-
4723
- run:
48-
name: Install ASDF tools
49-
environment:
50-
TOOLS: << parameters.tools >>
51-
command: .circleci/scripts/asdf_install.sh
52-
asdf_save_cache:
53-
parameters:
54-
cache_name:
55-
type: string
56-
description: "Name of asdf cache"
57-
default: "default"
58-
steps:
24+
name: Install Go dependencies
25+
command: go mod download
26+
- run:
27+
name: Go mod tidy
28+
command: go mod tidy
5929
- save_cache:
60-
name: Save ASDF cache
61-
key:
62-
grafana-asdf-cache-v7-{{ checksum "~/month" }}-<<
63-
parameters.cache_name >>-{{ checksum ".tool-versions" }}
6430
paths:
65-
- ~/.asdf
66-
opsninja_install:
67-
parameters:
68-
branch:
69-
type: string
70-
default: main
71-
description: opsninja branch to install from
72-
fingerprint:
73-
type: string
74-
default: 10:d1:92:4e:2a:55:81:c9:82:c2:74:ce:6d:0e:e8:a8 # fluxninja/cloud R/O
75-
description: What SSH identity to use for accessing opsninja repository
76-
steps:
77-
- add_ssh_keys:
78-
fingerprints:
79-
- << parameters.fingerprint >>
80-
- run:
81-
name: Install opsninja and its dependencies
82-
command: |
83-
# We need R/O access to cloud repository to be able to fetch opsninja library
84-
# FIXME: make "releases" of opsninja library somehow, even as a separate repository
85-
# to limit exposure.
86-
export CLOUD_RO_KEY_FINGERPRINT="<< parameters.fingerprint >>"
87-
export GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_$(echo "${CLOUD_RO_KEY_FINGERPRINT}" | tr -d ':')"
88-
export SSH_AUTH_SOCK=""
89-
# Bust asdf cache as our opsninja version is always 0.0.0
90-
pip uninstall -y opsninja
91-
pip install 'git+ssh://[email protected]/fluxninja/cloud@<< parameters.branch >>#egg=opsninja&subdirectory=ops/apps/opsninja/'
92-
which asdf > /dev/null 2>&1 && asdf reshim
31+
- ~/go/pkg/mod
32+
key: go-mod-cache-{{ checksum "go.sum" }}
9333

94-
jobs:
95-
release-components:
96-
executor: base-cimg-executor
34+
build-frontend:
35+
executor: node-executor
9736
steps:
9837
- checkout
99-
- asdf_install:
100-
cache_name: release
101-
tools: |-
102-
python
103-
gcloud
104-
- opsninja_install
38+
- restore_cache:
39+
keys:
40+
- yarn-cache-{{ checksum "yarn.lock" }}
41+
- yarn-cache-
10542
- run:
106-
name: Schedule release jobs
107-
working_directory: ops/apps/opsninja
108-
command: fn circleci trigger-release --tag << pipeline.git.tag >>
109-
- asdf_save_cache:
110-
cache_name: release
111-
build-push-add-tag:
112-
parameters:
113-
attach-workspace:
114-
type: boolean
115-
description: Boolean for whether or not to attach to an existing workspace
116-
default: false
117-
docker-context:
118-
type: string
119-
description: Path to the directory containing your build context, defaults to .
120-
default: .
121-
dockerfile:
122-
type: string
123-
description: Name of dockerfile to use, defaults to Dockerfile
124-
default: Dockerfile
125-
executor:
126-
type: executor
127-
description: executor to use for this job
128-
default: base-cimg-executor
129-
extra_build_args:
130-
type: string
131-
description: Extra flags to pass to docker build
132-
default: ""
133-
image:
134-
type: string
135-
description: A name for your Docker image
136-
path:
137-
type: string
138-
description: Path to the directory containing your Dockerfile, defaults to .
139-
default: .
140-
remote-docker-version:
141-
type: string
142-
description: Specify the remote docker version
143-
default: 20.10.14
144-
setup-remote-docker:
145-
type: boolean
146-
description: Setup and use CircleCI's remote Docker environment
147-
default: true
148-
tag:
149-
type: string
150-
description: A Docker image tag
151-
default: ${CIRCLE_SHA1:0:8}
152-
target-tag:
153-
type: string
154-
description: Additional image tag applied when job runs on fluxninja_micro_frontends branch
155-
default: latest
156-
use-docker-layer-caching:
157-
type: boolean
158-
description: Setup docker layer caching for optimized build
159-
default: false
160-
workspace-root:
161-
type: string
162-
description: >
163-
Workspace root path that is either an absolute path or a path relative
164-
to the working directory. Defaults to '.' (the working directory)
165-
default: .
166-
executor: <<parameters.executor>>
167-
environment:
168-
DOCKER_BUILDKIT: 1
169-
steps:
170-
- checkout
171-
- when:
172-
condition: <<parameters.setup-remote-docker>>
173-
steps:
174-
- setup_remote_docker:
175-
docker_layer_caching: <<parameters.use-docker-layer-caching>>
176-
version: <<parameters.remote-docker-version>>
177-
- gcp-gcr/gcr-auth
178-
- gcp-gcr/build-image:
179-
attach-workspace: <<parameters.attach-workspace>>
180-
docker-context: <<parameters.docker-context>>
181-
dockerfile: <<parameters.dockerfile>>
182-
extra_build_args: <<parameters.extra_build_args>>
183-
image: <<parameters.image>>
184-
path: <<parameters.path>>
185-
tag: <<parameters.tag>>
186-
workspace-root: <<parameters.workspace-root>>
187-
- gcp-gcr/push-image:
188-
image: <<parameters.image>>
189-
tag: <<parameters.tag>>
190-
- when:
191-
condition:
192-
equal: [coderabbit_micro_frontend, << pipeline.git.branch >>]
193-
steps:
194-
- gcp-gcr/tag-image:
195-
image: <<parameters.image>>
196-
source-tag: <<parameters.tag>>
197-
target-tag: <<parameters.target-tag>>
198-
update-environment:
199-
parameters:
200-
job-root:
201-
type: string
202-
default: "/home/circleci"
203-
description: The root folder of the job where all repositories will be cloned to
204-
manifests-repo:
205-
type: string
206-
default: [email protected]:fluxninja/argo-manifests.git
207-
description: ArgoCD manifests repository to update
208-
manifests-branch:
209-
type: string
210-
default: environments/latest
211-
description: Branch to use when pushing deployment changes
212-
environment-path:
213-
type: string
214-
description: Path to the environment to update
215-
component:
216-
type: string
217-
default: ""
218-
description: Application component to update image and deployment code for
219-
update:
220-
type: string
221-
default: everything
222-
description: Whether to update 'images', 'deployment-code' or 'everything'
223-
executor: python-cimg-executor
224-
steps:
225-
- add_ssh_keys:
226-
fingerprints:
227-
- "f9:49:04:10:b1:77:16:b0:0e:c0:ba:21:0e:9d:fd:40" # argo-manifests R/W
228-
- checkout
229-
- asdf_install:
230-
cache_name: release
231-
tools: |-
232-
python
233-
gcloud
234-
- gcp-gcr/gcr-auth
235-
- opsninja_install
43+
name: Install frontend dependencies
44+
command: yarn install --immutable
45+
- save_cache:
46+
paths:
47+
- ~/.cache/yarn
48+
key: yarn-cache-{{ checksum "yarn.lock" }}
23649
- run:
237-
name: Update application in the deployment
238-
environment:
239-
JOB_ROOT: << parameters.job-root >>
240-
UPDATE: << parameters.update >>
241-
MANIFESTS_BRANCH: << parameters.manifests-branch >>
242-
MANIFESTS_REPO: << parameters.manifests-repo >>
243-
COMPONENT: << parameters.component >>
244-
ENVIRONMENT_PATH: << parameters.environment-path >>
245-
command: .circleci/scripts/update_environment.sh
50+
name: Build frontend
51+
command: yarn run build
24652

24753
workflows:
24854
version: 2
249-
build-alpine:
250-
jobs:
251-
- build-push-add-tag:
252-
name: image-build-grafana-alpine
253-
image: cf-fn/grafana
254-
- update-environment:
255-
name: update-demo-environment
256-
filters:
257-
branches:
258-
only:
259-
- coderabbit_micro_frontend
260-
requires:
261-
- image-build-grafana-alpine
262-
environment-path: environments/latest/
263-
component: grafana
264-
update: images
265-
266-
release-components:
267-
when:
268-
matches: { value: << pipeline.git.tag >>, pattern: "^releases/.+$" }
55+
build-and-test:
26956
jobs:
270-
- release-components:
271-
# both this and workflow's when is needed
272-
filters:
273-
branches:
274-
ignore: /.+/
275-
tags:
276-
only: /releases\/.+/
57+
- go-mod-install
58+
- build-frontend

.github/workflows/deploy-cloud-run-grafana-prod.yaml

+9-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,12 @@ jobs:
4343
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
4444
4545
- name: Deploy to Cloud Run
46-
run: gcloud run deploy grafana-internal --image gcr.io/coderabbitprod/grafana:latest --region us-central1 --allow-unauthenticated --vpc-connector=coderabbitaiprod-prod-cr
46+
run: gcloud run deploy grafana-internal --image gcr.io/coderabbitprod/grafana:latest --region us-central1 --allow-unauthenticated --vpc-connector=coderabbit-prod-connector
47+
48+
- name: Trigger a repository dispatch
49+
run: |
50+
curl -X POST \
51+
-H "Authorization: token ${{ secrets.PAT_TRIGGER_GRAFANA }}" \
52+
-H "Accept: application/vnd.github.everest-preview+json" \
53+
https://api.github.com/repos/coderabbitai/mono/dispatches \
54+
-d '{"event_type": "trigger-grafana-micro-frontend"}'

.github/workflows/deploy-cloud-run-grafana.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ jobs:
4343
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
4444
4545
- name: Deploy to Cloud Run
46-
run: gcloud run deploy grafana --image gcr.io/coderabbit/grafana:latest --region us-central1 --allow-unauthenticated --vpc-connector=coderabbitai-dev-cr
46+
run: gcloud run deploy grafana --image gcr.io/coderabbit/grafana:latest --region us-central1 --allow-unauthenticated --vpc-connector=coderabbitai-dev-cr

0 commit comments

Comments
 (0)