mirror of
https://github.com/grafana/grafana.git
synced 2026-06-10 17:11:31 -04:00
* Docs: Document the folderless Git Sync target Adds a "Sync targets" section to the Git Sync key concepts page describing the `folder` and `folderless` targets, and updates the code-based setup page to document `target: folderless` alongside `target: folder`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Docs: Add folder vs folderless examples to Git Sync key concepts Focus the Sync targets section on the folder and folderless modes and add worked examples showing how the same repository files map to the Dashboards view under each target. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Docs: Refine folderless sync target examples in key concepts Describe the folder and folderless sync modes conceptually instead of by the spec.sync.target field (the field stays documented in the setup page), show unprovisioned content alongside synced resources in the examples, and add a multiple-folderless example. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Update docs/sources/as-code/observability-as-code/git-sync/key-concepts.md Co-authored-by: Anna Urbiztondo <anna.urbiztondo@grafana.com> * Update docs/sources/as-code/observability-as-code/git-sync/key-concepts.md Co-authored-by: Anna Urbiztondo <anna.urbiztondo@grafana.com> * Docs: Move sync target when-to-use guidance to top of section Address review feedback: surface when to use folder vs folderless sync up front, before the worked examples, since that's what readers want to know first. Remove the now-redundant trailing paragraph. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Anna Urbiztondo <anna.urbiztondo@grafana.com>
249 lines
9.1 KiB
Markdown
249 lines
9.1 KiB
Markdown
---
|
|
description: Instructions for setting up Git Sync as code, so you can provision Git repositories for use with Grafana.
|
|
keywords:
|
|
- set up
|
|
- git integration
|
|
- git sync
|
|
- github
|
|
- as code
|
|
labels:
|
|
products:
|
|
- enterprise
|
|
- oss
|
|
- cloud
|
|
title: Set up Git Sync as code
|
|
weight: 200
|
|
canonical: https://grafana.com/docs/grafana/latest/as-code/observability-as-code/git-sync/git-sync-setup/set-up-code
|
|
aliases:
|
|
- ../../../observability-as-code/provision-resources/git-sync-setup/ # /docs/grafana/next/observability-as-code/provision-resources/git-sync-setup/
|
|
- ../provision-resources/git-sync-setup/ # /docs/grafana/next/observability-as-code/provision-resources/git-sync-setup/
|
|
---
|
|
|
|
# Set up Git Sync as code
|
|
|
|
{{< admonition type="note" >}}
|
|
|
|
**Git Sync is now GA for Grafana Cloud, OSS and Enterprise.** Refer to [Usage and performance limitations](https://grafana.com/docs/grafana/<GRAFANA_VERSION>/as-code/observability-as-code/git-sync/usage-limits) to understand usage limits for the different tiers.
|
|
|
|
[Contact Grafana](https://grafana.com/help/) for support or to report any issues you encounter and help us improve this feature.
|
|
|
|
{{< /admonition >}}
|
|
|
|
You can also configure Git Sync using `gcx`, the Grafana CLI. Since Git Sync configuration is managed as code using Custom Resource Definitions (CRDs), you can create your required resources in YAML files and push them to Grafana using `gcx`. This approach enables automated, GitOps-style workflows for managing Git Sync configuration instead of using the Grafana UI.
|
|
|
|
For more information, refer to the following documents:
|
|
|
|
- [Repository resource](https://grafana.com/docs/grafana/<GRAFANA_VERSION>/as-code/observability-as-code/git-sync/key-concepts#git-sync-repository-resource) and [Connection resource](https://grafana.com/docs/grafana/<GRAFANA_VERSION>/as-code/observability-as-code/git-sync/key-concepts#git-sync-repository-resource) overview
|
|
- [Dashboard CRD Format](https://grafana.com/docs/grafana/<GRAFANA_VERSION>/as-code/observability-as-code/git-sync/export-resources/)
|
|
- [Grafana CLI documentation](https://grafana.com/docs/grafana/<GRAFANA_VERSION>/as-code/observability-as-code/grafana-cli/)
|
|
|
|
## Set up Git Sync as code with the Grafana CLI
|
|
|
|
To set up Git Sync as code with `gcx`, follow these steps:
|
|
|
|
1. Understand [Usage and performance limitations](https://grafana.com/docs/grafana/<GRAFANA_VERSION>/as-code/observability-as-code/git-sync/usage-limits)
|
|
1. [Create the connection and repository CRDs](#create-the-resources-crds)
|
|
1. [Push the CRDs to Grafana](#push-the-resources-to-grafana)
|
|
1. [Manage repository resources](#manage-repository-resources)
|
|
1. [Verify setup](#verify-setup)
|
|
|
|
## Create the resources CRDs
|
|
|
|
If you're connecting with any of the [supported Git providers](https://grafana.com/docs/grafana/<GRAFANA_VERSION>/as-code/observability-as-code/git-sync/usage-limits#compatible-git-providers) using a Personal Access Token, you need to create a repository resource to define the connection between your repositories and your Grafana instance.
|
|
|
|
If you're connecting to Git Sync with GitHub App, in addition to the repository resource you need to create a connection resource as well.
|
|
|
|
### Create the connection resource
|
|
|
|
If you're connecting Git Sync with GitHub App, create a `connection.yaml` file defining your Git Sync connection configuration:
|
|
|
|
```yaml
|
|
apiVersion: provisioning.grafana.app/v0alpha1
|
|
kind: Connection
|
|
metadata:
|
|
name: '<GITHUB_CONNECTION_NAME>'
|
|
namespace: default
|
|
spec:
|
|
title: '<REPOSITORY_TITLE>'
|
|
type: github
|
|
url: https://github.com
|
|
github:
|
|
appID: '<GITHUB_APP_ID>'
|
|
installationID: '<GITHUB_INSTALL_ID>'
|
|
secure:
|
|
privateKey:
|
|
create: '<GITHUB_PRIVATE_KEY>'
|
|
```
|
|
|
|
Replace the placeholders with your values:
|
|
|
|
- _`<GITHUB_CONNECTION_NAME>`_: The name of your GitHub connection
|
|
- _`<REPOSITORY_TITLE>`_: Human-readable name displayed in Grafana UI
|
|
- _`<GITHUB_APP_ID>`_: GitHub App unique identifier
|
|
- _`<GITHUB_INSTALL_ID>`_: GitHub App installation id
|
|
- _`<GITHUB_PRIVATE_KEY>`_: GitHub Private Key
|
|
|
|
### Create the repository resource
|
|
|
|
Next, create a `repository.yaml` file defining your Git Sync configuration. Depending on your Git provider and authentication method, add your Personal Access Token information or the connection name.
|
|
|
|
```yaml
|
|
apiVersion: provisioning.grafana.app/v0alpha1
|
|
kind: Repository
|
|
metadata:
|
|
name: '<REPOSITORY_NAME>'
|
|
spec:
|
|
sync:
|
|
enabled: true
|
|
intervalSeconds: 60
|
|
target: folder
|
|
workflows:
|
|
- write
|
|
- branch
|
|
title: '<REPOSITORY_TITLE>'
|
|
|
|
# Git Sync for GitHub:
|
|
spec:
|
|
type: github
|
|
github:
|
|
url: '<GIT_REPO_URL>'
|
|
branch: '<BRANCH>'
|
|
path: grafana/
|
|
# GitHub App connection only:
|
|
connection:
|
|
name: '<GITHUB_CONNECTION_NAME>'
|
|
# GitHub Personal Access Token only:
|
|
secure:
|
|
token: { create: "GIT_PAT" }
|
|
|
|
# GitLab Personal Access Token only:
|
|
spec:
|
|
type: gitlab
|
|
gitlab:
|
|
url: '<GIT_REPO_URL>'
|
|
branch: '<BRANCH>'
|
|
secure:
|
|
token: { create: "GIT_PAT" }
|
|
|
|
# Bitbucket Personal Access Token only:
|
|
spec:
|
|
type: bitbucket
|
|
bitbucket:
|
|
url: '<GIT_REPO_URL>'
|
|
branch: '<BRANCH>'
|
|
tokenUser: tokenuser
|
|
secure:
|
|
token: { create: "GIT_PAT" }
|
|
|
|
# Pure Git only:
|
|
spec:
|
|
type: git
|
|
git:
|
|
url: '<GIT_REPO_URL>'
|
|
branch: '<BRANCH>'
|
|
path: "grafana/"
|
|
tokenUser: tokenuser
|
|
secure:
|
|
token: { create: "GIT_PAT" }
|
|
```
|
|
|
|
Replace the placeholders with your values:
|
|
|
|
- _`<REPOSITORY_NAME>`_: Unique identifier for this repository resource
|
|
- _`<REPOSITORY_TITLE>`_: Human-readable name displayed in Grafana UI
|
|
- _`<GIT_REPO_URL>`_: GitHub repository URL
|
|
- _`<BRANCH>`_: Branch to sync
|
|
- _`<GITHUB_CONNECTION_NAME>`_: The name of your GitHub connection
|
|
- _`<GIT_PAT>`_: Git provider Personal Access Token
|
|
|
|
{{< admonition type="note" >}}
|
|
|
|
Git Sync supports two sync targets: `target: folder` (the default) creates a folder named after the repository and places synced resources inside it, while `target: folderless` places synced resources at the top level without creating a wrapper folder. Refer to [Sync targets](https://grafana.com/docs/grafana/<GRAFANA_VERSION>/as-code/observability-as-code/git-sync/key-concepts/#sync-targets) for details.
|
|
|
|
{{< /admonition >}}
|
|
|
|
### Configuration parameters
|
|
|
|
The following configuration parameters are available:
|
|
|
|
| Field | Description |
|
|
| --------------------------------------- | ----------------------------------------------------------- |
|
|
| `metadata.name` | Unique identifier for this repository resource |
|
|
| `spec.title` | Human-readable name displayed in Grafana UI |
|
|
| `spec.type` | Repository type (`github`) |
|
|
| `spec.github.url` | GitHub repository URL |
|
|
| `spec.github.branch` | Branch to sync |
|
|
| `spec.github.path` | Directory path containing dashboards |
|
|
| `spec.github.generateDashboardPreviews` | Generate preview images (true/false) |
|
|
| `spec.sync.enabled` | Enable synchronization (true/false) |
|
|
| `spec.sync.intervalSeconds` | Sync interval in seconds |
|
|
| `spec.sync.target` | Where to place synced dashboards (`folder` or `folderless`) |
|
|
| `spec.workflows` | Enabled workflows: `write` (direct commits), `branch` (PRs) |
|
|
| `secure.token.create` | GitHub Personal Access Token |
|
|
|
|
## Push the resources to Grafana
|
|
|
|
Before pushing any resources, configure `gcx` with your Grafana instance details. Refer to the [Grafana CLI documentation](https://grafana.com/docs/grafana/<GRAFANA_VERSION>/as-code/observability-as-code/grafana-cli/) for setup instructions.
|
|
|
|
Push the repository configuration. If you're using GitHub App to connect Git Sync, push the connection resource configuration file as well.
|
|
|
|
```sh
|
|
gcx resources push --path <DIRECTORY>
|
|
```
|
|
|
|
The `--path` parameter has to point to the directory containing your `repository.yaml` and `connection.yaml` files.
|
|
|
|
After pushing, Grafana will:
|
|
|
|
1. Create the required resources (repository and, for GitHub App, connection)
|
|
1. Connect to your GitHub repository
|
|
1. Pull dashboards from the specified path
|
|
1. Begin syncing at the configured interval
|
|
|
|
## Manage repository resources
|
|
|
|
### List repositories
|
|
|
|
To list all repositories:
|
|
|
|
```sh
|
|
gcx resources get repositories
|
|
```
|
|
|
|
### Get repository details
|
|
|
|
To get details for a specific repository:
|
|
|
|
```sh
|
|
gcx resources get repository/<REPOSITORY_NAME>
|
|
gcx resources get repository/<REPOSITORY_NAME> -o json
|
|
gcx resources get repository/<REPOSITORY_NAME> -o yaml
|
|
```
|
|
|
|
### Update the repository
|
|
|
|
To update a repository:
|
|
|
|
```sh
|
|
gcx resources edit repository/<REPOSITORY_NAME>
|
|
```
|
|
|
|
### Delete the repository
|
|
|
|
To delete a repository:
|
|
|
|
```sh
|
|
gcx resources delete repository/<REPOSITORY_NAME>
|
|
```
|
|
|
|
## Verify setup
|
|
|
|
Check that Git Sync is working:
|
|
|
|
```sh
|
|
# List repositories
|
|
gcx resources get repositories
|
|
|
|
# Check Grafana UI
|
|
# Navigate to: Administration → Provisioning → Git Sync
|
|
```
|