Skip to content

Commit

Permalink
Go code checks can be run locally in container
Browse files Browse the repository at this point in the history
Before the only option was to spin up a VM to run code checks, which is
expensive in terms of time.

Add Dockerfile-check to provide a container build for a runtime
environment that supports go tool vet, gofmt, and golint

Add script 'code_checks.sh' intended to be run inside the
Dockerfile-check container that runs 'go tool vet', 'gofmt',
misspell, and 'golint' against packages directories passed in.  This
script runs the checks in a different order than the Makefile, to deal
with the more severe issues first, and deal with pretty print
formatting last.

Makefile updated to build the docker container and run it against the
go pakages for netplugin.

Signed-off-by: Chris Plock <chrisplo@cisco.com>
  • Loading branch information
chrisplo committed Oct 16, 2017
1 parent 766b218 commit 8b4fa20
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Dockerfile-check
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ARG TAG=latest

FROM golang:1.7.6

ENV GOPATH=/go

WORKDIR /go/src/github.com/contiv/netplugin/
ENTRYPOINT ["/code_checks.sh"]

RUN go get github.com/tools/godep github.com/aktau/github-release \
github.com/contiv/modelgen \
&& go get -u github.com/golang/lint/golint \
github.com/client9/misspell/cmd/misspell

COPY scripts/code_checks.sh /
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ NAME := netplugin
VERSION_FILE := $(NAME)-version
VERSION := `cat $(VERSION_FILE)`
TAR_EXT := tar.bz2
# BUILD_VERSION=1.2 make --> 1.2-1097d2a7, otherwise devbuild-1097d2a7
export NETPLUGIN_CONTAINER_TAG := $(or $(BUILD_VERSION),devbuild)-$(shell ./scripts/getGitCommit.sh)
TAR_FILENAME := $(NAME)-$(VERSION).$(TAR_EXT)
TAR_LOC := .
TAR_FILE := $(TAR_LOC)/$(TAR_FILENAME)
Expand Down Expand Up @@ -87,6 +89,12 @@ endif

checks: go-version gofmt-src golint-src govet-src misspell-src

checks-with-docker: compile-with-docker
docker build -f Dockerfile-check -t contiv/netplugin-checks .
docker run --rm --name netplugin-checks \
-v ${PWD}:/go/src/github.com/contiv/netplugin/ \
contiv/netplugin-checks $(PKG_DIRS)

compile:
cd $(GOPATH)/src/github.com/contiv/netplugin && \
NIGHTLY_RELEASE=${NIGHTLY_RELEASE} BUILD_VERSION=${BUILD_VERSION} \
Expand Down
19 changes: 19 additions & 0 deletions scripts/code_checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -euo pipefail

PKG_DIRS=$*

############# CORRECTNESS CHECKING #########
echo -e "\nChecking correctness for $PKG_DIRS ...\n"
go tool vet $PKG_DIRS

############# LINT CHECKING ################
echo -e "\nChecking lint for $PKG_DIRS ...\n"
golint -set_exit_status $PKG_DIRS

############# FORMAT CHECKING #############
echo -e "\nChecking format for $PKG_DIRS ...\n"
gofmt -s -d $PKG_DIRS

misspell -locale US -error $PKG_DIRS

0 comments on commit 8b4fa20

Please sign in to comment.