Skip to content

Commit

Permalink
Use mixtool to lint mixins (grafana#357)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
tomwilkie and sh0rez authored Oct 13, 2020
1 parent a71896f commit 2829b0f
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2

defaults: &defaults
docker:
- image: grafana/jsonnet-build:1022b37
- image: grafana/jsonnet-build:e7ca4b7

workflows:
version: 2
Expand Down
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
JSONNET_FMT := jsonnetfmt -n 2 --max-blank-lines 2 --string-style s --comment-style s
SHELL := /bin/bash

fmt:
@find . -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \
Expand All @@ -12,4 +13,17 @@ lint:
RESULT=1; \
fi; \
done; \
for d in $$(find . -name '*-mixin' -a -type d -print); do \
if [ -e "$$d/jsonnetfile.json" ]; then \
echo "Installing dependencies for $$d"; \
pushd "$$d" >/dev/null && jb install && popd >/dev/null; \
fi; \
done; \
for m in $$(find . -name 'mixin.libsonnet' -print); do \
echo "Linting $$m"; \
mixtool lint -J $$(dirname "$$m")/vendor "$$m"; \
if [ $$? -ne 0 ]; then \
RESULT=1; \
fi; \
done; \
exit $$RESULT
24 changes: 20 additions & 4 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
# Dockerfile for image used to run CI.

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

# Build jb
FROM alpine:3.11 AS jb-builder
ARG JSONNET_BUNDLER_VERSION=0.4.0
ARG JSONNET_BUNDLER_CHECKSUM="433edab5554a88a0371e11e93080408b225d41c31decf321c02b50d2e44993ce /usr/bin/jb"
RUN apk add --no-cache curl
RUN curl -fSL -o "/usr/bin/jb" "https://github.com/jsonnet-bundler/jsonnet-bundler/releases/download/v${JSONNET_BUNDLER_VERSION}/jb-linux-amd64"
RUN echo "${JSONNET_BUNDLER_CHECKSUM}" | sha256sum -c || (printf "wanted: %s\n got: %s\n" "${JSONNET_BUNDLER_CHECKSUM}" "$(sha256sum /usr/bin/jb)"; exit 1)
RUN chmod +x /usr/bin/jb

# Build mixtool
FROM golang:1.15-alpine AS mixtool-builder
RUN GO111MODULE=on go get github.com/monitoring-mixins/mixtool/cmd/mixtool@59d44357240d

FROM alpine:3.7
RUN apk --no-cache add make python git openssh-client
COPY --from=0 jsonnet/jsonnet /usr/bin
COPY --from=0 jsonnet/jsonnetfmt /usr/bin
RUN apk --no-cache add make python git openssh-client bash
COPY --from=jsonnet-builder jsonnet/jsonnet /usr/bin
COPY --from=jsonnet-builder jsonnet/jsonnetfmt /usr/bin
COPY --from=jb-builder /usr/bin/jb /urs/bin
COPY --from=mixtool-builder /go/bin/mixtool /usr/bin
3 changes: 3 additions & 0 deletions build/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.uptodate: Dockerfile
docker build -t grafana/jsonnet-build:$(shell git rev-parse --short HEAD) .
touch $@

publish-build-image:
docker push grafana/jsonnet-build:$(shell git rev-parse --short HEAD)
23 changes: 12 additions & 11 deletions consul-mixin/jsonnetfile.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"dependencies": [
{
"name": "grafana-builder",
"source": {
"git": {
"remote": "https://github.com/grafana/jsonnet-libs",
"subdir": "grafana-builder"
}
},
"version": "master"
"version": 1,
"dependencies": [
{
"source": {
"git": {
"remote": "https://github.com/grafana/jsonnet-libs.git",
"subdir": "grafana-builder"
}
]
},
"version": "master"
}
],
"legacyImports": true
}
4 changes: 2 additions & 2 deletions jaeger-mixin/dashboards.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ local g = (import 'grafana-builder/grafana.libsonnet') + {
{
grafanaDashboards+: {
'jaeger-write.json':
g.dashboard('Jaeger / Write')
(g.dashboard('Jaeger / Write') + { uid: '5f26222aa7a3fb734f0cd4072cab43b3' })
.addRow(
g.row('Services')
.addPanel(
Expand Down Expand Up @@ -113,7 +113,7 @@ local g = (import 'grafana-builder/grafana.libsonnet') + {
),

'jaeger-read.json':
g.dashboard('Jaeger / Read')
(g.dashboard('Jaeger / Read') + { uid: '1311ff9971f44f5ade3e1592d579f3f4' })
.addRow(
g.row('Query')
.addPanel(
Expand Down
15 changes: 15 additions & 0 deletions jaeger-mixin/jsonnetfile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": 1,
"dependencies": [
{
"source": {
"git": {
"remote": "https://github.com/grafana/jsonnet-libs.git",
"subdir": "grafana-builder"
}
},
"version": "master"
}
],
"legacyImports": true
}
5 changes: 4 additions & 1 deletion memcached-mixin/dashboards.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ local g = (import 'grafana-builder/grafana.libsonnet');
{
grafanaDashboards+: {
'memcached-overview.json':
g.dashboard('Memcached Overview')
(
g.dashboard('Memcached Overview') +
{ uid: '124d5222454213f748dbfaf69b77ec48' }
)
.addMultiTemplate('cluster', 'memcached_commands_total', 'cluster')
.addMultiTemplate('job', 'memcached_commands_total{cluster=~"$cluster"}', 'job')
.addMultiTemplate('instance', 'memcached_commands_total{cluster=~"$cluster",job=~"$job"}', 'instance')
Expand Down
23 changes: 12 additions & 11 deletions memcached-mixin/jsonnetfile.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"dependencies": [
{
"name": "grafana-builder",
"source": {
"git": {
"remote": "https://github.com/grafana/jsonnet-libs",
"subdir": "grafana-builder"
}
},
"version": "master"
"version": 1,
"dependencies": [
{
"source": {
"git": {
"remote": "https://github.com/grafana/jsonnet-libs.git",
"subdir": "grafana-builder"
}
]
},
"version": "master"
}
],
"legacyImports": true
}

0 comments on commit 2829b0f

Please sign in to comment.