Skip to content

Commit 2829b0f

Browse files
tomwilkietombrk
andauthored
Use mixtool to lint mixins (grafana#357)
* Make link use mixtool to ensure mixins compile and lint. Signed-off-by: Tom Wilkie <[email protected]> * Add jsonnetfile for jaeger-mixin, update others. Signed-off-by: Tom Wilkie <[email protected]> * Add UIDs for dashboards so they lint. Based on the md5 of the filename, same as prometheus-ksonnet. Signed-off-by: Tom Wilkie <[email protected]> * Put @ back Signed-off-by: Tom Wilkie <[email protected]> * Make it work in CI Signed-off-by: Tom Wilkie <[email protected]> * Add bash to CI container. Signed-off-by: Tom Wilkie <[email protected]> * Add jb to build image. Signed-off-by: Tom Wilkie <[email protected]> * Update Makefile Co-authored-by: sh0rez <[email protected]> Co-authored-by: sh0rez <[email protected]>
1 parent a71896f commit 2829b0f

File tree

9 files changed

+83
-30
lines changed

9 files changed

+83
-30
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22

33
defaults: &defaults
44
docker:
5-
- image: grafana/jsonnet-build:1022b37
5+
- image: grafana/jsonnet-build:e7ca4b7
66

77
workflows:
88
version: 2

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
JSONNET_FMT := jsonnetfmt -n 2 --max-blank-lines 2 --string-style s --comment-style s
2+
SHELL := /bin/bash
23

34
fmt:
45
@find . -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \
@@ -12,4 +13,17 @@ lint:
1213
RESULT=1; \
1314
fi; \
1415
done; \
16+
for d in $$(find . -name '*-mixin' -a -type d -print); do \
17+
if [ -e "$$d/jsonnetfile.json" ]; then \
18+
echo "Installing dependencies for $$d"; \
19+
pushd "$$d" >/dev/null && jb install && popd >/dev/null; \
20+
fi; \
21+
done; \
22+
for m in $$(find . -name 'mixin.libsonnet' -print); do \
23+
echo "Linting $$m"; \
24+
mixtool lint -J $$(dirname "$$m")/vendor "$$m"; \
25+
if [ $$? -ne 0 ]; then \
26+
RESULT=1; \
27+
fi; \
28+
done; \
1529
exit $$RESULT

build/Dockerfile

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
# Dockerfile for image used to run CI.
22

3-
FROM alpine:3.7
3+
# Build jsonnet
4+
FROM alpine:3.7 AS jsonnet-builder
45
RUN apk --no-cache add alpine-sdk git
56
RUN git clone https://github.com/google/jsonnet
67
RUN git -C jsonnet checkout v0.15.0
78
RUN make -C jsonnet LDFLAGS=-static
89

10+
# Build jb
11+
FROM alpine:3.11 AS jb-builder
12+
ARG JSONNET_BUNDLER_VERSION=0.4.0
13+
ARG JSONNET_BUNDLER_CHECKSUM="433edab5554a88a0371e11e93080408b225d41c31decf321c02b50d2e44993ce /usr/bin/jb"
14+
RUN apk add --no-cache curl
15+
RUN curl -fSL -o "/usr/bin/jb" "https://github.com/jsonnet-bundler/jsonnet-bundler/releases/download/v${JSONNET_BUNDLER_VERSION}/jb-linux-amd64"
16+
RUN echo "${JSONNET_BUNDLER_CHECKSUM}" | sha256sum -c || (printf "wanted: %s\n got: %s\n" "${JSONNET_BUNDLER_CHECKSUM}" "$(sha256sum /usr/bin/jb)"; exit 1)
17+
RUN chmod +x /usr/bin/jb
18+
19+
# Build mixtool
20+
FROM golang:1.15-alpine AS mixtool-builder
21+
RUN GO111MODULE=on go get github.com/monitoring-mixins/mixtool/cmd/mixtool@59d44357240d
22+
923
FROM alpine:3.7
10-
RUN apk --no-cache add make python git openssh-client
11-
COPY --from=0 jsonnet/jsonnet /usr/bin
12-
COPY --from=0 jsonnet/jsonnetfmt /usr/bin
24+
RUN apk --no-cache add make python git openssh-client bash
25+
COPY --from=jsonnet-builder jsonnet/jsonnet /usr/bin
26+
COPY --from=jsonnet-builder jsonnet/jsonnetfmt /usr/bin
27+
COPY --from=jb-builder /usr/bin/jb /urs/bin
28+
COPY --from=mixtool-builder /go/bin/mixtool /usr/bin

build/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
.uptodate: Dockerfile
22
docker build -t grafana/jsonnet-build:$(shell git rev-parse --short HEAD) .
33
touch $@
4+
5+
publish-build-image:
6+
docker push grafana/jsonnet-build:$(shell git rev-parse --short HEAD)

consul-mixin/jsonnetfile.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
2-
"dependencies": [
3-
{
4-
"name": "grafana-builder",
5-
"source": {
6-
"git": {
7-
"remote": "https://github.com/grafana/jsonnet-libs",
8-
"subdir": "grafana-builder"
9-
}
10-
},
11-
"version": "master"
2+
"version": 1,
3+
"dependencies": [
4+
{
5+
"source": {
6+
"git": {
7+
"remote": "https://github.com/grafana/jsonnet-libs.git",
8+
"subdir": "grafana-builder"
129
}
13-
]
10+
},
11+
"version": "master"
12+
}
13+
],
14+
"legacyImports": true
1415
}

jaeger-mixin/dashboards.libsonnet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ local g = (import 'grafana-builder/grafana.libsonnet') + {
3030
{
3131
grafanaDashboards+: {
3232
'jaeger-write.json':
33-
g.dashboard('Jaeger / Write')
33+
(g.dashboard('Jaeger / Write') + { uid: '5f26222aa7a3fb734f0cd4072cab43b3' })
3434
.addRow(
3535
g.row('Services')
3636
.addPanel(
@@ -113,7 +113,7 @@ local g = (import 'grafana-builder/grafana.libsonnet') + {
113113
),
114114

115115
'jaeger-read.json':
116-
g.dashboard('Jaeger / Read')
116+
(g.dashboard('Jaeger / Read') + { uid: '1311ff9971f44f5ade3e1592d579f3f4' })
117117
.addRow(
118118
g.row('Query')
119119
.addPanel(

jaeger-mixin/jsonnetfile.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": 1,
3+
"dependencies": [
4+
{
5+
"source": {
6+
"git": {
7+
"remote": "https://github.com/grafana/jsonnet-libs.git",
8+
"subdir": "grafana-builder"
9+
}
10+
},
11+
"version": "master"
12+
}
13+
],
14+
"legacyImports": true
15+
}

memcached-mixin/dashboards.libsonnet

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ local g = (import 'grafana-builder/grafana.libsonnet');
33
{
44
grafanaDashboards+: {
55
'memcached-overview.json':
6-
g.dashboard('Memcached Overview')
6+
(
7+
g.dashboard('Memcached Overview') +
8+
{ uid: '124d5222454213f748dbfaf69b77ec48' }
9+
)
710
.addMultiTemplate('cluster', 'memcached_commands_total', 'cluster')
811
.addMultiTemplate('job', 'memcached_commands_total{cluster=~"$cluster"}', 'job')
912
.addMultiTemplate('instance', 'memcached_commands_total{cluster=~"$cluster",job=~"$job"}', 'instance')

memcached-mixin/jsonnetfile.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
2-
"dependencies": [
3-
{
4-
"name": "grafana-builder",
5-
"source": {
6-
"git": {
7-
"remote": "https://github.com/grafana/jsonnet-libs",
8-
"subdir": "grafana-builder"
9-
}
10-
},
11-
"version": "master"
2+
"version": 1,
3+
"dependencies": [
4+
{
5+
"source": {
6+
"git": {
7+
"remote": "https://github.com/grafana/jsonnet-libs.git",
8+
"subdir": "grafana-builder"
129
}
13-
]
10+
},
11+
"version": "master"
12+
}
13+
],
14+
"legacyImports": true
1415
}

0 commit comments

Comments
 (0)