diff --git a/Dockerfile b/Dockerfile index edd41b1c86..cc9ae08ad6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -176,8 +176,8 @@ COPY hack/dockerfile/install/install.sh ./install.sh COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./ RUN PREFIX=/build ./install.sh $INSTALL_BINARY_NAME -FROM base AS gometalinter -ENV INSTALL_BINARY_NAME=gometalinter +FROM base AS golangci_lint +ENV INSTALL_BINARY_NAME=golangci_lint COPY hack/dockerfile/install/install.sh ./install.sh COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./ RUN PREFIX=/build ./install.sh $INSTALL_BINARY_NAME @@ -265,7 +265,7 @@ RUN pip3 install yamllint==1.16.0 COPY --from=swagger /build/swagger* /usr/local/bin/ COPY --from=frozen-images /build/ /docker-frozen-images -COPY --from=gometalinter /build/ /usr/local/bin/ +COPY --from=golangci_lint /build/ /usr/local/bin/ COPY --from=gotestsum /build/ /usr/local/bin/ COPY --from=tomlv /build/ /usr/local/bin/ COPY --from=vndr /build/ /usr/local/bin/ diff --git a/hack/dockerfile/install/golangci_lint.installer b/hack/dockerfile/install/golangci_lint.installer new file mode 100755 index 0000000000..198f8a76b2 --- /dev/null +++ b/hack/dockerfile/install/golangci_lint.installer @@ -0,0 +1,11 @@ +#!/bin/sh + +: "${GOLANGCI_LINT_COMMIT=v1.17.1}" + +install_golangci_lint() { + echo "Installing golangci-lint version ${GOLANGCI_LINT_COMMIT}" + go get -d github.com/golangci/golangci-lint/cmd/golangci-lint + cd "$GOPATH/src/github.com/golangci/golangci-lint/" || exit 1 + git checkout -q "${GOLANGCI_LINT_COMMIT}" + go build -buildmode=pie -o "${PREFIX}/golangci-lint" "github.com/golangci/golangci-lint/cmd/golangci-lint" +} diff --git a/hack/dockerfile/install/gometalinter.installer b/hack/dockerfile/install/gometalinter.installer deleted file mode 100755 index 461850f936..0000000000 --- a/hack/dockerfile/install/gometalinter.installer +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -GOMETALINTER_COMMIT=v2.0.6 - -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 -buildmode=pie -o "${PREFIX}/gometalinter" "github.com/alecthomas/gometalinter" - GOBIN=${PREFIX} "${PREFIX}/gometalinter" --install -} diff --git a/hack/validate/default b/hack/validate/default index 4266d1f82f..216c214770 100755 --- a/hack/validate/default +++ b/hack/validate/default @@ -6,7 +6,7 @@ export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" . ${SCRIPTDIR}/dco . ${SCRIPTDIR}/default-seccomp -. ${SCRIPTDIR}/gometalinter +. ${SCRIPTDIR}/golangci-lint . ${SCRIPTDIR}/pkg-imports . ${SCRIPTDIR}/swagger . ${SCRIPTDIR}/swagger-gen diff --git a/hack/validate/golangci-lint b/hack/validate/golangci-lint new file mode 100755 index 0000000000..9d9cadaffb --- /dev/null +++ b/hack/validate/golangci-lint @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -e -o pipefail + +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# CI platforms differ, so per-platform GOLANGCI_LINT_OPTS can be set +# from a platform-specific Dockerfile, otherwise let's just set +# (somewhat pessimistic) default of 10 minutes. +: ${GOLANGCI_LINT_OPTS=--deadline=20m} + +[ -n "${TESTDEBUG}" ] && set -x + +# TODO use --out-format=junit-xml and store artifacts +GOGC=20 golangci-lint run \ + ${GOLANGCI_LINT_OPTS} \ + --print-resources-usage \ + --build-tags="${DOCKER_BUILDTAGS}" \ + --verbose \ + --config ${SCRIPTDIR}/golangci-lint.yml diff --git a/hack/validate/golangci-lint.yml b/hack/validate/golangci-lint.yml new file mode 100644 index 0000000000..02bb59f05a --- /dev/null +++ b/hack/validate/golangci-lint.yml @@ -0,0 +1,31 @@ +linters: + enable: + - deadcode + - gofmt + - goimports + - golint + - gosimple + - govet + - ineffassign + - unconvert + + disable: + - errcheck + + run: + concurrency: 2 + modules-download-mode: vendor + + skip-dirs: + - docs + - integration-cli + + skip-files: + - ".*\\.pb\\.go" + - "dockerversion/version_autogen.go" + - "api/types/container/container_.*" + - "api/types/volume/volume_.*" + +linters-settings: + govet: + check-shadowing: false diff --git a/hack/validate/gometalinter b/hack/validate/gometalinter deleted file mode 100755 index 4300b67a11..0000000000 --- a/hack/validate/gometalinter +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -set -e -o pipefail - -SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# CI platforms differ, so per-platform GOMETALINTER_OPTS can be set -# in the Jenkinsfile, otherwise let's just set a -# (somewhat pessimistic) default of 10 minutes. -: "${GOMETALINTER_OPTS=--deadline=10m}" - -# shellcheck disable=SC2086 -gometalinter \ - ${GOMETALINTER_OPTS} \ - --config "${SCRIPTDIR}/gometalinter.json" ./... diff --git a/hack/validate/gometalinter.json b/hack/validate/gometalinter.json deleted file mode 100644 index e36dd73306..0000000000 --- a/hack/validate/gometalinter.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "Vendor": true, - "EnableGC": true, - "Sort": ["linter", "severity", "path"], - "Exclude": [ - ".*\\.pb\\.go", - "dockerversion/version_autogen.go", - "api/types/container/container_.*", - "api/types/volume/volume_.*", - "integration-cli/" - ], - "Skip": ["integration-cli/"], - - "Enable": [ - "deadcode", - "gofmt", - "goimports", - "golint", - "gosimple", - "ineffassign", - "unconvert", - "vet" - ], - - "LineLength": 200 -}