Skip to content

Commit cd1de97

Browse files
authoredJun 19, 2024··
Chore: Bump create plugin to 4.12.0 (#881)
1 parent 6655ad3 commit cd1de97

24 files changed

+3844
-3474
lines changed
 

‎.config/.cprc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "2.10.1"
2+
"version": "4.12.0"
33
}

‎.config/Dockerfile

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

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

6+
ARG development=false
7+
8+
ARG GO_VERSION=1.21.6
9+
ARG GO_ARCH=amd64
10+
11+
ENV DEV "${development}"
12+
613
# Make it as simple as possible to access the grafana instance for development purposes
714
# Do NOT enable these settings in a public facing / production grafana instance
815
ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin"
@@ -11,6 +18,58 @@ ENV GF_AUTH_BASIC_ENABLED "false"
1118
# Set development mode so plugins can be loaded without the need to sign
1219
ENV GF_DEFAULT_APP_MODE "development"
1320

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

‎.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

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
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', {

‎.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/yesoreyeram-infinity-datasource/dist/gpx_infinity* ]; 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_infinity); 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/yesoreyeram-infinity-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/yesoreyeram-infinity-datasource
41+
command=/bin/bash -c 'git config --global --add safe.directory /root/yesoreyeram-infinity-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/webpack/utils.ts

+3-12
Original file line numberDiff line numberDiff line change
@@ -2,12 +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';
6-
import glob from 'glob';
5+
import { glob } from 'glob';
76
import { SOURCE_DIR } from './constants';
87

9-
const globAsync = util.promisify(glob);
10-
118
export function isWSL() {
129
if (process.platform !== 'linux') {
1310
return false;
@@ -32,25 +29,19 @@ export function getPluginJson() {
3229
return require(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`));
3330
}
3431

35-
export function getPluginId() {
36-
const { id } = require(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`));
37-
38-
return id;
39-
}
40-
4132
export function hasReadme() {
4233
return fs.existsSync(path.resolve(process.cwd(), SOURCE_DIR, 'README.md'));
4334
}
4435

4536
// Support bundling nested plugins by finding all plugin.json files in src directory
4637
// then checking for a sibling module.[jt]sx? file.
4738
export async function getEntries(): Promise<Record<string, string>> {
48-
const pluginsJson = await globAsync('**/src/**/plugin.json', { absolute: true });
39+
const pluginsJson = await glob('**/src/**/plugin.json', { absolute: true });
4940

5041
const plugins = await Promise.all(
5142
pluginsJson.map((pluginJson) => {
5243
const folder = path.dirname(pluginJson);
53-
return globAsync(`${folder}/module.{ts,tsx,js,jsx}`, { absolute: true });
44+
return glob(`${folder}/module.{ts,tsx,js,jsx}`, { absolute: true });
5445
})
5546
);
5647

‎.config/webpack/webpack.config.ts

+21-14
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ const config = async (env): Promise<Configuration> => {
7171
},
7272
],
7373

74+
// Support WebAssembly according to latest spec - makes WebAssembly module async
75+
experiments: {
76+
asyncWebAssembly: true,
77+
},
78+
7479
mode: env.production ? 'production' : 'development',
7580

7681
module: {
@@ -82,7 +87,7 @@ const config = async (env): Promise<Configuration> => {
8287
loader: 'swc-loader',
8388
options: {
8489
jsc: {
85-
baseUrl: path.resolve(__dirname, 'src'),
90+
baseUrl: path.resolve(process.cwd(), SOURCE_DIR),
8691
target: 'es2015',
8792
loose: false,
8893
parser: {
@@ -155,7 +160,7 @@ const config = async (env): Promise<Configuration> => {
155160
{ from: 'img/**/*', to: '.', noErrorOnMissing: true }, // Optional
156161
{ from: 'libs/**/*', to: '.', noErrorOnMissing: true }, // Optional
157162
{ from: 'static/**/*', to: '.', noErrorOnMissing: true }, // Optional
158-
{ from: '**/query_help.md', to: '.', noErrorOnMissing: true}, // Optional
163+
{ from: '**/query_help.md', to: '.', noErrorOnMissing: true }, // Optional
159164
],
160165
}),
161166
// Replace certain template-variables in the README and plugin.json
@@ -179,18 +184,20 @@ const config = async (env): Promise<Configuration> => {
179184
],
180185
},
181186
]),
182-
new ForkTsCheckerWebpackPlugin({
183-
async: Boolean(env.development),
184-
issue: {
185-
include: [{ file: '**/*.{ts,tsx}' }],
186-
},
187-
typescript: { configFile: path.join(process.cwd(), 'tsconfig.json') },
188-
}),
189-
new ESLintPlugin({
190-
extensions: ['.ts', '.tsx'],
191-
lintDirtyModulesOnly: Boolean(env.development), // don't lint on start, only lint changed files
192-
}),
193-
...(env.development ? [new LiveReloadPlugin()] : []),
187+
...(env.development ? [
188+
new LiveReloadPlugin(),
189+
new ForkTsCheckerWebpackPlugin({
190+
async: Boolean(env.development),
191+
issue: {
192+
include: [{ file: '**/*.{ts,tsx}' }],
193+
},
194+
typescript: { configFile: path.join(process.cwd(), 'tsconfig.json') },
195+
}),
196+
new ESLintPlugin({
197+
extensions: ['.ts', '.tsx'],
198+
lintDirtyModulesOnly: Boolean(env.development), // don't lint on start, only lint changed files
199+
}),
200+
] : []),
194201
],
195202

196203
resolve: {

‎.eslintrc

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{
2-
"extends": ["eslint:recommended","@grafana/eslint-config"],
3-
"env": { "browser": true, "jest": true },
4-
"plugins": ["import"],
2+
"extends": "./.config/.eslintrc",
3+
"plugins": ["prettier"],
54
"rules": {
6-
"no-extra-boolean-cast":"off",
7-
"no-unused-vars": "off",
8-
"import/order": "off"
5+
"prettier/prettier": "error"
96
}
107
}

‎.github/workflows/lint.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Lint frontend
2+
3+
on: [push]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- uses: actions/setup-node@v3
11+
with:
12+
node-version-file: '.nvmrc'
13+
cache: 'yarn'
14+
- run: yarn install
15+
- run: yarn lint

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ docker/blocks/tempo/tempo-data
3333
.idea
3434
.vscode/
3535
!.vscode/launch.json
36+
.eslintcache

‎jest.config.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,5 @@ const originalConfig = require('./.config/jest.config');
88
module.exports = {
99
// Jest configuration provided by Grafana scaffolding
1010
...originalConfig,
11-
transformIgnorePatterns: originalConfig.transformIgnorePatterns.map((pattern) =>
12-
pattern.startsWith('node_modules') ? `../../${pattern}` : pattern
13-
),
14-
};
11+
transformIgnorePatterns: originalConfig.transformIgnorePatterns.map((pattern) => (pattern.startsWith('node_modules') ? `../../${pattern}` : pattern)),
12+
};

0 commit comments

Comments
 (0)
Please sign in to comment.