From b73d2a29a729650dcaf8a0b0bf4e2cc7d1377bd3 Mon Sep 17 00:00:00 2001 From: Riyaz Faizullabhoy Date: Mon, 19 Dec 2016 16:34:57 -0800 Subject: [PATCH] Add lint docker image for golang linting and testing to individual package subdirs Signed-off-by: Riyaz Faizullabhoy --- Makefile | 10 +-------- alpine/base/alpine-go-lint/Dockerfile | 11 ++++++++++ alpine/base/alpine-go-lint/Makefile | 29 +++++++++++++++++++++++++++ alpine/base/alpine-go-lint/lint.sh | 16 +++++++++++++++ alpine/packages/diagnostics/Makefile | 8 +++++++- alpine/packages/proxy/Makefile | 8 +++++++- alpine/packages/vsudd/Makefile | 8 +++++++- 7 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 alpine/base/alpine-go-lint/Dockerfile create mode 100644 alpine/base/alpine-go-lint/Makefile create mode 100755 alpine/base/alpine-go-lint/lint.sh diff --git a/Makefile b/Makefile index 827b54bb6..ceaf9616b 100644 --- a/Makefile +++ b/Makefile @@ -37,14 +37,6 @@ hyperkit.git/build/com.docker.hyperkit: hyperkit.git hyperkit: hyperkit.sh hyperkit.git/build/com.docker.hyperkit alpine/initrd.img alpine/kernel/x86_64/vmlinuz64 sudo ./hyperkit.sh -lint: - # gofmt - @test -z "$$(gofmt -s -l .| grep -v .pb. | grep -v */vendor/ | tee /dev/stderr)" - # govet - @test -z "$$(go tool vet -printf=false . 2>&1 | grep -v */vendor/ | tee /dev/stderr)" - # golint - @test -z "$(shell find . -type f -name "*.go" -not -path "*/vendor/*" -not -name "*.pb.*" -exec golint {} \; | tee /dev/stderr)" - test: Dockerfile.test alpine/initrd-test.img alpine/kernel/x86_64/vmlinuz64 $(MAKE) -C alpine BUILD=$$( tar cf - $^ | docker build -f Dockerfile.test -q - ) && \ @@ -101,7 +93,7 @@ ci: $(MAKE) AUFS=1 test $(MAKE) AUFS=1 media -ci-pr: lint +ci-pr: $(MAKE) clean $(MAKE) all $(MAKE) test diff --git a/alpine/base/alpine-go-lint/Dockerfile b/alpine/base/alpine-go-lint/Dockerfile new file mode 100644 index 000000000..7b31897c9 --- /dev/null +++ b/alpine/base/alpine-go-lint/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:1.7-alpine +RUN apk update && apk add --no-cache build-base git + +# Get linting tools +RUN go get -u github.com/golang/lint/golint + +# Get the linting script and make its source dir +COPY lint.sh . +RUN mkdir /src + +CMD ["./lint.sh", "/src"] \ No newline at end of file diff --git a/alpine/base/alpine-go-lint/Makefile b/alpine/base/alpine-go-lint/Makefile new file mode 100644 index 000000000..56da374e9 --- /dev/null +++ b/alpine/base/alpine-go-lint/Makefile @@ -0,0 +1,29 @@ +.PHONY: tag push + +BASE=golang:1.7-alpine +IMAGE=alpine-go-lint + +default: push + +hash: + DOCKER_CONTENT_TRUST=1 docker pull $(BASE) + tar cf - Dockerfile | docker build --no-cache -t $(IMAGE):build . + docker run --rm $(IMAGE):build sh -c 'cat /go/lint.sh /usr/local/go/bin/go /lib/apk/db/installed /go/bin/golint | sha1sum' | sed 's/ .*//' > hash + +push: hash + docker pull mobylinux/$(IMAGE):$(shell cat hash) || \ + (docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash) && \ + docker push mobylinux/$(IMAGE):$(shell cat hash)) + docker rmi $(IMAGE):build + rm -f hash + +tag: hash + docker pull mobylinux/$(IMAGE):$(shell cat hash) || \ + docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash) + docker rmi $(IMAGE):build + rm -f hash + +clean: + rm -f hash + +.DELETE_ON_ERROR: diff --git a/alpine/base/alpine-go-lint/lint.sh b/alpine/base/alpine-go-lint/lint.sh new file mode 100755 index 000000000..d5bd31154 --- /dev/null +++ b/alpine/base/alpine-go-lint/lint.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +cd /src + +>&2 echo "gofmt..." +test -z $(gofmt -s -l .| grep -v .pb. | grep -v */vendor/ | tee /dev/stderr) + +>&2 echo "govet..." +test -z $(go tool vet -printf=false . 2>&1 | grep -v */vendor/ | tee /dev/stderr) + +>&2 echo "golint..." +test -z $(find . -type f -name "*.go" -not -path "*/vendor/*" -not -name "*.pb.*" -exec golint {} \; | tee /dev/stderr) + +>&2 echo "Successful lint check!" \ No newline at end of file diff --git a/alpine/packages/diagnostics/Makefile b/alpine/packages/diagnostics/Makefile index 541c19900..91b6cd5ac 100644 --- a/alpine/packages/diagnostics/Makefile +++ b/alpine/packages/diagnostics/Makefile @@ -2,7 +2,10 @@ all: usr/bin/diagnostics-server DEPS=Dockerfile $(wildcard *.go) -usr/bin/diagnostics-server: $(DEPS) ../vendor/manifest +# Tag: 02a04b2dc262195773b29125daebca0eebd97845 +LINT_IMAGE=mobylinux/alpine-go-lint@sha256:3009197c25294d87a7e81a53493666de47ed2b55a5bd283eabad4b876ea64559 + +usr/bin/diagnostics-server: $(DEPS) ../vendor/manifest lint BUILD=$$( tar cf - $(DEPS) -C .. vendor | docker build -q - ) && \ [ -n "$$BUILD" ] && \ echo "Built $$BUILD" && \ @@ -11,4 +14,7 @@ usr/bin/diagnostics-server: $(DEPS) ../vendor/manifest clean: rm -f usr/bin/diagnostics-server +lint: + docker run --rm -v $(PWD):/src $(LINT_IMAGE) + .DELETE_ON_ERROR: diff --git a/alpine/packages/proxy/Makefile b/alpine/packages/proxy/Makefile index 964b08a6d..e05997c3e 100644 --- a/alpine/packages/proxy/Makefile +++ b/alpine/packages/proxy/Makefile @@ -2,7 +2,10 @@ all: usr/bin/slirp-proxy sbin/proxy-vsockd DEPS=Dockerfile $(wildcard *.go libproxy/*.go) -proxy: $(DEPS) ../vendor/manifest +# Tag: 02a04b2dc262195773b29125daebca0eebd97845 +LINT_IMAGE=mobylinux/alpine-go-lint@sha256:3009197c25294d87a7e81a53493666de47ed2b55a5bd283eabad4b876ea64559 + +proxy: $(DEPS) ../vendor/manifest lint BUILD=$$( tar cf - $(DEPS) -C .. vendor | docker build -q - ) && \ [ -n "$$BUILD" ] && \ echo "Built $$BUILD" && \ @@ -19,4 +22,7 @@ sbin/proxy-vsockd: proxy clean: rm -rf proxy sbin usr +lint: + docker run --rm -v $(PWD):/src $(LINT_IMAGE) + .DELETE_ON_ERROR: diff --git a/alpine/packages/vsudd/Makefile b/alpine/packages/vsudd/Makefile index ec5aec1a8..f93a5ff75 100644 --- a/alpine/packages/vsudd/Makefile +++ b/alpine/packages/vsudd/Makefile @@ -2,7 +2,10 @@ all: vsudd DEPS=Dockerfile $(wildcard *.go) -vsudd: $(DEPS) ../vendor/manifest +# Tag: 02a04b2dc262195773b29125daebca0eebd97845 +LINT_IMAGE=mobylinux/alpine-go-lint@sha256:3009197c25294d87a7e81a53493666de47ed2b55a5bd283eabad4b876ea64559 + +vsudd: $(DEPS) ../vendor/manifest lint mkdir -p sbin BUILD=$$( tar cf - $(DEPS) -C .. vendor | docker build -q - ) && \ [ -n "$$BUILD" ] && \ @@ -12,4 +15,7 @@ vsudd: $(DEPS) ../vendor/manifest clean: rm -rf sbin +lint: + docker run --rm -v $(PWD):/src $(LINT_IMAGE) + .DELETE_ON_ERROR: