From 7df5b6ef33b9ef7a26d965c87024c2e1ad684674 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Fri, 14 Apr 2023 10:10:25 -0600 Subject: [PATCH] add script to download and extract latest grafana flight sql plugin (#4866) --- .../cloud-iox/query-data/tools/grafana.md | 47 ++++++++++++------- deploy/edge.js | 1 + layouts/shortcodes/readfile.html | 1 + .../download-grafana-flightsql-plugin.sh | 28 +++++++++++ 4 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 layouts/shortcodes/readfile.html create mode 100644 static/downloads/download-grafana-flightsql-plugin.sh diff --git a/content/influxdb/cloud-iox/query-data/tools/grafana.md b/content/influxdb/cloud-iox/query-data/tools/grafana.md index 01f9fb6e4..ba7b297de 100644 --- a/content/influxdb/cloud-iox/query-data/tools/grafana.md +++ b/content/influxdb/cloud-iox/query-data/tools/grafana.md @@ -51,31 +51,46 @@ Because Grafana Flight SQL Plugin is a custom plugin, you can't use it with Graf For more information, see [Find and Use Plugins in the Grafana Cloud documentation](https://grafana.com/docs/grafana-cloud/fundamentals/find-and-use-plugins/) {{% /warn %}} +## Create a custom plugins director + +Create a **custom plugins directory** to store the Flight SQL plugin in and +navigate into the directory. +_The custom plugins directory can be anywhere in your filesystem that Grafana can access._ + +{{% code-callout "/custom/plugins/directory" %}} +```sh +mkdir -p /custom/plugins/directory/ && cd $_ +``` +{{% /code-callout %}} + ## Download the Grafana Flight SQL plugin -Download the latest release from [influxdata/grafana-flightsql-datasource releases](https://github.com/influxdata/grafana-flightsql-datasource/releases). +Download the latest [Grafana Flight SQL plugin (influxdata/grafana-flightsql-datasource)](https://github.com/influxdata/grafana-flightsql-datasource/releases). + +The following shell script downloads and extracts the latest Flight SQL plugin +source code into the the current working directory. +**Run the following inside your [custom plugin directory](#create-a-custom-plugins-directory):** + +```sh +curl -s https://docs.influxdata.com/downloads/download-grafana-flightsql-plugin.sh | bash +``` + +{{< expand-wrapper >}} +{{% expand "View the script source code" %}} + +```sh +{{% readfile "/static/downloads/download-grafana-flightsql-plugin.sh" %}} +``` + +{{% /expand %}} +{{< /expand-wrapper >}} {{% warn %}} The Grafana Flight SQL plugin is experimental and subject to change. {{% /warn %}} -```sh -curl -L https://github.com/influxdata/grafana-flightsql-datasource/releases/download/v0.1.9/influxdata-flightsql-datasource-0.1.9.zip --output influxdata-flightsql-datasource.zip -``` - -## Extract the Flight SQL plugin - -Extract the Flight SQL plugin archive to your Grafana **custom plugins directory**. -The custom plugins directory can be any filesystem location that Grafana can access. - -{{% code-callout "/custom/plugins/directory" %}} -```sh -unzip influxdata-flightsql-datasource.zip -d /custom/plugins/directory/ -``` -{{% /code-callout %}} - ## Install the Grafana Flight SQL plugin Install the custom-built Flight SQL plugin in a local or Docker-based instance diff --git a/deploy/edge.js b/deploy/edge.js index 04679aef6..83edf6aad 100644 --- a/deploy/edge.js +++ b/deploy/edge.js @@ -79,6 +79,7 @@ exports.handler = (event, context, callback) => { '.zip': true, '.md5': true, '.sha256': true, + '.sh':true, }; // Remove index.html from path diff --git a/layouts/shortcodes/readfile.html b/layouts/shortcodes/readfile.html new file mode 100644 index 000000000..e6e2b472a --- /dev/null +++ b/layouts/shortcodes/readfile.html @@ -0,0 +1 @@ +{{ readFile (.Get 0) | safeHTML }} \ No newline at end of file diff --git a/static/downloads/download-grafana-flightsql-plugin.sh b/static/downloads/download-grafana-flightsql-plugin.sh new file mode 100644 index 000000000..f13176479 --- /dev/null +++ b/static/downloads/download-grafana-flightsql-plugin.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Set repository information +REPO_OWNER="influxdata" +REPO_NAME="grafana-flightsql-datasource" +API_URL="https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases" + +# Fetch all release information +ALL_RELEASES=$(curl -s $API_URL) + +# Check if a valid release list is found +if [[ $ALL_RELEASES == *"Not Found"* ]]; then + echo "Releases not found for the $REPO_NAME repository." + exit 1 +fi + +# Extract the latest pre-release tag from the release information +LATEST_RELEASE_TAG=$(echo "$ALL_RELEASES" | grep -Eo '"tag_name": "[^"]*' | sed -E 's/"tag_name": "//' | head -n 1) +VERSION=$(echo "$LATEST_RELEASE_TAG" | sed 's/^v//') +if [[ -z "$LATEST_RELEASE_TAG" ]]; then + echo "No pre-release found for the $REPO_NAME repository." + exit 1 +fi + +echo "The latest release tag of $REPO_NAME is: $LATEST_RELEASE_TAG" + +curl -L https://github.com/influxdata/grafana-flightsql-datasource/releases/download/$LATEST_RELEASE_TAG/influxdata-flightsql-datasource-$VERSION.zip --output influxdata-flightsql-datasource.zip +unzip influxdata-flightsql-datasource.zip -d . \ No newline at end of file