Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bitnami/grafana] feat: handle space separated GF_INSTALL_PLUGINS #51889

Merged
merged 2 commits into from
Oct 25, 2023

Conversation

portswigger-tim
Copy link
Contributor

@portswigger-tim portswigger-tim commented Oct 16, 2023

Description of the change

Brings GF_INSTALL_PLUGINS handling inline with documented usage

Extract from: https://grafana.com/docs/grafana/latest/setup-grafana/installation/docker/

Note: If you want to specify the version of a plugin, add the version number to the GF_INSTALL_PLUGINS environment variable. For example: -e "GF_INSTALL_PLUGINS=grafana-clock-panel 1.0.1,grafana-simple-json-datasource 1.3.5". If you do not specify a version number, the latest version is used.

Benefits

Currently, the Bitnami Grafana image doesn't handle plugins installed via Dashboard or Datasource resources handled by the grafana-operator. This fixes that problem which is also mentioned in issue: grafana/grafana-operator#1269

Possible drawbacks

Space-separated GF_INSTALL_PLUGINS will no longer work.

Applicable issues

Additional information

I have tested this change with several different specifications of plugins:

sh-3.2$ export GF_INSTALL_PLUGINS="something 1.1.2,another 1.1.3,grafana-clock-panel:1.1.0,grafana-kubernetes-app,worldpring=https://github.com/raintank/worldping-app/releases/download/v1.2.6/worldping-app-release-1.2.6.zip"
sh-3.2$
sh-3.2$ grafana_plugin_test() {
>     [[ -z "$GF_INSTALL_PLUGINS" ]] && return
>
>     local -a plugin_list
>     IFS="," read -r -a plugin_list <<< "$(tr ';' ',' <<< "${GF_INSTALL_PLUGINS}")"
>     if [[ "${#plugin_list[@]}" -le 0 ]]; then
>         warn "There are no plugins to install"
>         return
>     fi
>
>     local plugin_id plugin_version
>     local -a grafana_plugin_install_args
>     local -a plugin_url_array
>     local -a plugin_id_version_array
>     for plugin in "${plugin_list[@]}"; do
>         plugin_id="$plugin"
>         plugin_version=""
>         grafana_plugin_install_args=("--pluginsDir" "/dummy")
>         if grep -q '=' <<< "$plugin"; then
>             read -r -a plugin_url_array <<< "$(tr '=' ' ' <<< "${plugin}")"
>             echo "Installing plugin ${plugin_url_array[0]} from URL ${plugin_url_array[1]}"
>             plugin_id="${plugin_url_array[0]}"
>             grafana_plugin_install_args+=("--pluginUrl" "${plugin_url_array[1]}")
>         elif grep ':' <<< "$plugin"; then
>             read -r -a plugin_id_version_array <<< "$(tr ':' ' ' <<< "${plugin}")"
>             plugin_id="${plugin_id_version_array[0]}"
>             plugin_version="${plugin_id_version_array[1]}"
>             echo "Installing plugin ${plugin_id} @ ${plugin_version}"
>         elif grep ' ' <<< "$plugin"; then
>             read -r -a plugin_id_version_array <<< $plugin
>             plugin_id="${plugin_id_version_array[0]}"
>             plugin_version="${plugin_id_version_array[1]}"
>             echo "Installing plugin ${plugin_id} @ ${plugin_version}"
>         else
>             echo "Installing plugin ${plugin_id}"
>         fi
>
>         grafana_plugin_install_args+=("plugins" "install" "${plugin_id}")
>         if [[ -n "$plugin_version" ]]; then
>             grafana_plugin_install_args+=("$plugin_version")
>         fi
>         echo "Would execute: grafana-cli ${grafana_plugin_install_args[@]}"
>         echo "---"
>     done
> }
sh-3.2$
sh-3.2$ grafana_plugin_test
something 1.1.2
Installing plugin something @ 1.1.2
Would execute: grafana-cli --pluginsDir /dummy plugins install something 1.1.2
---
another 1.1.3
Installing plugin another @ 1.1.3
Would execute: grafana-cli --pluginsDir /dummy plugins install another 1.1.3
---
grafana-clock-panel:1.1.0
Installing plugin grafana-clock-panel @ 1.1.0
Would execute: grafana-cli --pluginsDir /dummy plugins install grafana-clock-panel 1.1.0
---
Installing plugin grafana-kubernetes-app
Would execute: grafana-cli --pluginsDir /dummy plugins install grafana-kubernetes-app
---
Installing plugin worldpring from URL https://github.com/raintank/worldping-app/releases/download/v1.2.6/worldping-app-release-1.2.6.zip
Would execute: grafana-cli --pluginsDir /dummy --pluginUrl https://github.com/raintank/worldping-app/releases/download/v1.2.6/worldping-app-release-1.2.6.zip plugins install worldpring

@github-actions github-actions bot added the triage Triage is needed label Oct 16, 2023
@bitnami-bot bitnami-bot requested a review from carrodher October 16, 2023 10:04
@portswigger-tim portswigger-tim changed the title feat: handle space separated GF_INSTALL_PLUGINS [bitnami/grafana] feat: handle space separated GF_INSTALL_PLUGINS Oct 16, 2023
@carrodher carrodher added the verify Execute verification workflow for these changes label Oct 16, 2023
@github-actions github-actions bot added in-progress and removed triage Triage is needed labels Oct 16, 2023
@bitnami-bot bitnami-bot removed the request for review from carrodher October 16, 2023 18:45
@bitnami-bot bitnami-bot requested a review from migruiz4 October 16, 2023 18:45
Signed-off-by: Miguel Ruiz <[email protected]>

Signed-off-by: Miguel Ruiz <[email protected]>
Copy link
Member

@migruiz4 migruiz4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your contribution @portswigger-tim!

Changes look good to me, but I had to apply a small linting fix before merging it.
Once merged, a new release of the bitnami/grafana image including this feature should be released soon.

@migruiz4 migruiz4 merged commit 1ef9097 into bitnami:main Oct 25, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
grafana solved verify Execute verification workflow for these changes
Projects
None yet
3 participants