diff --git a/Dockerfile b/Dockerfile index a26468201b..8971edf6b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -115,17 +115,6 @@ RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" \ ENV PATH /go/bin:/usr/local/go/bin:$PATH ENV GOPATH /go -# Dependency for golint -ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3 -RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \ - && (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT) - -# Grab Go's lint tool -ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456 -RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \ - && (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \ - && go install -v github.com/golang/lint/golint - # Install CRIU for checkpoint/restore support ENV CRIU_VERSION 2.12.1 # Install dependancy packages specific to criu @@ -215,7 +204,7 @@ RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \ # Please edit hack/dockerfile/install-binaries.sh to update them. COPY hack/dockerfile/binaries-commits /tmp/binaries-commits COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh -RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy dockercli +RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy dockercli gometalinter ENV PATH=/usr/local/cli:$PATH # Activate bash completion and include Docker's completion if mounted with DOCKER_BASH_COMPLETION_PATH diff --git a/Dockerfile.aarch64 b/Dockerfile.aarch64 index fd06e52265..5f3b25ce59 100644 --- a/Dockerfile.aarch64 +++ b/Dockerfile.aarch64 @@ -98,17 +98,6 @@ RUN mkdir /usr/src/go && curl -fsSL https://golang.org/dl/go${GO_VERSION}.src.ta ENV PATH /go/bin:/usr/src/go/bin:$PATH ENV GOPATH /go -# Dependency for golint -ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3 -RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \ - && (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT) - -# Grab Go's lint tool -ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456 -RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \ - && (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \ - && go install -v github.com/golang/lint/golint - # Only install one version of the registry, because old version which support # schema1 manifests is not working on ARM64, we should skip integration-cli # tests for schema1 manifests on ARM64. diff --git a/Dockerfile.armhf b/Dockerfile.armhf index 29503afdce..18cd74f12f 100644 --- a/Dockerfile.armhf +++ b/Dockerfile.armhf @@ -81,17 +81,6 @@ ENV GOPATH /go ENV GOARCH arm ENV GOARM 7 -# Dependency for golint -ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3 -RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \ - && (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT) - -# Grab Go's lint tool -ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456 -RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \ - && (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \ - && go install -v github.com/golang/lint/golint - # Install seccomp: the version shipped upstream is too old ENV SECCOMP_VERSION 2.3.2 RUN set -x \ diff --git a/Dockerfile.ppc64le b/Dockerfile.ppc64le index 55c1aa13c8..3234239ea6 100644 --- a/Dockerfile.ppc64le +++ b/Dockerfile.ppc64le @@ -94,17 +94,6 @@ RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-ppc64le.tar.gz" \ ENV PATH /go/bin:/usr/local/go/bin:$PATH ENV GOPATH /go -# Dependency for golint -ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3 -RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \ - && (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT) - -# Grab Go's lint tool -ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456 -RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \ - && (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \ - && go install -v github.com/golang/lint/golint - # Install two versions of the registry. The first is an older version that # only supports schema1 manifests. The second is a newer version that supports # both. This allows integration-cli tests to cover push/pull with both schema1 diff --git a/Dockerfile.s390x b/Dockerfile.s390x index 5a90f6c7c5..14dfd12bdb 100644 --- a/Dockerfile.s390x +++ b/Dockerfile.s390x @@ -87,17 +87,6 @@ RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-s390x.tar.gz" \ ENV PATH /go/bin:/usr/local/go/bin:$PATH ENV GOPATH /go -# Dependency for golint -ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3 -RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \ - && (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT) - -# Grab Go's lint tool -ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456 -RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \ - && (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \ - && go install -v github.com/golang/lint/golint - # Install two versions of the registry. The first is an older version that # only supports schema1 manifests. The second is a newer version that supports # both. This allows integration-cli tests to cover push/pull with both schema1 diff --git a/hack/dockerfile/binaries-commits b/hack/dockerfile/binaries-commits index 84c5c0faae..48c49a1889 100644 --- a/hack/dockerfile/binaries-commits +++ b/hack/dockerfile/binaries-commits @@ -12,3 +12,6 @@ VNDR_COMMIT=9909bb2b8a0b7ea464527b376dc50389c90df587 # CLI DOCKERCLI_REPO=https://github.com/docker/cli DOCKERCLI_COMMIT=3dfb8343b139d6342acfd9975d7f1068b5b1c3d3 + +# Linting +GOMETALINTER_COMMIT=f7b6e55301c9c67035003b7ba7f8a1cde532d338 diff --git a/hack/dockerfile/install-binaries.sh b/hack/dockerfile/install-binaries.sh index 370ec7ce45..f7032e68f4 100755 --- a/hack/dockerfile/install-binaries.sh +++ b/hack/dockerfile/install-binaries.sh @@ -54,6 +54,19 @@ install_dockercli() { go build -o /usr/local/bin/docker github.com/docker/cli/cmd/docker } +install_gometalinter() { + echo "Installing gometalinter version $GOMETALINTER_COMMIT" + go get -d github.com/alecthomas/gometalinter + cd "$GOPATH/src/github.com/alecthomas/gometalinter" + git checkout -q "$GOMETALINTER_COMMIT" + go build -o /usr/local/bin/gometalinter github.com/alecthomas/gometalinter + ( + export GOBIN=/usr/local/bin + export GOPATH="$PWD/_linters/" + go install github.com/golang/lint/golint + ) +} + for prog in "$@" do case $prog in @@ -80,6 +93,10 @@ do install_containerd ;; + gometalinter) + install_gometalinter + ;; + tini) echo "Install tini version $TINI_COMMIT" git clone https://github.com/krallin/tini.git "$GOPATH/tini" @@ -114,7 +131,7 @@ do ;; *) - echo echo "Usage: $0 [tomlv|runc|runc-dynamic|containerd|containerd-dynamic|tini|proxy|proxy-dynamic|vndr|dockercli]" + echo echo "Usage: $0 [tomlv|runc|runc-dynamic|containerd|containerd-dynamic|tini|proxy|proxy-dynamic|vndr|dockercli|gometalinter]" exit 1 esac diff --git a/hack/validate/default b/hack/validate/default index e243f43831..4da0686d10 100755 --- a/hack/validate/default +++ b/hack/validate/default @@ -6,13 +6,11 @@ export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" . $SCRIPTDIR/dco . $SCRIPTDIR/default-seccomp -. $SCRIPTDIR/gofmt -. $SCRIPTDIR/lint +. $SCRIPTDIR/gometalinter . $SCRIPTDIR/pkg-imports . $SCRIPTDIR/swagger . $SCRIPTDIR/swagger-gen . $SCRIPTDIR/test-imports . $SCRIPTDIR/toml -. $SCRIPTDIR/vet . $SCRIPTDIR/changelog-well-formed . $SCRIPTDIR/changelog-date-descending diff --git a/hack/validate/gofmt b/hack/validate/gofmt deleted file mode 100755 index 38027a9f77..0000000000 --- a/hack/validate/gofmt +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash - -export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "${SCRIPTDIR}/.validate" - -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | - grep -v '^vendor/' | - grep -v '\.pb\.go$' || true) ) -unset IFS - -badFiles=() -for f in "${files[@]}"; do - # we use "git show" here to validate that what's committed is formatted - if [ "$(git show "$VALIDATE_HEAD:$f" | gofmt -s -l)" ]; then - badFiles+=( "$f" ) - fi -done - -if [ ${#badFiles[@]} -eq 0 ]; then - echo 'Congratulations! All Go source files are properly formatted.' -else - { - echo "These files are not properly gofmt'd:" - for f in "${badFiles[@]}"; do - echo " - $f" - done - echo - echo 'Please reformat the above files using "gofmt -s -w" and commit the result.' - echo - } >&2 - false -fi diff --git a/hack/validate/gometalinter b/hack/validate/gometalinter new file mode 100755 index 0000000000..9830659d69 --- /dev/null +++ b/hack/validate/gometalinter @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -e -o pipefail + +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +gometalinter --config $SCRIPTDIR/gometalinter.json ./... diff --git a/hack/validate/gometalinter.json b/hack/validate/gometalinter.json new file mode 100644 index 0000000000..867bac7429 --- /dev/null +++ b/hack/validate/gometalinter.json @@ -0,0 +1,14 @@ +{ + "Vendor": true, + "Deadline": "2m", + "Sort": ["linter", "severity", "path"], + "Exclude": [".*\\.pb\\.go"], + + "Enable": [ + "gofmt", + "golint", + "vet" + ], + + "LineLength": 200 +} diff --git a/hack/validate/lint b/hack/validate/lint deleted file mode 100755 index 341490a042..0000000000 --- a/hack/validate/lint +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "${SCRIPTDIR}/.validate" - -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' | grep -v '^api/types/container/' | grep -v '\.pb\.go$' || true) ) -unset IFS - -errors=() -for f in "${files[@]}"; do - failedLint=$(golint "$f") - if [ "$failedLint" ]; then - errors+=( "$failedLint" ) - fi -done - -if [ ${#errors[@]} -eq 0 ]; then - echo 'Congratulations! All Go source files have been linted.' -else - { - echo "Errors from golint:" - for err in "${errors[@]}"; do - echo "$err" - done - echo - echo 'Please fix the above errors. You can test via "golint" and commit the result.' - echo - } >&2 - false -fi diff --git a/hack/validate/vet b/hack/validate/vet deleted file mode 100755 index 95dc7a718f..0000000000 --- a/hack/validate/vet +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash - -export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "${SCRIPTDIR}/.validate" - -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' | grep -v '^api/types/container/' || true) ) -unset IFS - -errors=() -for f in "${files[@]}"; do - failedVet=$(go vet "$f") - if [ "$failedVet" ]; then - errors+=( "$failedVet" ) - fi -done - - -if [ ${#errors[@]} -eq 0 ]; then - echo 'Congratulations! All Go source files have been vetted.' -else - { - echo "Errors from go vet:" - for err in "${errors[@]}"; do - echo " - $err" - done - echo - echo 'Please fix the above errors. You can test via "go vet" and commit the result.' - echo - } >&2 - false -fi