Skip to content

Commit bfce979

Browse files
ye11owjovezhong
andauthored
v2.0.0, improve stability and update SDKs (#2)
* feat: new code based no new sdk * fix * fix * fixed bool * bumped version to 1.1.0 * fix * Update plugin display name and desc * update go.mod/sum via `go mod tidy` * Update LICENSE to avoid placeholder text * per review feedback, update version to 2.0.0 * update CHANGELOG and package-lock to 2.0.0 --------- Co-authored-by: Jove Zhong <[email protected]>
1 parent eff3319 commit bfce979

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+9987
-14697
lines changed

.config/.cprc.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"version": "5.5.3"
3+
}

.config/.eslintrc

+15-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,24 @@
22
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
33
*
44
* In order to extend the configuration follow the steps in
5-
* https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-eslint-config
5+
* https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment#extend-the-eslint-config
66
*/
7-
{
7+
{
88
"extends": ["@grafana/eslint-config"],
99
"root": true,
1010
"rules": {
1111
"react/prop-types": "off"
12-
}
12+
},
13+
"overrides": [
14+
{
15+
"plugins": ["deprecation"],
16+
"files": ["src/**/*.{ts,tsx}"],
17+
"rules": {
18+
"deprecation/deprecation": "warn"
19+
},
20+
"parserOptions": {
21+
"project": "./tsconfig.json"
22+
}
23+
}
24+
]
1325
}

.config/.prettierrc.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
*/
66

77
module.exports = {
8-
"endOfLine": "auto",
9-
"printWidth": 120,
10-
"trailingComma": "es5",
11-
"semi": true,
12-
"jsxSingleQuote": false,
13-
"singleQuote": true,
14-
"useTabs": false,
15-
"tabWidth": 2
16-
};
8+
endOfLine: 'auto',
9+
printWidth: 120,
10+
trailingComma: 'es5',
11+
semi: true,
12+
jsxSingleQuote: false,
13+
singleQuote: true,
14+
useTabs: false,
15+
tabWidth: 2,
16+
};

.config/Dockerfile

+62-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ ARG grafana_image=grafana-enterprise
33

44
FROM grafana/${grafana_image}:${grafana_version}
55

6+
ARG development=false
7+
ARG TARGETARCH
8+
9+
ARG GO_VERSION=1.21.6
10+
ARG GO_ARCH=${TARGETARCH:-amd64}
11+
12+
ENV DEV "${development}"
13+
614
# Make it as simple as possible to access the grafana instance for development purposes
715
# Do NOT enable these settings in a public facing / production grafana instance
816
ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin"
@@ -11,6 +19,58 @@ ENV GF_AUTH_BASIC_ENABLED "false"
1119
# Set development mode so plugins can be loaded without the need to sign
1220
ENV GF_DEFAULT_APP_MODE "development"
1321

