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

Add CI step to publish image to GAR #20

Merged
merged 4 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
34 changes: 34 additions & 0 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI
on:
push:
branches:
- main

# These permissions are needed to assume roles from Github's OIDC.
permissions:
contents: read
id-token: write

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Image tag
id: image-tag
run: echo "version=$(./image-tag)" >> $GITHUB_OUTPUT

- name: Build and push to GAR
uses: grafana/shared-workflows/actions/push-to-gar-docker@main
id: push-to-gar
with:
platforms: linux/amd64,linux/arm64
file: ./Dockerfile
tags: |
"${{ steps.image-tag.outputs.version }}"
"latest"
image_name: "mcp-grafana"
environment: "dev"
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: build-image
build-image:
docker build -t mcp-grafana:latest .
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ To run the server, use:
uvx --from . mcp-grafana
```

You can also run the server using docker. To build the image, use

```
make build-image
```

And to run the image, use:

```
docker run -it --rm mcp-grafana:latest --port-forward 8000:8000
```

### Testing

TL;DR: start a Grafana instance with `docker-compose up`, run `uv run ruff check .` for lints, and `uv run pytest tests --integration` to run unit and integration tests.
Expand Down
21 changes: 21 additions & 0 deletions image-tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

WIP=$(git diff --quiet || echo '-WIP')
BRANCH=$(git rev-parse --abbrev-ref HEAD | sed 's#/#-#g')
# When 7 chars are not enough to be unique, git automatically uses more.
# We are forcing to 7 here, as we are doing for grafana/grafana as well.
SHA=$(git rev-parse --short=7 HEAD | head -c7)

# If not a tag, use branch-hash else use tag
TAG=$((git describe --exact-match 2> /dev/null || echo "") | sed 's/v//g')

if [ -z "$TAG" ]
then
echo ${BRANCH}-${SHA}${WIP}
else
echo ${TAG}
fi