|
| 1 | +#! /bin/bash |
| 2 | + |
| 3 | +# This creates a deploy-able plugin zip file in the release directory. |
| 4 | +# |
| 5 | +# Installation instructions: |
| 6 | +# 1. Determine the Grafana server URL. This may not be the public URL, and are defined in the `server` section |
| 7 | +# of the Settings page or grafana.ini file. For example, the server URL may be http://localhost:3000. |
| 8 | +# 2. Run this script with the server URL. |
| 9 | +# 3. Copy the zip file to the machine hosting grafana and unzip into the grafana plugins directory |
| 10 | +# (/var/lib/grafana/plugins on linux). |
| 11 | +# 4. Restart grafana. |
| 12 | + |
| 13 | +set -eo pipefail |
| 14 | + |
| 15 | +usage() { |
| 16 | +cat << EOF |
| 17 | +Usage: $0 -u [root_urls] -k [api_key] |
| 18 | +
|
| 19 | +Packages the project as a "private" plugin so it may be used on a grafana server. |
| 20 | +The end result is a zip file in the 'release' directory containing the plugin. |
| 21 | +
|
| 22 | +Unfortunately, only NeedleInAJayStack can run this since the API key cloud account must match the datasource name. |
| 23 | +This is a workaround until the package is approved as a "public" plugin by Grafana. |
| 24 | +
|
| 25 | +-u root_urls: Comma separated list of root urls for the grafana server. |
| 26 | +-k api_key: API key for the grafana server. |
| 27 | +EOF |
| 28 | +exit 1 |
| 29 | +} |
| 30 | + |
| 31 | +# This follows the gitlab release.yml file. |
| 32 | +main() { |
| 33 | + export GRAFANA_API_KEY=${api_key} |
| 34 | + |
| 35 | + # Install dependencies |
| 36 | + yarn install --immutable --prefer-offline |
| 37 | + |
| 38 | + # Build and test frontend |
| 39 | + yarn build |
| 40 | + |
| 41 | + # Test backend |
| 42 | + mage coverage |
| 43 | + |
| 44 | + # Build backend |
| 45 | + mage buildAll |
| 46 | + |
| 47 | + # Sign plugin |
| 48 | + npx --yes @grafana/sign-plugin --rootUrls ${rootUrls} |
| 49 | + |
| 50 | + # Get plugin metadata |
| 51 | + plugin_id=$(cat dist/plugin.json | jq -r .id) |
| 52 | + archive=${plugin_id}.zip |
| 53 | + |
| 54 | + # Package plugin |
| 55 | + mv -f dist ${plugin_id} |
| 56 | + |
| 57 | + if [ ! -d "release" ]; then |
| 58 | + mkdir release |
| 59 | + fi |
| 60 | + zip release/${archive} ${plugin_id} -r |
| 61 | + |
| 62 | + # Cleanup |
| 63 | + rm -r ${plugin_id} |
| 64 | +} |
| 65 | + |
| 66 | +while getopts ":k:u:" option; do |
| 67 | + case "$option" in |
| 68 | + k) |
| 69 | + readonly api_key=${OPTARG} |
| 70 | + ;; |
| 71 | + u) |
| 72 | + readonly rootUrls=${OPTARG} |
| 73 | + ;; |
| 74 | + *) |
| 75 | + usage |
| 76 | + ;; |
| 77 | + esac |
| 78 | +done |
| 79 | + |
| 80 | +if [ -z "${rootUrls}" ] || [ -z "${api_key}" ]; then |
| 81 | + usage |
| 82 | +fi |
| 83 | + |
| 84 | +main |
0 commit comments