14-
# Inject livereload script into grafana index.html
22+
23+
LABEL maintainer="Grafana Labs <[email protected]>"
24+
25+
ENV GF_PATHS_HOME="/usr/share/grafana"
26+
WORKDIR $GF_PATHS_HOME
27+
1528
USER root
16-
RUN sed -i 's/<\/body><\/html>/<script src=\"http:\/\/localhost:35729\/livereload.js\"><\/script><\/body><\/html>/g' /usr/share/grafana/public/views/index.html
29+
30+
# Installing supervisor and inotify-tools
31+
RUN if [ "${development}" = "true" ]; then \
32+
if grep -i -q alpine /etc/issue; then \
33+
apk add supervisor inotify-tools git; \
34+
elif grep -i -q ubuntu /etc/issue; then \
35+
DEBIAN_FRONTEND=noninteractive && \
36+
apt-get update && \
37+
apt-get install -y supervisor inotify-tools git && \
38+
rm -rf /var/lib/apt/lists/*; \
39+
else \
40+
echo 'ERROR: Unsupported base image' && /bin/false; \
41+
fi \
42+
fi
43+
44+
COPY supervisord/supervisord.conf /etc/supervisor.d/supervisord.ini
45+
COPY supervisord/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
46+
47+
48+
# Installing Go
49+
RUN if [ "${development}" = "true" ]; then \
50+
curl -O -L https://golang.org/dl/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \
51+
rm -rf /usr/local/go && \
52+
tar -C /usr/local -xzf go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \
53+
echo "export PATH=$PATH:/usr/local/go/bin:~/go/bin" >> ~/.bashrc && \
54+
rm -f go${GO_VERSION}.linux-${GO_ARCH}.tar.gz; \
55+
fi
56+
57+
# Installing delve for debugging
58+
RUN if [ "${development}" = "true" ]; then \
59+
/usr/local/go/bin/go install github.com/go-delve/delve/cmd/dlv@latest; \
60+
fi
61+
62+
# Installing mage for plugin (re)building
63+
RUN if [ "${development}" = "true" ]; then \
64+
git clone https://github.com/magefile/mage; \
65+
cd mage; \
66+
export PATH=$PATH:/usr/local/go/bin; \
67+
go run bootstrap.go; \
68+
fi
69+
70+
# Inject livereload script into grafana index.html
71+
RUN sed -i 's|</body>|<script src="http://localhost:35729/livereload.js"></script></body>|g' /usr/share/grafana/public/views/index.html
72+
73+
74+
COPY entrypoint.sh /entrypoint.sh
75+
RUN chmod +x /entrypoint.sh
76+
ENTRYPOINT ["/entrypoint.sh"]

.config/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ set up the Jest DOM for the testing library and to apply some polyfills. ([link
5656

5757
#### ESM errors with Jest
5858

59-
A common issue found with the current jest config involves importing an npm package which only offers an ESM build. These packages cause jest to error with `SyntaxError: Cannot use import statement outside a module`. To work around this we provide a list of known packages to pass to the `[transformIgnorePatterns](https://jestjs.io/docs/configuration#transformignorepatterns-arraystring)` jest configuration property. If need be this can be extended in the following way:
59+
A common issue with the current jest config involves importing an npm package that only offers an ESM build. These packages cause jest to error with `SyntaxError: Cannot use import statement outside a module`. To work around this, we provide a list of known packages to pass to the `[transformIgnorePatterns](https://jestjs.io/docs/configuration#transformignorepatterns-arraystring)` jest configuration property. If need be, this can be extended in the following way:
6060

6161
```javascript
6262
process.env.TZ = 'UTC';
@@ -142,7 +142,7 @@ We need to update the `scripts` in the `package.json` to use the extended Webpac
142142

143143
### Configure grafana image to use when running docker
144144

145-
By default `grafana-enterprise` will be used as the docker image for all docker related commands. If you want to override this behaviour simply alter the `docker-compose.yaml` by adding the following build arg `grafana_image`.
145+
By default, `grafana-enterprise` will be used as the docker image for all docker related commands. If you want to override this behavior, simply alter the `docker-compose.yaml` by adding the following build arg `grafana_image`.
146146

147147
**Example:**
148148

@@ -159,6 +159,6 @@ services:
159159
grafana_image: ${GRAFANA_IMAGE:-grafana}
160160
```
161161
162-
In this example we are assigning the environment variable `GRAFANA_IMAGE` to the build arg `grafana_image` with a default value of `grafana`. This will give you the possibility to set the value while running the docker-compose commands which might be convinent in some scenarios.
162+
In this example, we assign the environment variable `GRAFANA_IMAGE` to the build arg `grafana_image` with a default value of `grafana`. This will allow you to set the value while running the docker compose commands, which might be convenient in some scenarios.
163163

164164
---

.config/entrypoint.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
if [ "${DEV}" = "false" ]; then
4+
echo "Starting test mode"
5+
exec /run.sh
6+
fi
7+
8+
echo "Starting development mode"
9+
10+
if grep -i -q alpine /etc/issue; then
11+
exec /usr/bin/supervisord -c /etc/supervisord.conf
12+
elif grep -i -q ubuntu /etc/issue; then
13+
exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf
14+
else
15+
echo 'ERROR: Unsupported base image'
16+
exit 1
17+
fi
18+

.config/jest-setup.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
33
*
44
* In order to extend the configuration follow the steps in
5-
* https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-jest-config
5+
* https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment#extend-the-jest-config
66
*/
77

88
import '@testing-library/jest-dom';
9+
import { TextEncoder, TextDecoder } from 'util';
10+
11+
Object.assign(global, { TextDecoder, TextEncoder });
912

