{"id":18429721,"url":"https://github.com/joanlopez/grafonnet-example","last_synced_at":"2025-04-07T17:33:15.162Z","repository":{"id":182545716,"uuid":"668678119","full_name":"joanlopez/grafonnet-example","owner":"joanlopez","description":"Example repository with a Grafana dashboard defined with Grafonnet and deployed with Grizzly","archived":false,"fork":false,"pushed_at":"2024-03-18T14:15:15.000Z","size":405,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-22T22:02:16.440Z","etag":null,"topics":["as-code","continuous-deployment","grafana","grafonnet","grizzly"],"latest_commit_sha":null,"homepage":"https://github.com/joanlopez/grafonnet-example","language":"Jsonnet","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joanlopez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-07-20T10:59:54.000Z","updated_at":"2025-02-03T15:57:00.000Z","dependencies_parsed_at":"2023-07-26T01:16:00.057Z","dependency_job_id":null,"html_url":"https://github.com/joanlopez/grafonnet-example","commit_stats":null,"previous_names":["joanlopez/grafonnet-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joanlopez%2Fgrafonnet-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joanlopez%2Fgrafonnet-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joanlopez%2Fgrafonnet-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joanlopez%2Fgrafonnet-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joanlopez","download_url":"https://codeload.github.com/joanlopez/grafonnet-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247698022,"owners_count":20981288,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["as-code","continuous-deployment","grafana","grafonnet","grizzly"],"created_at":"2024-11-06T05:18:27.765Z","updated_at":"2025-04-07T17:33:14.539Z","avatar_url":"https://github.com/joanlopez.png","language":"Jsonnet","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Grafonnet example\n\nThis repository contains an example of a [Grafana dashboard](https://grafana.com/docs/grafana/latest/dashboards/)\n[as code](https://grafana.com/blog/2022/12/06/a-complete-guide-to-managing-grafana-as-code-tools-tips-and-tricks/), \ndefined with [Grafonnet](https://github.com/grafana/grafonnet), continuously deployed to \na [Grafana Cloud](https://grafana.com/products/cloud/) instance, \nthanks to [Grizzly](https://github.com/grafana/grizzly) and [GitHub Actions](https://docs.github.com/en/actions).\n\n## What's here?\n\n- An **[example dashboard](./example.jsonnet)** written in [Jsonnet](https://jsonnet.org/) with [Grafonnet](https://github.com/grafana/grafonnet).\n  - Are you willing to extend it? Find [here](https://grafana.github.io/grafonnet/API/dashboard/index.html) the Grafonnet API for dashboards.\n- An example of how to **[use Grizzle to push dashboards to a Grafana instance](./.github/workflows/deploy.yml#L20)**.\n  - Would you like to learn more about Grizzly? Find [here](https://grafana.github.io/grizzly/) the docs.\n- An example of how to **[continuously deploy Grafonnet code to a Grafana instance](./.github/workflows/deploy.yml)** with GitHub Actions.\n\n## Looking for building your own example?\n\n**If you're a [learning-by-doing](https://en.wikipedia.org/wiki/Learning-by-doing) kind of person,** you can follow the steps below to build your own example.\n\n### Pre-requisites\n\nFirst of all, you need to have these tools up and running before starting:\n\n  - [Jsonnet](https://jsonnet.org/) (*[go-jsonnet](https://github.com/google/go-jsonnet#installation-instructions)* flavor)\n  - [jsonnet-bundler](https://github.com/jsonnet-bundler/jsonnet-bundler#install)\n  - [Grafana Cloud](https://grafana.com/products/cloud/) instance (*with a [service account token](https://grafana.com/docs/grafana/latest/administration/service-accounts/#service-account-tokens) with enough permissions - e.g. admin*)\n\n### Step by step\n\n1. **Initialize** a new project:\n\n    ```sh\n    jb init\n    ```\n\n2. **Add Grafonnet** as dependency:\n\n    ```sh\n    jb install github.com/grafana/grafonnet/gen/grafonnet-latest@main\n    ```\n\n3. **Create an `example.jsonnet` file** with a basic dashboard:\n\n    ```jsonnet\n    local g = import 'github.com/grafana/grafonnet/gen/grafonnet-latest/main.libsonnet';\n    \n    g.dashboard.new('Grafonnet example')\n    + g.dashboard.withDescription('Example dashboard built with Grafonnet')\n    ```\n\n4. **Create a `dashboards.libsonnet` file** with the main definition:\n\n    ```jsonnet\n    {\n      grafanaDashboards+:: {\n        'example.json': (import 'example.jsonnet'),\n      },\n    }\n    ```\n\n    *NOTE: It basically imports the example dashboard we defined in the previous step*\n\n5. **Set up [Grafana auth for Grizzly](https://grafana.github.io/grizzly/authentication/#grafana-itself)** as [Actions secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets):\n\n    - `GRAFANA_URL` with the root url of your instance\n    - `GRAFANA_TOKEN` with your service account token\n\n6. **Set up GitHub Actions** to automatically `grr apply` your changes on every push to `main`:\n\n    ```yaml\n    # .github/workflows/deploy.yml\n\n    name: deploy\n    \n    on:\n      push:\n        branches:\n          - main\n    \n    jobs:\n      deploy:\n        runs-on: ubuntu-latest\n        container:\n          image: grafana/grizzly:0.2.1-amd64\n          env:\n            GRAFANA_URL: ${{ secrets.GRAFANA_URL }}\n            GRAFANA_TOKEN: ${{ secrets.GRAFANA_TOKEN }}\n        steps:\n          - name: Check out code\n            uses: actions/checkout@v3\n          - name: Deploy dashboards\n            run: grr apply dashboards.libsonnet -l debug\n    ```\n\n7. **Push** new changes on `example.jsonnet` to `main` and **enjoy**!\n\n## Contribute\n\nHave you detected a typo or something incorrect, and you are **willing to contribute?** \n\nPlease, [open a pull request](https://github.com/joanlopez/grafonnet-example/compare), and I'll be happy to review it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoanlopez%2Fgrafonnet-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoanlopez%2Fgrafonnet-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoanlopez%2Fgrafonnet-example/lists"}