Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 104 additions & 23 deletions .github/workflows/grafana-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,126 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

# The Node version comes from the plugin's .nvmrc so it cannot drift away
# from the toolchain again; npm caching is keyed on the lockfile.
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: "14.x"
node-version-file: connectors/grafana-plugin/.nvmrc
cache: 'npm'
cache-dependency-path: connectors/grafana-plugin/package-lock.json

- name: Setup Go environment
uses: actions/setup-go@v5
with:
go-version: "1.21"

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- name: Install dependencies and Build and test frontend
run: |
cd connectors/grafana-plugin/
npm ci
npm run build

- name: Install dependencies and Build backend
run: |
cd connectors/grafana-plugin/
./backend-compile.sh

# The job above exercises the npm path directly. This one exercises the Maven
# entrypoint (`mvn -Pwith-grafana-plugin`), which drives the same frontend build
# through frontend-maven-plugin. Without it that path is unverified: the module is
# not in the `with-all-connectors` profile that compile-check.yml builds, and the
# Jenkinsfile's bare `mvn clean install` does not activate `with-grafana-plugin`
# either -- so a toolchain change can leave the Maven build broken while every
# check is green.
maven-build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache yarn cache
uses: actions/cache@v4
id: cache-yarn-cache
- name: Setup JDK
uses: actions/setup-java@v4
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
java-version: '17'
distribution: 'temurin'
cache: 'maven'

- name: Setup Go environment
uses: actions/setup-go@v5
with:
path: node_modules
key: ${{ runner.os }}-${{ matrix.node-version }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.node-version }}-nodemodules-
go-version: "1.21"

- name: Install dependencies and Build and test frontend
- name: Build through the Maven entrypoint
run: mvn clean package -Pwith-grafana-plugin -DskipTests -ntp

# plugin.json declares a grafanaDependency floor, but the @grafana/* packages are
# webpack externals resolved from the host at runtime -- so a plugin built against a
# newer Grafana compiles cleanly and then fails inside an older one. This job boots
# the exact version parsed out of grafanaDependency and checks that the plugin loads
# and answers a table-model query there. Changing the declared floor changes what is
# tested; nothing here needs editing.
minimum-grafana-version:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version-file: connectors/grafana-plugin/.nvmrc
cache: 'npm'
cache-dependency-path: connectors/grafana-plugin/package-lock.json

- name: Setup Go environment
uses: actions/setup-go@v5
with:
go-version: "1.21"

- name: Resolve the declared minimum Grafana version
id: floor
run: |
cd connectors/grafana-plugin/
yarn install --frozen-lockfile
yarn build
version=$(node -e "
const dep = require('./src/plugin.json').dependencies.grafanaDependency;
const m = /(\d+\.\d+\.\d+)/.exec(dep);
if (!m) { console.error('cannot parse grafanaDependency: ' + dep); process.exit(1); }
process.stdout.write(m[1]);
")
echo "Declared floor: $version"
echo "version=$version" >> "$GITHUB_OUTPUT"

- name: Install dependencies and Build backend
- name: Build the plugin
run: |
cd connectors/grafana-plugin/
npm ci
npm run build
./backend-compile.sh

- name: Boot Grafana at the declared minimum and wait for both services
env:
GRAFANA_VERSION: ${{ steps.floor.outputs.version }}
GRAFANA_IMAGE: grafana
run: |
cd connectors/grafana-plugin/
docker compose up -d --build
# IoTDB's REST port answers before the native RPC port is ready, so wait on
# Grafana's health endpoint and give the datasource a moment to provision.
for i in $(seq 1 60); do
if curl -sf http://localhost:3000/api/health > /dev/null; then break; fi
sleep 5
done
curl -sf http://localhost:3000/api/health

- name: Run the compatibility smoke test
run: |
cd connectors/grafana-plugin/
npx playwright install --with-deps chromium
npm run e2e -- tests/minimumGrafanaVersion.spec.ts

- name: Dump service logs on failure
if: failure()
run: |
cd connectors/grafana-plugin/
docker compose logs --no-color --tail 200
3 changes: 3 additions & 0 deletions connectors/grafana-plugin/.config/.cprc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "7.9.0"
}
16 changes: 16 additions & 0 deletions connectors/grafana-plugin/.config/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
*
* In order to extend the configuration follow the steps in .config/README.md
*/

module.exports = {
endOfLine: 'auto',
printWidth: 120,
trailingComma: 'es5',
semi: true,
jsxSingleQuote: false,
singleQuote: true,
useTabs: false,
tabWidth: 2,
};
77 changes: 77 additions & 0 deletions connectors/grafana-plugin/.config/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
ARG grafana_version=latest
ARG grafana_image=grafana-enterprise

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

ARG anonymous_auth_enabled=true
ARG development=false
ARG TARGETARCH

ARG GO_VERSION=1.21.6
ARG GO_ARCH=${TARGETARCH:-amd64}

ENV DEV "${development}"

# Make it as simple as possible to access the grafana instance for development purposes
# Do NOT enable these settings in a public facing / production grafana instance
ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin"
ENV GF_AUTH_ANONYMOUS_ENABLED "${anonymous_auth_enabled}"
ENV GF_AUTH_BASIC_ENABLED "false"
# Set development mode so plugins can be loaded without the need to sign
ENV GF_DEFAULT_APP_MODE "development"


LABEL maintainer="Grafana Labs <hello@grafana.com>"

ENV GF_PATHS_HOME="/usr/share/grafana"
WORKDIR $GF_PATHS_HOME

USER root

# Installing supervisor and inotify-tools
RUN if [ "${development}" = "true" ]; then \
if grep -i -q alpine /etc/issue; then \
apk add supervisor inotify-tools git; \
elif grep -i -q ubuntu /etc/issue; then \
DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install -y supervisor inotify-tools git && \
rm -rf /var/lib/apt/lists/*; \
else \
echo 'ERROR: Unsupported base image' && /bin/false; \
fi \
fi

COPY supervisord/supervisord.conf /etc/supervisor.d/supervisord.ini
COPY supervisord/supervisord.conf /etc/supervisor/conf.d/supervisord.conf


# Installing Go
RUN if [ "${development}" = "true" ]; then \
curl -O -L https://golang.org/dl/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \
rm -rf /usr/local/go && \
tar -C /usr/local -xzf go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \
echo "export PATH=$PATH:/usr/local/go/bin:~/go/bin" >> ~/.bashrc && \
rm -f go${GO_VERSION}.linux-${GO_ARCH}.tar.gz; \
fi

# Installing delve for debugging
RUN if [ "${development}" = "true" ]; then \
/usr/local/go/bin/go install github.com/go-delve/delve/cmd/dlv@latest; \
fi

# Installing mage for plugin (re)building
RUN if [ "${development}" = "true" ]; then \
git clone https://github.com/magefile/mage; \
cd mage; \
export PATH=$PATH:/usr/local/go/bin; \
go run bootstrap.go; \
fi

# Inject livereload script into grafana index.html
RUN sed -i 's|</body>|<script src="http://localhost:35729/livereload.js"></script></body>|g' /usr/share/grafana/public/views/index.html


COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
Loading