Skip to content

Commit 8b4fa20

Browse files
committed
Go code checks can be run locally in container
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 <[email protected]>
1 parent 766b218 commit 8b4fa20

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

Dockerfile-check

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ARG TAG=latest
2+
3+
FROM golang:1.7.6
4+
5+
ENV GOPATH=/go
6+
7+
WORKDIR /go/src/github.com/contiv/netplugin/
8+
ENTRYPOINT ["/code_checks.sh"]
9+
10+
RUN go get github.com/tools/godep github.com/aktau/github-release \
11+
github.com/contiv/modelgen \
12+
&& go get -u github.com/golang/lint/golint \
13+
github.com/client9/misspell/cmd/misspell
14+
15+
COPY scripts/code_checks.sh /

Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ NAME := netplugin
1616
VERSION_FILE := $(NAME)-version
1717
VERSION := `cat $(VERSION_FILE)`
1818
TAR_EXT := tar.bz2
19+
# BUILD_VERSION=1.2 make --> 1.2-1097d2a7, otherwise devbuild-1097d2a7
20+
export NETPLUGIN_CONTAINER_TAG := $(or $(BUILD_VERSION),devbuild)-$(shell ./scripts/getGitCommit.sh)
1921
TAR_FILENAME := $(NAME)-$(VERSION).$(TAR_EXT)
2022
TAR_LOC := .
2123
TAR_FILE := $(TAR_LOC)/$(TAR_FILENAME)
@@ -87,6 +89,12 @@ endif
8789

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

92+
checks-with-docker: compile-with-docker
93+
docker build -f Dockerfile-check -t contiv/netplugin-checks .
94+
docker run --rm --name netplugin-checks \
95+
-v ${PWD}:/go/src/github.com/contiv/netplugin/ \
96+
contiv/netplugin-checks $(PKG_DIRS)
97+
9098
compile:
9199
cd $(GOPATH)/src/github.com/contiv/netplugin && \
92100
NIGHTLY_RELEASE=${NIGHTLY_RELEASE} BUILD_VERSION=${BUILD_VERSION} \

scripts/code_checks.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
PKG_DIRS=$*
6+
7+
############# CORRECTNESS CHECKING #########
8+
echo -e "\nChecking correctness for $PKG_DIRS ...\n"
9+
go tool vet $PKG_DIRS
10+
11+
############# LINT CHECKING ################
12+
echo -e "\nChecking lint for $PKG_DIRS ...\n"
13+
golint -set_exit_status $PKG_DIRS
14+
15+
############# FORMAT CHECKING #############
16+
echo -e "\nChecking format for $PKG_DIRS ...\n"
17+
gofmt -s -d $PKG_DIRS
18+
19+
misspell -locale US -error $PKG_DIRS

0 commit comments

Comments
 (0)