Skip to content

Commit

Permalink
Merge pull request #162 from grafana/readme-ci
Browse files Browse the repository at this point in the history
Add README instructions to CI tests
  • Loading branch information
jdbaldry authored Aug 19, 2020
2 parents 2527cf8 + 9d30355 commit 3308e09
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 20 deletions.
11 changes: 9 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,27 @@ workflows:
jobs:
- lint
- build
- test-readme

jobs:
lint:
docker:
- image: grafana/cortex-jsonnet-build-image:387f7ca
- image: grafana/cortex-jsonnet-build-image:55f5699
steps:
- checkout
- run: make lint

build:
docker:
- image: grafana/cortex-jsonnet-build-image:387f7ca
- image: grafana/cortex-jsonnet-build-image:55f5699
steps:
- checkout
- run: make build-mixin
- store_artifacts:
path: cortex-mixin.zip
test-readme:
docker:
- image: grafana/cortex-jsonnet-build-image:55f5699
steps:
- checkout
- run: make test-readme
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cortex-mixin.zip
cortex-mixin/out
cortex-mixin/vendor
/test-readme/
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: lint build-image publish-build-image
.PHONY: lint build-image publish-build-image test-readme

JSONNET_FMT := jsonnetfmt

Expand Down Expand Up @@ -28,3 +28,13 @@ build-mixin:
jsonnet -J vendor -S recording_rules.jsonnet > out/rules.yaml && \
jsonnet -J vendor -S alerts.jsonnet > out/alerts.yaml
zip -r cortex-mixin.zip cortex-mixin/out

test-readme:
rm -rf test-readme && \
mkdir test-readme && cd test-readme && \
tk init --k8s=false && \
jb install github.com/jsonnet-libs/k8s-alpha/1.18 && \
printf '(import "github.com/jsonnet-libs/k8s-alpha/1.18/main.libsonnet")\n+(import "github.com/jsonnet-libs/k8s-alpha/1.18/extensions/kausal-shim.libsonnet")' > lib/k.libsonnet && \
jb install github.com/grafana/cortex-jsonnet/cortex && \
cp vendor/cortex/cortex-manifests.jsonnet.example environments/default/main.jsonnet && \
PAGER=cat tk show environments/default
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,53 @@ To generate the YAMLs for deploying Cortex:

Follow the steps at https://tanka.dev/install. If you have `go` installed locally you can also use:

```
# make sure to be outside of GOPATH or a go.mod project
```console
$ # make sure to be outside of GOPATH or a go.mod project
$ GO111MODULE=on go get github.com/grafana/tanka/cmd/tk
$ GO111MODULE=on go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
```

1. Initialise the application and download the cortex jsonnet lib.
1. Initialise the Tanka, and install the Cortex and Kubernetes Jsonnet libraries.

```
```console
$ mkdir <name> && cd <name>
$ tk init
$ tk init --k8s=false
$ # The k8s-alpha library supports Kubernetes versions 1.14+
$ jb install github.com/jsonnet-libs/k8s-alpha/1.18
$ cat <<EOF > lib/k.libsonnet
(import "github.com/jsonnet-libs/k8s-alpha/1.18/main.libsonnet")
+ (import "github.com/jsonnet-libs/k8s-alpha/1.18/extensions/kausal-shim.libsonnet")
EOF
$ jb install github.com/grafana/cortex-jsonnet/cortex
```
1. Use the example monitoring.jsonnet.example:

```
```console
$ cp vendor/cortex/cortex-manifests.jsonnet.example environments/default/main.jsonnet
```

1. Check what is in the example:

```
```console
$ cat environments/default/main.jsonnet
...
```

1. Generate the YAML manifests:

```
```console
$ tk show environments/default
```

To output YAML manifests to `./manifests`, run:

```
```console
$ tk export environments/default manifests
```

To generate the dashboards and alerts for Cortex:

```
```console
$ cd cortex-mixin
$ jb install
$ mkdir out
Expand Down
25 changes: 18 additions & 7 deletions build-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,26 @@ RUN git clone https://github.com/google/jsonnet && \
cp jsonnet/jsonnetfmt /usr/bin

# Build jb
FROM golang:1.14.1-alpine3.11 AS jb-builder
RUN apk add --no-cache git make
RUN git clone https://github.com/jsonnet-bundler/jsonnet-bundler /jsonnet-bundler && \
cd /jsonnet-bundler && \
git checkout v0.2.0 && \
make install
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 tanka
FROM alpine:3.11 AS tk-builder
ARG TANKA_VERSION=0.11.1
ARG TANKA_CHECKSUM="3b253ca7d7bf01189604c10a8f7cead20a553ddc04c813f0f836d80338cfad71 /usr/bin/tk"
RUN apk add --no-cache curl
RUN curl -fSL -o "/usr/bin/tk" "https://github.com/grafana/tanka/releases/download/v${TANKA_VERSION}/tk-linux-amd64"
RUN echo "${TANKA_CHECKSUM}" | sha256sum -c || (printf "wanted: %s\n got: %s\n" "${TANKA_CHECKSUM}" "$(sha256sum /usr/bin/tk)"; exit 1)
RUN chmod +x /usr/bin/tk

FROM alpine:3.11
RUN apk add --no-cache git make libgcc libstdc++ zip
COPY --from=jsonnet-builder /usr/bin/jsonnetfmt /usr/bin
COPY --from=jsonnet-builder /usr/bin/jsonnet /usr/bin
COPY --from=jb-builder /go/bin/jb /usr/bin
COPY --from=jb-builder /usr/bin/jb /usr/bin
COPY --from=tk-builder /usr/bin/tk /usr/bin

0 comments on commit 3308e09

Please sign in to comment.