Skip to content

Commit 01da373

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. Drive-by: * Fix comment in Dockerfile * http_proxy and https_proxy are not useful as args when not referenced * add GOPATH environment var to Dockerfile for general use Signed-off-by: Chris Plock <[email protected]>
1 parent 766b218 commit 01da373

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

Dockerfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ FROM golang:1.7.6
2626
# a proxy.
2727
#ENV http_proxy ""
2828
#ENV https_proxy ""
29-
ARG http_proxy
30-
ARG https_proxy
3129

30+
ENV GOPATH=/go
3231
WORKDIR /go/src/github.com/contiv/netplugin/
3332

3433
ENTRYPOINT ["netplugin"]

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

+9-1
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} \
@@ -100,7 +108,7 @@ compile-with-docker:
100108
docker build \
101109
--build-arg NIGHTLY_RELEASE=${NIGHTLY_RELEASE} \
102110
--build-arg BUILD_VERSION=${BUILD_VERSION} \
103-
-t netplugin:$${BUILD_VERSION:-devbuild}-$$(./scripts/getGitCommit.sh) .
111+
-t netplugin-build:$${BUILD_VERSION:-devbuild}-$$(./scripts/getGitCommit.sh) .
104112

105113
build-docker-image: start
106114
vagrant ssh netplugin-node1 -c 'bash -lc "source /etc/profile.d/envvar.sh && cd /opt/gopath/src/github.com/contiv/netplugin && make host-build-docker-image"'

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)