1013
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
1114
Object.defineProperty(global, 'matchMedia', {
1215
writable: true,
13-
value: jest.fn().mockImplementation((query) => ({
16+
value: (query) => ({
1417
matches: false,
1518
media: query,
1619
onchange: null,
@@ -19,7 +22,7 @@ Object.defineProperty(global, 'matchMedia', {
1922
addEventListener: jest.fn(),
2023
removeEventListener: jest.fn(),
2124
dispatchEvent: jest.fn(),
22-
})),
25+
}),
2326
});
2427

2528
HTMLCanvasElement.prototype.getContext = () => {};

.config/jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
33
*
44
* In order to extend the configuration follow the steps in
5-
* https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-jest-config
5+
* https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment#extend-the-jest-config
66
*/
77

88
const path = require('path');

.config/supervisord/supervisord.conf

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[supervisord]
2+
nodaemon=true
3+
user=root
4+
5+
[program:grafana]
6+
user=root
7+
directory=/var/lib/grafana
8+
command=bash -c 'while [ ! -f /root/timeplus-timeplus-datasource/dist/gpx_timeplus* ]; do sleep 1; done; /run.sh'
9+
stdout_logfile=/dev/fd/1
10+
stdout_logfile_maxbytes=0
11+
redirect_stderr=true
12+
killasgroup=true
13+
stopasgroup=true
14+
autostart=true
15+
16+
[program:delve]
17+
user=root
18+
command=/bin/bash -c 'pid=""; while [ -z "$pid" ]; do pid=$(pgrep -f gpx_timeplus); done; /root/go/bin/dlv attach --api-version=2 --headless --continue --accept-multiclient --listen=:2345 $pid'
19+
stdout_logfile=/dev/fd/1
20+
stdout_logfile_maxbytes=0
21+
redirect_stderr=true
22+
killasgroup=false
23+
stopasgroup=false
24+
autostart=true
25+
autorestart=true
26+
27+
[program:build-watcher]
28+
user=root
29+
command=/bin/bash -c 'while inotifywait -e modify,create,delete -r /var/lib/grafana/plugins/timeplus-timeplus-datasource; do echo "Change detected, restarting delve...";supervisorctl restart delve; done'
30+
stdout_logfile=/dev/fd/1
31+
stdout_logfile_maxbytes=0
32+
redirect_stderr=true
33+
killasgroup=true
34+
stopasgroup=true
35+
autostart=true
36+
37+
[program:mage-watcher]
38+
user=root
39+
environment=PATH="/usr/local/go/bin:/root/go/bin:%(ENV_PATH)s"
40+
directory=/root/timeplus-timeplus-datasource
41+
command=/bin/bash -c 'git config --global --add safe.directory /root/timeplus-timeplus-datasource && mage -v watch'
42+
stdout_logfile=/dev/fd/1
43+
stdout_logfile_maxbytes=0
44+
redirect_stderr=true
45+
killasgroup=true
46+
stopasgroup=true
47+
autostart=true

.config/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
33
*
44
* In order to extend the configuration follow the steps in
5-
* https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-typescript-config
5+
* https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment#extend-the-typescript-config
66
*/
7-
{
7+
{
88
"compilerOptions": {
99
"alwaysStrict": true,
1010
"declaration": false,

.config/webpack/utils.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import fs from 'fs';
22
import process from 'process';
33
import os from 'os';
44
import path from 'path';
5-
import util from 'util';
65
import { glob } from 'glob';
76
import { SOURCE_DIR } from './constants';
87

9-
108
export function isWSL() {
119
if (process.platform !== 'linux') {
1210
return false;
@@ -21,7 +19,7 @@ export function isWSL() {
2119
} catch {
2220
return false;
2321
}
24-
}
22+
}
2523

2624
export function getPackageJson() {
2725
return require(path.resolve(process.cwd(), 'package.json'));
@@ -31,6 +29,11 @@ export function getPluginJson() {
3129
return require(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`));
3230
}
3331

32+
export function getCPConfigVersion() {
33+
const cprcJson = path.resolve(__dirname, '../', '.cprc.json');
34+
return fs.existsSync(cprcJson) ? require(cprcJson).version : { version: 'unknown' };
35+
}
36+
3437
export function hasReadme() {
3538
return fs.existsSync(path.resolve(process.cwd(), SOURCE_DIR, 'README.md'));
3639
}
@@ -40,7 +43,8 @@ export function hasReadme() {
4043
export async function getEntries(): Promise<Record<string, string>> {
4144
const pluginsJson = await glob('**/src/**/plugin.json', { absolute: true });
4245

43-
const plugins = await Promise.all(pluginsJson.map((pluginJson) => {
46+
const plugins = await Promise.all(
47+
pluginsJson.map((pluginJson) => {
4448
const folder = path.dirname(pluginJson);
4549
return glob(`${folder}/module.{ts,tsx,js,jsx}`, { absolute: true });
4650
})

0 commit comments

Comments
 (0)