-
Notifications
You must be signed in to change notification settings - Fork 328
150 lines (134 loc) · 5.04 KB
/
docker.yml
File metadata and controls
150 lines (134 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
name: Build and Push Docker Image
on:
push:
branches:
- main
tags:
- "v*.*.*"
pull_request:
branches:
- main
release:
types: [published]
permissions:
contents: read
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
is_tag: ${{ steps.check.outputs.is_tag }}
version: ${{ steps.tag.outputs.version }}
is_stable: ${{ steps.tag.outputs.is_stable }}
platforms: ${{ steps.platforms.outputs.platforms }}
steps:
- name: Check if tag push
id: check
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
echo "is_tag=true" >> $GITHUB_OUTPUT
else
echo "is_tag=false" >> $GITHUB_OUTPUT
fi
- name: Process tag name
id: tag
if: steps.check.outputs.is_tag == 'true'
run: |
VERSION=${GITHUB_REF_NAME#v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Check if this is a stable release (no rc, alpha, beta, etc.)
if [[ ! "$VERSION" =~ (rc|alpha|beta|pre|dev) ]]; then
echo "is_stable=true" >> $GITHUB_OUTPUT
else
echo "is_stable=false" >> $GITHUB_OUTPUT
fi
- name: Determine platforms
id: platforms
run: |
# Only build multi-arch on pushes/tags/releases, not on PRs
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "platforms=linux/amd64" >> $GITHUB_OUTPUT
else
echo "platforms=linux/amd64,linux/arm64" >> $GITHUB_OUTPUT
fi
docker:
runs-on: ubuntu-latest
needs: prepare
permissions:
id-token: write
steps:
- uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98
- name: Build and Push to Docker Hub
uses: grafana/shared-workflows/actions/build-push-to-dockerhub@7f983a8135eb58eaec83c96d8b842b2092e110e3
with:
context: .
file: ./Dockerfile
repository: grafana/mcp-grafana
platforms: ${{ needs.prepare.outputs.platforms }}
tags: |
${{ needs.prepare.outputs.is_tag == 'true' && needs.prepare.outputs.is_stable == 'true' && 'latest' || '' }}
${{ needs.prepare.outputs.is_tag == 'true' && needs.prepare.outputs.version || '' }}
push: ${{ needs.prepare.outputs.is_tag == 'true' }}
docker-alpine:
runs-on: ubuntu-latest
needs: prepare
permissions:
id-token: write
steps:
- uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98
- name: Build and Push Alpine to Docker Hub
uses: grafana/shared-workflows/actions/build-push-to-dockerhub@7f983a8135eb58eaec83c96d8b842b2092e110e3
with:
context: .
file: ./Dockerfile.alpine
repository: grafana/mcp-grafana
platforms: ${{ needs.prepare.outputs.platforms }}
tags: |
${{ needs.prepare.outputs.is_tag == 'true' && needs.prepare.outputs.is_stable == 'true' && 'alpine' || '' }}
${{ needs.prepare.outputs.is_tag == 'true' && format('{0}-alpine', needs.prepare.outputs.version) || '' }}
push: ${{ needs.prepare.outputs.is_tag == 'true' }}
mcp-registry:
runs-on: ubuntu-latest
needs: docker
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: read
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
- name: Extract version from tag
id: version
run: |
# Get the tag from the triggering workflow
TAG=$(git describe --tags --exact-match HEAD 2>/dev/null || echo "")
if [ -z "$TAG" ]; then
echo "No tag found at HEAD"
exit 1
fi
echo "VERSION=$TAG" >> $GITHUB_OUTPUT
- name: Extract image tag from version
id: image-tag
run: |
# Extract the image tag from the version
VERSION="${{ steps.version.outputs.VERSION }}"
echo "IMAGE_TAG=${VERSION#v}" >> $GITHUB_OUTPUT
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get install -y jq
curl -L "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_linux_amd64.tar.gz" | tar xz mcp-publisher
chmod +x mcp-publisher
sudo mv mcp-publisher /usr/local/bin/
- name: Update server.json with Docker image
run: |
# Update the server.json with the correct Docker image reference
# (note the image tag does not include the "v" prefix)
jq --arg version "${{ steps.version.outputs.VERSION }}" \
--arg image "docker.io/grafana/mcp-grafana:${{ steps.image-tag.outputs.IMAGE_TAG }}" \
'.version = $version | .packages[0].identifier = $image' server.json > server.json.tmp
mv server.json.tmp server.json
- name: Login to MCP Registry
run: mcp-publisher login github-oidc
- name: Publish to MCP Registry
run: mcp-publisher publish