Skip to content

Commit d28d495

Browse files
authoredJul 10, 2020
Chore: Enable PR testing in Drone (grafana#26189)
* Add Drone configuration Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Add more steps Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Add more steps Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Build front-end before testing it Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Upgrade grafana/build-container Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Add packaging step Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Trigger on push Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Remove some steps Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Enable steps Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Install Dockerize Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Use node image for test-frontend Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Increase number of test workers Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Make plugin installation depend on frontend tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Make integration tests depend on frontend tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Use grafana/build-container also for front-end tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Upgrade dependencies in order to fix front-end tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Depend on es-check Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Dont' depend on tests before building front-end Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Add more steps Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix packaging Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Simplify Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Try to build images Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix e2e tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Remove steps Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Install netcat Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Include golangci-lint with grafana/build-container Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Build storybook and docs website Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix e2e tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Use build image with root user Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Drop CircleCI dependencies Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix e2e tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix e2e under Drone Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Execute e2e server separately Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Use own plugin for building Docker images Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Use Starlark to configure Drone Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Add enterprise steps to pipeline Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Add more enterprise steps to pipeline Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Maintain Yarn cache Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Build enterprise Docker images Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Build Ubuntu Docker images Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Refactor Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Add Postgres integration test Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Add MySQL integration test Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix integration tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Parameterize integration test DB connections Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Categorize integration tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Use grabpl integration-tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Remove unintended change Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Drone: Disable Ubuntu Docker images for PR pipeline Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Regenerate yarn.lock Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Upgrade grabpl Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Restore Yarn cache before installing in grafana-enterprise Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Use separate pipelines for OSS and enterprise Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Let OSS builds depend on tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Restore Go cache before building back-end Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Reduce number of variants built for PRs Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix building of Docker images Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Drone: Simplify logic Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Drone: Use Starlark Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Drone: Fix syntax error Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Convert .drone.star to YAML Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Upgrade AWS Go SDK Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Drone: Fix Go linting Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Undo irrelevant changes Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Revert "Undo irrelevant changes" This reverts commit 5152f65. * Undo irrelevant changes Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * e2e: Support Circle Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Remove unused script Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * TypeScript fixes Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * TypeScript fixes Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Remove unused script Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * More Drone support Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Remove unused script Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix build on Circle Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Remove TODO comment Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
1 parent 1391575 commit d28d495

25 files changed

+1009
-206
lines changed
 

‎.drone.star

+488
Large diffs are not rendered by default.

‎.drone.yml

+351
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,351 @@
1+
---
2+
kind: pipeline
3+
type: docker
4+
name: test-pr-oss
5+
6+
platform:
7+
os: linux
8+
arch: amd64
9+
10+
steps:
11+
- name: install-deps
12+
image: grafana/build-container:1.2.21
13+
commands:
14+
- curl -fLO https://grafana-downloads.storage.googleapis.com/grafana-build-pipeline/v$${GRABPL_VERSION}/grabpl
15+
- chmod +x grabpl
16+
- mkdir -p bin
17+
- mv grabpl bin
18+
- curl -fLO https://github.com/jwilder/dockerize/releases/download/v$${DOCKERIZE_VERSION}/dockerize-linux-amd64-v$${DOCKERIZE_VERSION}.tar.gz
19+
- tar -C bin -xzvf dockerize-linux-amd64-v$${DOCKERIZE_VERSION}.tar.gz
20+
- rm dockerize-linux-amd64-v$${DOCKERIZE_VERSION}.tar.gz
21+
- yarn install --frozen-lockfile --no-progress
22+
- cp -r $(yarn cache dir) yarn-cache
23+
environment:
24+
DOCKERIZE_VERSION: 0.6.1
25+
GRABPL_VERSION: 0.4.15
26+
27+
- name: lint-go
28+
image: grafana/build-container:1.2.21
29+
commands:
30+
- make lint-go
31+
environment:
32+
CGO_ENABLED: 1
33+
depends_on:
34+
- install-deps
35+
36+
- name: codespell
37+
image: grafana/build-container:1.2.21
38+
commands:
39+
- "echo -e \"unknwon\nreferer\nerrorstring\neror\niam\" > words_to_ignore.txt"
40+
- codespell -I words_to_ignore.txt docs/
41+
depends_on:
42+
- install-deps
43+
44+
- name: shellcheck
45+
image: grafana/build-container:1.2.21
46+
commands:
47+
- curl -fLO http://storage.googleapis.com/grafana-downloads/ci-dependencies/shellcheck-v$${VERSION}.linux.x86_64.tar.xz
48+
- echo $$CHKSUM shellcheck-v$${VERSION}.linux.x86_64.tar.xz | sha512sum --check --strict --status
49+
- tar xf shellcheck-v$${VERSION}.linux.x86_64.tar.xz
50+
- mv shellcheck-v$${VERSION}/shellcheck /usr/local/bin/
51+
- rm -rf shellcheck-v$${VERSION}*
52+
- ./bin/grabpl shellcheck
53+
environment:
54+
CHKSUM: beca3d7819a6bdcfbd044576df4fc284053b48f468b2f03428fe66f4ceb2c05d9b5411357fa15003cb0311406c255084cf7283a3b8fce644c340c2f6aa910b9f
55+
VERSION: 0.7.1
56+
depends_on:
57+
- install-deps
58+
59+
- name: build-backend
60+
image: grafana/build-container:1.2.21
61+
commands:
62+
- rm -rf $(go env GOCACHE) && cp -r go-cache $(go env GOCACHE)
63+
- ./bin/grabpl build-backend --github-token "$${GITHUB_TOKEN}" --edition oss --build-id $DRONE_BUILD_NUMBER --variants linux-x64,linux-x64-musl,osx64,win64
64+
environment:
65+
GITHUB_TOKEN:
66+
from_secret: github_token
67+
depends_on:
68+
- install-deps
69+
- lint-go
70+
- test-backend
71+
72+
- name: build-frontend
73+
image: grafana/build-container:1.2.21
74+
commands:
75+
- rm -rf $(yarn cache dir) && cp -r yarn-cache $(yarn cache dir)
76+
- ./bin/grabpl build-frontend --no-install-deps --github-token "$${GITHUB_TOKEN}" --edition oss --build-id $DRONE_BUILD_NUMBER
77+
environment:
78+
GITHUB_TOKEN:
79+
from_secret: github_token
80+
depends_on:
81+
- install-deps
82+
- test-frontend
83+
84+
- name: test-backend
85+
image: grafana/build-container:1.2.21
86+
commands:
87+
- go test -covermode=atomic ./pkg/...
88+
- ./bin/grabpl integration-tests
89+
- cp -r $(go env GOCACHE) go-cache
90+
depends_on:
91+
- install-deps
92+
- lint-go
93+
94+
- name: test-frontend
95+
image: grafana/build-container:1.2.21
96+
commands:
97+
- rm -rf $(yarn cache dir) && cp -r yarn-cache $(yarn cache dir)
98+
- yarn run prettier:check
99+
- yarn run packages:typecheck
100+
- yarn run typecheck
101+
- yarn run test
102+
depends_on:
103+
- install-deps
104+
105+
- name: build-plugins
106+
image: grafana/build-container:1.2.21
107+
commands:
108+
- rm -rf $(yarn cache dir) && cp -r yarn-cache $(yarn cache dir)
109+
- ./bin/grabpl build-plugins --edition oss --no-install-deps
110+
depends_on:
111+
- install-deps
112+
- lint-go
113+
114+
- name: package
115+
image: grafana/build-container:1.2.21
116+
commands:
117+
- . scripts/build/gpg-test-vars.sh && ./bin/grabpl package --github-token "$${GITHUB_TOKEN}" --edition oss --build-id $DRONE_BUILD_NUMBER --variants linux-x64,linux-x64-musl,osx64,win64
118+
environment:
119+
GITHUB_TOKEN:
120+
from_secret: github_token
121+
depends_on:
122+
- build-backend
123+
- build-frontend
124+
- build-plugins
125+
- test-backend
126+
- test-frontend
127+
- codespell
128+
- shellcheck
129+
130+
- name: end-to-end-tests-server
131+
image: grafana/build-container:1.2.21
132+
detach: true
133+
commands:
134+
- ./e2e/start-server
135+
depends_on:
136+
- package
137+
138+
- name: end-to-end-tests
139+
image: grafana/ci-e2e:12.18-1
140+
commands:
141+
- rm -rf $(yarn cache dir) && cp -r yarn-cache $(yarn cache dir)
142+
- ./node_modules/.bin/cypress install
143+
- ./e2e/wait-for-grafana
144+
- ./e2e/run-suite
145+
environment:
146+
HOST: end-to-end-tests-server
147+
depends_on:
148+
- end-to-end-tests-server
149+
150+
- name: publish-storybook
151+
image: grafana/build-container:1.2.21
152+
commands:
153+
- rm -rf $(yarn cache dir) && cp -r yarn-cache $(yarn cache dir)
154+
- yarn storybook:build
155+
depends_on:
156+
- package
157+
158+
- name: build-docs-website
159+
image: grafana/docs-base:latest
160+
commands:
161+
- mkdir -p /hugo/content/docs/grafana
162+
- cp -r docs/sources /hugo/content/docs/grafana/latest
163+
- cd /hugo && make prod
164+
165+
- name: copy-packages-for-docker
166+
image: grafana/build-container:1.2.21
167+
commands:
168+
- cp dist/*.tar.gz packaging/docker/
169+
depends_on:
170+
- package
171+
172+
- name: build-docker-images
173+
image: grafana/drone-grafana-docker:0.2.0
174+
settings:
175+
archs: amd64
176+
dry_run: true
177+
edition: oss
178+
depends_on:
179+
- copy-packages-for-docker
180+
181+
- name: postgres-integration-test
182+
image: grafana/build-container:1.2.21
183+
commands:
184+
- apt-get update
185+
- apt-get install -yq postgresql-client
186+
- ./bin/dockerize -wait tcp://postgres:5432 -timeout 120s
187+
- psql -p 5432 -h postgres -U grafanatest -d grafanatest -f devenv/docker/blocks/postgres_tests/setup.sql
188+
- rm -rf $(go env GOCACHE) && cp -r go-cache $(go env GOCACHE)
189+
- go clean -testcache
190+
- ./bin/grabpl integration-tests --database postgres
191+
environment:
192+
GRAFANA_TEST_DB: postgres
193+
PGPASSWORD: grafanatest
194+
POSTGRES_HOST: postgres
195+
depends_on:
196+
- test-backend
197+
- test-frontend
198+
199+
- name: mysql-integration-test
200+
image: grafana/build-container:1.2.21
201+
commands:
202+
- apt-get update
203+
- apt-get install -yq default-mysql-client
204+
- ./bin/dockerize -wait tcp://mysql:3306 -timeout 120s
205+
- cat devenv/docker/blocks/mysql_tests/setup.sql | mysql -h mysql -P 3306 -u root -prootpass
206+
- rm -rf $(go env GOCACHE) && cp -r go-cache $(go env GOCACHE)
207+
- go clean -testcache
208+
- ./bin/grabpl integration-tests --database mysql
209+
environment:
210+
GRAFANA_TEST_DB: mysql
211+
MYSQL_HOST: mysql
212+
depends_on:
213+
- test-backend
214+
- test-frontend
215+
216+
services:
217+
- name: postgres
218+
image: postgres:12.3-alpine
219+
environment:
220+
POSTGRES_DB: grafanatest
221+
POSTGRES_PASSWORD: grafanatest
222+
POSTGRES_USER: grafanatest
223+
224+
- name: mysql
225+
image: mysql:5.6.48
226+
environment:
227+
MYSQL_DATABASE: grafana_tests
228+
MYSQL_PASSWORD: password
229+
MYSQL_ROOT_PASSWORD: rootpass
230+
MYSQL_USER: grafana
231+
232+
trigger:
233+
event:
234+
- pull_request
235+
236+
---
237+
kind: pipeline
238+
type: docker
239+
name: test-pr-enterprise
240+
241+
platform:
242+
os: linux
243+
arch: amd64
244+
245+
steps:
246+
- name: install-deps
247+
image: grafana/build-container:1.2.21
248+
commands:
249+
- curl -fLO https://grafana-downloads.storage.googleapis.com/grafana-build-pipeline/v$${GRABPL_VERSION}/grabpl
250+
- chmod +x grabpl
251+
- mkdir -p bin
252+
- mv grabpl bin
253+
- curl -fLO https://github.com/jwilder/dockerize/releases/download/v$${DOCKERIZE_VERSION}/dockerize-linux-amd64-v$${DOCKERIZE_VERSION}.tar.gz
254+
- tar -C bin -xzvf dockerize-linux-amd64-v$${DOCKERIZE_VERSION}.tar.gz
255+
- rm dockerize-linux-amd64-v$${DOCKERIZE_VERSION}.tar.gz
256+
- yarn install --frozen-lockfile --no-progress
257+
- cp -r $(yarn cache dir) yarn-cache
258+
environment:
259+
DOCKERIZE_VERSION: 0.6.1
260+
GRABPL_VERSION: 0.4.15
261+
when:
262+
repo:
263+
- grafana/grafana
264+
- aknuds1/grafana
265+
266+
- name: build-backend
267+
image: grafana/build-container:1.2.21
268+
commands:
269+
- ./bin/grabpl build-backend --github-token "$${GITHUB_TOKEN}" --edition enterprise --build-id $DRONE_BUILD_NUMBER --variants linux-x64,linux-x64-musl,osx64,win64
270+
environment:
271+
GITHUB_TOKEN:
272+
from_secret: github_token
273+
when:
274+
repo:
275+
- grafana/grafana
276+
- aknuds1/grafana
277+
depends_on:
278+
- install-deps
279+
280+
- name: build-frontend
281+
image: grafana/build-container:1.2.21
282+
commands:
283+
- rm -rf $(yarn cache dir) && cp -r yarn-cache $(yarn cache dir)
284+
- ./bin/grabpl build-frontend --no-install-deps --github-token "$${GITHUB_TOKEN}" --edition enterprise --build-id $DRONE_BUILD_NUMBER
285+
environment:
286+
GITHUB_TOKEN:
287+
from_secret: github_token
288+
when:
289+
repo:
290+
- grafana/grafana
291+
- aknuds1/grafana
292+
depends_on:
293+
- install-deps
294+
295+
- name: build-plugins
296+
image: grafana/build-container:1.2.21
297+
commands:
298+
- rm -rf $(yarn cache dir) && cp -r yarn-cache $(yarn cache dir)
299+
- ./bin/grabpl build-plugins --edition enterprise --no-install-deps
300+
when:
301+
repo:
302+
- grafana/grafana
303+
- aknuds1/grafana
304+
depends_on:
305+
- install-deps
306+
307+
- name: package
308+
image: grafana/build-container:1.2.21
309+
commands:
310+
- . scripts/build/gpg-test-vars.sh && ./bin/grabpl package --github-token "$${GITHUB_TOKEN}" --edition enterprise --build-id $DRONE_BUILD_NUMBER --variants linux-x64,linux-x64-musl,osx64,win64
311+
environment:
312+
GITHUB_TOKEN:
313+
from_secret: github_token
314+
when:
315+
repo:
316+
- grafana/grafana
317+
- aknuds1/grafana
318+
depends_on:
319+
- build-backend
320+
- build-frontend
321+
- build-plugins
322+
323+
- name: copy-packages-for-docker
324+
image: grafana/build-container:1.2.21
325+
commands:
326+
- cp dist/*.tar.gz packaging/docker/
327+
when:
328+
repo:
329+
- grafana/grafana
330+
- aknuds1/grafana
331+
depends_on:
332+
- package
333+
334+
- name: build-docker-images
335+
image: grafana/drone-grafana-docker:0.2.0
336+
settings:
337+
archs: amd64
338+
dry_run: true
339+
edition: enterprise
340+
when:
341+
repo:
342+
- grafana/grafana
343+
- aknuds1/grafana
344+
depends_on:
345+
- copy-packages-for-docker
346+
347+
trigger:
348+
event:
349+
- pull_request
350+
351+
...

‎.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ trim_trailing_whitespace = false
2525
[Makefile]
2626
indent_style = tab
2727
indent_size = 2
28+
29+
[*.star]
30+
indent_size = 4

‎e2e/run-suite

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#!/bin/bash
2+
set -xeo pipefail
23

34
. e2e/variables
45

6+
HOST=${HOST:-$DEFAULT_HOST}
7+
PORT=${PORT:-$DEFAULT_PORT}
8+
59
echo -e "Starting Cypress scenarios"
610

711
CMD="start"
812
PARAMS=""
913
SLOWMO=0
10-
URL=${BASE_URL:-"http://$DEFAULT_HOST:$DEFAULT_PORT"}
14+
URL=${BASE_URL:-"http://$HOST:$PORT"}
1115
SUITE=${SUITE:-$DEFAULT_SUITE}
1216

1317
if [ "$1" == "debug" ]; then
@@ -23,6 +27,6 @@ fi
2327

2428
cd packages/grafana-e2e
2529

26-
yarn $CMD --env BASE_URL=$URL,CIRCLE_SHA1=$CIRCLE_SHA1,SLOWMO=$SLOWMO \
30+
yarn $CMD --env BASE_URL=$URL,SLOWMO=$SLOWMO \
2731
--config integrationFolder=../../e2e/$SUITE/specs,screenshotsFolder=../../e2e/$SUITE/screenshots,videosFolder=../../e2e/$SUITE/videos,fileServerFolder=./cypress,viewportWidth=1920,viewportHeight=1080,trashAssetsBeforeRuns=false \
2832
$PARAMS

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"e2e:debug": "./e2e/start-and-run-suite debug",
1414
"e2e:dev": "./e2e/start-and-run-suite dev",
1515
"jest": "jest --notify --watch",
16-
"jest-ci": "mkdir -p reports/junit && export JEST_JUNIT_OUTPUT_DIR=reports/junit && jest --ci --reporters=default --reporters=jest-junit --maxWorkers 2",
16+
"jest-ci": "mkdir -p reports/junit && export JEST_JUNIT_OUTPUT_DIR=reports/junit && jest --ci --reporters=default --reporters=jest-junit -w ${TEST_MAX_WORKERS:-100%}",
1717
"lint": "eslint public/app e2e/suite1 public/test --ext=.js,.ts,.tsx",
1818
"lint:fix": "yarn lint --fix",
1919
"packages:build": "lerna run clean && lerna run build --ignore @grafana-plugins/input-datasource",

‎packages/grafana-e2e/src/flows/login.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ export const login = (username: string = 'admin', password: string = 'admin') =>
1313
e2e()
1414
.url()
1515
.then(url => {
16-
if (/^https?:\/\/localhost/.test(url)) {
17-
e2e.pages.Login.skip()
18-
.should('be.visible')
19-
.click();
20-
}
16+
e2e.pages.Login.skip()
17+
.should('be.visible')
18+
.click();
2119
});
2220

2321
e2e()

‎packages/grafana-toolkit/src/cli/tasks/plugin.utils.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,16 @@ export interface GithubPublishOptions {
161161
}
162162

163163
const githubPublishRunner: TaskRunner<GithubPublishOptions> = async ({ dryrun, verbose, commitHash }) => {
164-
if (!process.env['CIRCLE_REPOSITORY_URL']) {
164+
let repoUrl: string | undefined = process.env.DRONE_REPO_LINK || process.env.CIRCLE_REPOSITORY_URL;
165+
if (!repoUrl) {
165166
// Try and figure it out
166167
const repo = await execa('git', ['config', '--local', 'remote.origin.url']);
167168
if (repo && repo.stdout) {
168-
process.env.CIRCLE_REPOSITORY_URL = repo.stdout;
169+
repoUrl = repo.stdout;
169170
} else {
170171
throw new Error(
171-
'The release plugin requires you specify the repository url as environment variable CIRCLE_REPOSITORY_URL'
172+
'The release plugin requires you specify the repository url as environment variable DRONE_REPO_LINK or ' +
173+
'CIRCLE_REPOSITORY_URL'
172174
);
173175
}
174176
}
@@ -190,7 +192,7 @@ const githubPublishRunner: TaskRunner<GithubPublishOptions> = async ({ dryrun, v
190192
process.env['GITHUB_USERNAME'] = DEFAULT_EMAIL_ADDRESS;
191193
}
192194

193-
const parsedUrl = gitUrlParse(process.env['CIRCLE_REPOSITORY_URL']);
195+
const parsedUrl = gitUrlParse(repoUrl);
194196
const githubToken = process.env['GITHUB_ACCESS_TOKEN'];
195197
const githubUser = parsedUrl.owner;
196198

‎packages/grafana-toolkit/src/plugins/env.ts

+39-12
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,47 @@ const getJobFromProcessArgv = () => {
1919
return 'unknown_job';
2020
};
2121

22-
export const job = process.env.CIRCLE_JOB || getJobFromProcessArgv();
22+
export const job =
23+
(process.env.DRONE_STEP_NAME ? process.env.DRONE_STEP_NAME : process.env.CIRCLE_JOB) || getJobFromProcessArgv();
2324

2425
export const getPluginBuildInfo = async (): Promise<PluginBuildInfo> => {
25-
if (process.env.CIRCLE_SHA1) {
26+
if (process.env.CI === 'true') {
27+
let repo: string | undefined;
28+
let branch: string | undefined;
29+
let hash: string | undefined;
30+
let build: number | undefined;
31+
let pr: number | undefined;
32+
if (process.env.DRONE === 'true') {
33+
repo = process.env.DRONE_REPO_LINK;
34+
branch = process.env.DRONE_BRANCH;
35+
hash = process.env.DRONE_COMMIT_SHA;
36+
build = parseInt(process.env.DRONE_BUILD_NUMBER || '', 10);
37+
pr = parseInt(process.env.DRONE_PULL_REQUEST || '', 10);
38+
} else if (process.env.CIRCLECI === 'true') {
39+
repo = process.env.CIRCLE_REPOSITORY_URL;
40+
branch = process.env.CIRCLE_BRANCH;
41+
hash = process.env.CIRCLE_SHA1;
42+
build = parseInt(process.env.CIRCLE_BUILD_NUM || '', 10);
43+
const url = process.env.CIRCLE_PULL_REQUEST || '';
44+
const idx = url.lastIndexOf('/') + 1;
45+
pr = parseInt(url.substring(idx), 10);
46+
}
47+
2648
const info: PluginBuildInfo = {
2749
time: Date.now(),
28-
repo: process.env.CIRCLE_REPOSITORY_URL,
29-
branch: process.env.CIRCLE_BRANCH,
30-
hash: process.env.CIRCLE_SHA1,
50+
repo,
51+
branch,
52+
hash,
3153
};
32-
const pr = getPullRequestNumber();
33-
const build = getBuildNumber();
3454
if (pr) {
3555
info.pr = pr;
3656
}
3757
if (build) {
3858
info.number = build;
3959
}
40-
return Promise.resolve(info);
60+
return info;
4161
}
62+
4263
const branch = await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD']);
4364
const hash = await execa('git', ['rev-parse', 'HEAD']);
4465
return {
@@ -49,18 +70,24 @@ export const getPluginBuildInfo = async (): Promise<PluginBuildInfo> => {
4970
};
5071

5172
export const getBuildNumber = (): number | undefined => {
52-
if (process.env.CIRCLE_BUILD_NUM) {
53-
return parseInt(process.env.CIRCLE_BUILD_NUM, 10);
73+
if (process.env.DRONE === 'true') {
74+
return parseInt(process.env.DRONE_BUILD_NUMBER || '', 10);
75+
} else if (process.env.CIRCLECI === 'true') {
76+
return parseInt(process.env.CIRCLE_BUILD_NUM || '', 10);
5477
}
78+
5579
return undefined;
5680
};
5781

5882
export const getPullRequestNumber = (): number | undefined => {
59-
if (process.env.CIRCLE_PULL_REQUEST) {
60-
const url = process.env.CIRCLE_PULL_REQUEST;
83+
if (process.env.DRONE === 'true') {
84+
return parseInt(process.env.DRONE_PULL_REQUEST || '', 10);
85+
} else if (process.env.CIRCLECI === 'true') {
86+
const url = process.env.CIRCLE_PULL_REQUEST || '';
6187
const idx = url.lastIndexOf('/') + 1;
6288
return parseInt(url.substring(idx), 10);
6389
}
90+
6491
return undefined;
6592
};
6693

‎packaging/docker/build-deploy.sh

-32
This file was deleted.

‎packaging/docker/deploy_to_k8s.sh

-6
This file was deleted.

‎pkg/services/sqlstore/migrations/migrations_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
func TestMigrations(t *testing.T) {
1414
testDBs := []sqlutil.TestDB{
15-
sqlutil.TestDB_Sqlite3,
15+
sqlutil.Sqlite3TestDB(),
1616
}
1717

1818
for _, testDB := range testDBs {

‎pkg/services/sqlstore/migrator/mysql_dialect.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package migrator
22

33
import (
4-
"fmt"
54
"strconv"
65
"strings"
76

87
"github.com/VividCortex/mysqlerr"
98
"github.com/go-sql-driver/mysql"
9+
"github.com/grafana/grafana/pkg/util/errutil"
1010
"xorm.io/xorm"
1111
)
1212

@@ -115,19 +115,22 @@ func (db *Mysql) ColumnCheckSql(tableName, columnName string) (string, []interfa
115115
}
116116

117117
func (db *Mysql) CleanDB() error {
118-
tables, _ := db.engine.DBMetas()
118+
tables, err := db.engine.DBMetas()
119+
if err != nil {
120+
return err
121+
}
119122
sess := db.engine.NewSession()
120123
defer sess.Close()
121124

122125
for _, table := range tables {
123126
if _, err := sess.Exec("set foreign_key_checks = 0"); err != nil {
124-
return fmt.Errorf("failed to disable foreign key checks")
127+
return errutil.Wrap("failed to disable foreign key checks", err)
125128
}
126129
if _, err := sess.Exec("drop table " + table.Name + " ;"); err != nil {
127-
return fmt.Errorf("failed to delete table: %v, err: %v", table.Name, err)
130+
return errutil.Wrapf(err, "failed to delete table %q", table.Name)
128131
}
129132
if _, err := sess.Exec("set foreign_key_checks = 1"); err != nil {
130-
return fmt.Errorf("failed to disable foreign key checks")
133+
return errutil.Wrap("failed to disable foreign key checks", err)
131134
}
132135
}
133136

‎pkg/services/sqlstore/migrator/postgres_dialect.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ func (db *Postgres) CleanDB() error {
130130
defer sess.Close()
131131

132132
if _, err := sess.Exec("DROP SCHEMA public CASCADE;"); err != nil {
133-
return fmt.Errorf("Failed to drop schema public")
133+
return errutil.Wrap("failed to drop schema public", err)
134134
}
135135

136136
if _, err := sess.Exec("CREATE SCHEMA public;"); err != nil {
137-
return fmt.Errorf("Failed to create schema public")
137+
return errutil.Wrap("failed to create schema public", err)
138138
}
139139

140140
return nil

‎pkg/services/sqlstore/sqlstore.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,10 @@ func (ss *SqlStore) readConfig() {
335335
type ITestDB interface {
336336
Helper()
337337
Fatalf(format string, args ...interface{})
338+
Logf(format string, args ...interface{})
338339
}
339340

340-
// InitTestDB initialize test DB.
341+
// InitTestDB initializes the test DB.
341342
func InitTestDB(t ITestDB) *SqlStore {
342343
t.Helper()
343344
sqlstore := &SqlStore{}
@@ -349,6 +350,7 @@ func InitTestDB(t ITestDB) *SqlStore {
349350

350351
// environment variable present for test db?
351352
if db, present := os.LookupEnv("GRAFANA_TEST_DB"); present {
353+
t.Logf("Using database type %q", db)
352354
dbType = db
353355
}
354356

@@ -364,20 +366,21 @@ func InitTestDB(t ITestDB) *SqlStore {
364366

365367
switch dbType {
366368
case "mysql":
367-
if _, err := sec.NewKey("connection_string", sqlutil.TestDB_Mysql.ConnStr); err != nil {
369+
if _, err := sec.NewKey("connection_string", sqlutil.MySQLTestDB().ConnStr); err != nil {
368370
t.Fatalf("Failed to create key: %s", err)
369371
}
370372
case "postgres":
371-
if _, err := sec.NewKey("connection_string", sqlutil.TestDB_Postgres.ConnStr); err != nil {
373+
if _, err := sec.NewKey("connection_string", sqlutil.PostgresTestDB().ConnStr); err != nil {
372374
t.Fatalf("Failed to create key: %s", err)
373375
}
374376
default:
375-
if _, err := sec.NewKey("connection_string", sqlutil.TestDB_Sqlite3.ConnStr); err != nil {
377+
if _, err := sec.NewKey("connection_string", sqlutil.Sqlite3TestDB().ConnStr); err != nil {
376378
t.Fatalf("Failed to create key: %s", err)
377379
}
378380
}
379381

380382
// need to get engine to clean db before we init
383+
t.Logf("Creating database connection: %q", sec.Key("connection_string"))
381384
engine, err := xorm.NewEngine(dbType, sec.Key("connection_string").String())
382385
if err != nil {
383386
t.Fatalf("Failed to init test database: %v", err)
@@ -388,6 +391,7 @@ func InitTestDB(t ITestDB) *SqlStore {
388391
// temp global var until we get rid of global vars
389392
dialect = sqlstore.Dialect
390393

394+
t.Logf("Cleaning DB")
391395
if err := dialect.CleanDB(); err != nil {
392396
t.Fatalf("Failed to clean test db %v", err)
393397
}
+58-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,65 @@
11
package sqlutil
22

3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
38
type TestDB struct {
49
DriverName string
510
ConnStr string
611
}
712

8-
var TestDB_Sqlite3 = TestDB{DriverName: "sqlite3", ConnStr: ":memory:"}
9-
var TestDB_Mysql = TestDB{DriverName: "mysql", ConnStr: "grafana:password@tcp(localhost:3306)/grafana_tests?collation=utf8mb4_unicode_ci"}
10-
var TestDB_Postgres = TestDB{DriverName: "postgres", ConnStr: "user=grafanatest password=grafanatest host=localhost port=5432 dbname=grafanatest sslmode=disable"}
11-
var TestDB_Mssql = TestDB{DriverName: "mssql", ConnStr: "server=localhost;port=1433;database=grafanatest;user id=grafana;password=Password!"}
13+
func Sqlite3TestDB() TestDB {
14+
return TestDB{
15+
DriverName: "sqlite3",
16+
ConnStr: ":memory:",
17+
}
18+
}
19+
20+
func MySQLTestDB() TestDB {
21+
host := os.Getenv("MYSQL_HOST")
22+
if host == "" {
23+
host = "localhost"
24+
}
25+
port := os.Getenv("MYSQL_PORT")
26+
if port == "" {
27+
port = "3306"
28+
}
29+
return TestDB{
30+
DriverName: "mysql",
31+
ConnStr: fmt.Sprintf("grafana:password@tcp(%s:%s)/grafana_tests?collation=utf8mb4_unicode_ci", host, port),
32+
}
33+
}
34+
35+
func PostgresTestDB() TestDB {
36+
host := os.Getenv("POSTGRES_HOST")
37+
if host == "" {
38+
host = "localhost"
39+
}
40+
port := os.Getenv("POSTGRES_PORT")
41+
if port == "" {
42+
port = "5432"
43+
}
44+
connStr := fmt.Sprintf("user=grafanatest password=grafanatest host=%s port=%s dbname=grafanatest sslmode=disable",
45+
host, port)
46+
return TestDB{
47+
DriverName: "postgres",
48+
ConnStr: connStr,
49+
}
50+
}
51+
52+
func MSSQLTestDB() TestDB {
53+
host := os.Getenv("MSSQL_HOST")
54+
if host == "" {
55+
host = "localhost"
56+
}
57+
port := os.Getenv("MSSQL_PORT")
58+
if port == "" {
59+
port = "1433"
60+
}
61+
return TestDB{
62+
DriverName: "mssql",
63+
ConnStr: fmt.Sprintf("server=%s;port=%s;database=grafanatest;user id=grafana;password=Password!", host, port),
64+
}
65+
}

‎pkg/tsdb/mssql/mssql_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,9 @@ func TestMSSQL(t *testing.T) {
11371137
}
11381138

11391139
func InitMSSQLTestDB(t *testing.T) *xorm.Engine {
1140-
x, err := xorm.NewEngine(sqlutil.TestDB_Mssql.DriverName, strings.Replace(sqlutil.TestDB_Mssql.ConnStr, "localhost", serverIP, 1))
1140+
testDB := sqlutil.MSSQLTestDB()
1141+
x, err := xorm.NewEngine(testDB.DriverName, strings.Replace(testDB.ConnStr, "localhost",
1142+
serverIP, 1))
11411143
if err != nil {
11421144
t.Fatalf("Failed to init mssql db %v", err)
11431145
}

‎pkg/tsdb/mysql/mysql_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build integration
2+
13
package mysql
24

35
import (
@@ -1040,7 +1042,9 @@ func TestMySQL(t *testing.T) {
10401042
}
10411043

10421044
func InitMySQLTestDB(t *testing.T) *xorm.Engine {
1043-
x, err := xorm.NewEngine(sqlutil.TestDB_Mysql.DriverName, strings.Replace(sqlutil.TestDB_Mysql.ConnStr, "/grafana_tests", "/grafana_ds_tests", 1))
1045+
testDB := sqlutil.MySQLTestDB()
1046+
x, err := xorm.NewEngine(testDB.DriverName, strings.Replace(testDB.ConnStr, "/grafana_tests",
1047+
"/grafana_ds_tests", 1))
10441048
if err != nil {
10451049
t.Fatalf("Failed to init mysql db %v", err)
10461050
}

‎pkg/tsdb/postgres/postgres_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build integration
2+
13
package postgres
24

35
import (
@@ -1064,9 +1066,11 @@ func TestPostgres(t *testing.T) {
10641066
}
10651067

10661068
func InitPostgresTestDB(t *testing.T) *xorm.Engine {
1067-
x, err := xorm.NewEngine(sqlutil.TestDB_Postgres.DriverName, strings.Replace(sqlutil.TestDB_Postgres.ConnStr, "dbname=grafanatest", "dbname=grafanadstest", 1))
1069+
testDB := sqlutil.PostgresTestDB()
1070+
x, err := xorm.NewEngine(testDB.DriverName, strings.Replace(testDB.ConnStr, "dbname=grafanatest",
1071+
"dbname=grafanadstest", 1))
10681072
if err != nil {
1069-
t.Fatalf("Failed to init postgres db %v", err)
1073+
t.Fatalf("Failed to init postgres DB %v", err)
10701074
}
10711075

10721076
x.DatabaseTZ = time.UTC

‎scripts/build/build-all.sh

-106
This file was deleted.

‎scripts/build/ci-build/Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ RUN apt-get update && \
101101
apt-get install -yq \
102102
build-essential clang gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf gcc-mingw-w64-x86-64 \
103103
apt-transport-https \
104+
python-pip \
104105
ca-certificates \
105106
curl \
106107
libfontconfig1 \
@@ -126,7 +127,8 @@ RUN apt-get update && \
126127
apt-get update && apt-get install -yq yarn=${YARNVERSION} && \
127128
curl -fL https://storage.googleapis.com/golang/go${GOVERSION}.linux-amd64.tar.gz \
128129
| tar -xz -C /usr/local && \
129-
git clone https://github.com/raspberrypi/tools.git /opt/rpi-tools --depth=1
130+
git clone https://github.com/raspberrypi/tools.git /opt/rpi-tools --depth=1 && \
131+
pip install codespell
130132

131133
# We build our own musl cross-compilers via the musl-cross-make project, on the same OS as this image's base image,
132134
# to ensure compatibility. We also make sure to target musl 1.1.x, since musl 1.2.x introduces 64-bit time types

‎scripts/build/ci-build/build-deploy.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -eo pipefail
33

4-
_version="1.2.20"
4+
_version="1.2.21"
55
_tag="grafana/build-container:${_version}"
66

77
_dpath=$(dirname "${BASH_SOURCE[0]}")

‎scripts/build/ci-e2e/Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM node:12.18-buster-slim
2+
3+
WORKDIR /root
4+
5+
RUN apt-get update && apt-get install -yq gnupg netcat curl
6+
RUN curl -fsSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - && \
7+
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list && \
8+
# Cypress dependencies
9+
apt-get update && apt-get install -yq libgtk2.0-0 libgtk-3-0 libnotify-dev libgconf-2-4 libnss3 libxss1 \
10+
libasound2 libxtst6 xauth xvfb google-chrome-stable && \
11+
apt-get autoremove -y && rm -rf /var/lib/apt/lists/*

‎scripts/build/prepare-enterprise.sh

-14
This file was deleted.

‎scripts/circle-release-next-packages.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ else
6767
start=$(date +%s%N)
6868
yarn workspace @grafana/"${PACKAGE}" run build
6969
runtime=$((($(date +%s%N) - start)/1000000))
70-
if [ "${CIRCLE_BRANCH}" == "master" ]; then
71-
exit_if_fail ./scripts/ci-metrics-publisher.sh "grafana.ci-buildtimes.$CIRCLE_JOB.$PACKAGE=$runtime"
70+
if [ "${DRONE_BRANCH}" == "master" ]; then
71+
exit_if_fail ./scripts/ci-metrics-publisher.sh "grafana.ci-buildtimes.${DRONE_STEP_NAME}.$PACKAGE=$runtime"
72+
elif [ "${CIRCLE_BRANCH}" == "master" ]; then
73+
exit_if_fail ./scripts/ci-metrics-publisher.sh "grafana.ci-buildtimes.${CIRCLE_JOB}.$PACKAGE=$runtime"
7274
fi
7375

7476
exit_status=$?

‎scripts/circle-test-frontend.sh

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ source "$(dirname "$0")/helpers/exit-if-fail.sh"
55

66
start=$(date +%s)
77

8+
export TEST_MAX_WORKERS=2
9+
810
exit_if_fail yarn run prettier:check
911
exit_if_fail yarn run packages:typecheck
1012
exit_if_fail yarn run typecheck

0 commit comments

Comments
 (0)
Please sign in to comment.