Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: Docker Build and Test
name: Build, Test, and Deploy

on:
push:
paths:
- 'grafana/**'
- '.github/workflows/workflow.yml'
- "grafana/**"
- ".github/workflows/workflow.yml"
pull_request:
paths:
- 'grafana/**'
- '.github/workflows/workflow.yml'
- "grafana/**"
- ".github/workflows/workflow.yml"

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand Down Expand Up @@ -49,3 +49,17 @@ jobs:
run: |
cd grafana
docker compose down -v

deploy:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/main'

steps:
- uses: actions/checkout@v4

- name: Deploy dashboards to Grafana Cloud
env:
GRAFANA_URL: https://softwarecsc65.grafana.net
GRAFANA_TOKEN: ${{ secrets.GRAFANA_SERVICE_ACCOUNT_TOKEN }}
run: bash grafana/scripts/deploy.sh
7 changes: 5 additions & 2 deletions grafana/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
MQTT_PASSWORD=yourpassword
MQTT_USERNAME=yourusername
MQTT_PASSWORD=yourpassword
MQTT_HOST=yourhost

POSTGRES_USERNAME=yourusername
POSTGRES_PASSWORD=yourpassword
POSTGRES_HOST=yourhost
POSTGRES_HOST=yourhost
POSTGRES_SSLMODE=disable
60 changes: 60 additions & 0 deletions grafana/DASHBOARD_WORKFLOW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Dashboard Update Workflow

Edit dashboards locally, commit to git, and let CI/CD deploy to Grafana Cloud.
Never edit dashboards directly in Grafana Cloud.

## Steps

### 1. Start local Grafana

```bash
cd grafana
docker compose up -d
```

Open http://localhost:3000 (admin / admin).

### 2. Edit the dashboard locally

Make your changes in local Grafana as usual.

### 3. Export the dashboard JSON

Save the dashboard in Grafana first (Ctrl+S), then export — this ensures the
exported JSON reflects your latest changes.

1. Open the dashboard in local Grafana
2. Click the **Share icon** (top right)
3. Select the **Export** tab
4. Click **Copy to clipboard**

### 4. Replace the file in git

Open the corresponding file in `grafana/dashboards/` and paste the clipboard
content, replacing the entire file contents. The filename should stay the same.

### 5. Commit and push

CI/CD runs on merge to `main` and deploys to Grafana Cloud automatically.

---

## What CI/CD does

The deploy job in `.github/workflows/workflow.yml`:

1. Fetches all datasources from Grafana Cloud
2. Strips `__inputs`, `__requires`, and `__elements` from the dashboard JSON (safe to include or omit in the exported file)
3. Walks the entire dashboard JSON and rewrites every datasource `uid` by matching on `type` against the Cloud datasources
4. POSTs the remapped dashboard to `POST /api/dashboards/db`

---

## Common mistakes

| Mistake | Result |
| -------------------------------------------- | ------------------------------------------------------------ |
| Using "Share externally" instead of "Export" | Creates a public URL link — not what you want |
| Editing dashboard directly in Grafana Cloud | Changes get overwritten on next CI/CD deploy, no git history |

---
Loading
Loading