From 51b05085125c6b9626ce7b14a38a3c434bb08f9f Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 11 Aug 2019 12:20:53 +0200 Subject: [PATCH] scripts: makefile, dockerfile, travis, ... --- .golangci.toml | 2 +- .goreleaser.yml | 22 +++++------ .semaphoreci/setup.sh | 11 ++++-- .travis.yml | 7 ++-- Makefile | 11 +----- build.Dockerfile | 38 ++++++++++--------- exp.Dockerfile | 6 +++ script/binary | 6 +-- script/make.sh | 3 ++ script/prune-dep.sh | 59 ----------------------------- script/update-generated-crd-code.sh | 14 ++++--- script/validate-vendor | 25 +++--------- 12 files changed, 71 insertions(+), 133 deletions(-) delete mode 100755 script/prune-dep.sh diff --git a/.golangci.toml b/.golangci.toml index bdbe5c3b0..a7c6ad4e7 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -65,7 +65,7 @@ text = "Error return value of `rw.Write` is not checked" [[issues.exclude-rules]] path = "pkg/middlewares/recovery/recovery.go" - text = "`logger` can be `github.com/containous/traefik/vendor/github.com/stretchr/testify/assert.TestingT`" + text = "`logger` can be `github.com/stretchr/testify/assert.TestingT`" [[issues.exclude-rules]] path = "pkg/provider/docker/builder_test.go" text = "(U1000: func )?`(.+)` is unused" diff --git a/.goreleaser.yml b/.goreleaser.yml index b21524285..95086aeb3 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -11,7 +11,7 @@ builds: env: - CGO_ENABLED=0 ldflags: - - -s -w -X github.com/containous/traefik/pkg/version.Version={{.Version}} -X github.com/containous/traefik/pkg/version.Codename={{.Env.CODENAME}} -X github.com/containous/traefik/pkg/version.BuildDate={{.Date}} + - -s -w -X github.com/containous/traefik/v2/pkg/version.Version={{.Version}} -X github.com/containous/traefik/v2/pkg/version.Codename={{.Env.CODENAME}} -X github.com/containous/traefik/v2/pkg/version.BuildDate={{.Date}} goos: - linux @@ -40,16 +40,16 @@ builds: changelog: skip: true -archive: - name_template: '{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm - }}v{{ .Arm }}{{ end }}' - format: tar.gz - format_overrides: - - goos: windows - format: zip - files: - - LICENSE.md - - CHANGELOG.md +archives: + - id: traefik + name_template: '{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' + format: tar.gz + format_overrides: + - goos: windows + format: zip + files: + - LICENSE.md + - CHANGELOG.md checksum: name_template: "{{ .ProjectName }}_v{{ .Version }}_checksums.txt" diff --git a/.semaphoreci/setup.sh b/.semaphoreci/setup.sh index af0878c0e..b79415769 100755 --- a/.semaphoreci/setup.sh +++ b/.semaphoreci/setup.sh @@ -1,6 +1,6 @@ -#!/usr/bin/env bash -set -e - +# For personnal CI +# mv /home/runner/workspace/src/github.com// /home/runner/workspace/src/github.com/containous/ +# cd /home/runner/workspace/src/github.com/containous/traefik/ for s in apache2 cassandra elasticsearch memcached mysql mongod postgresql sphinxsearch rethinkdb rabbitmq-server redis-server; do sudo service $s stop; done sudo swapoff -a sudo dd if=/dev/zero of=/swapfile bs=1M count=3072 @@ -20,3 +20,8 @@ if [ -n "$SHOULD_TEST" ]; then docker version; fi if [ -f "./.semaphoreci/golang.sh" ]; then ./.semaphoreci/golang.sh; fi if [ -f "./.semaphoreci/golang.sh" ]; then export GOROOT="/usr/local/golang/1.12/go"; fi if [ -f "./.semaphoreci/golang.sh" ]; then export GOTOOLDIR="/usr/local/golang/1.12/go/pkg/tool/linux_amd64"; fi +if [ -f "./go.mod" ]; then export GO111MODULE=on; fi +if [ -f "./go.mod" ]; then export GOPROXY=https://proxy.golang.org; fi +if [ -f "./go.mod" ]; then go mod download; fi +sudo rm -rf /usr/local/golang/1.4.3/ /usr/local/golang/1.5.4/ /usr/local/golang/1.6.4 /usr/local/golang/1.7.6 /usr/local/golang/1.8.6 /usr/local/golang/1.9.7 /usr/local/golang/1.10.3 +df diff --git a/.travis.yml b/.travis.yml index 45c8eb33e..bfdb99a3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,9 +9,10 @@ services: env: global: - - REPO: $TRAVIS_REPO_SLUG - - VERSION: $TRAVIS_TAG - - CODENAME: faisselle + - REPO=$TRAVIS_REPO_SLUG + - VERSION=$TRAVIS_TAG + - CODENAME=faisselle + - GO111MODULE=on script: - echo "Skipping tests... (Tests are executed on SemaphoreCI)" diff --git a/Makefile b/Makefile index 08d1abeb4..daf2cbae3 100644 --- a/Makefile +++ b/Makefile @@ -128,15 +128,6 @@ docs-serve: generate-crd: ./script/update-generated-crd-code.sh -## Download dependencies -dep-ensure: - dep ensure -v - ./script/prune-dep.sh - -## Clean vendor directory -dep-prune: - ./script/prune-dep.sh - ## Create packages for the release release-packages: generate-webui build-dev-image rm -rf dist @@ -156,5 +147,5 @@ fmt: run-dev: go generate - go build ./cmd/traefik + GO111MODULE=on go build ./cmd/traefik ./traefik diff --git a/build.Dockerfile b/build.Dockerfile index c3ff44b5f..f5b3c4323 100644 --- a/build.Dockerfile +++ b/build.Dockerfile @@ -5,31 +5,33 @@ RUN apk --update upgrade \ && update-ca-certificates \ && rm -rf /var/cache/apk/* -# Download golangci-lint and misspell binary to bin folder in $GOPATH -RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.17.1 \ - && go get github.com/client9/misspell/cmd/misspell - -# Download goreleaser binary to bin folder in $GOPATH -RUN curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh - # Which docker version to test on ARG DOCKER_VERSION=18.09.7 -ARG DEP_VERSION=0.5.4 - -# Download go-bindata binary to bin folder in $GOPATH -RUN mkdir -p /usr/local/bin \ - && curl -fsSL -o /usr/local/bin/go-bindata https://github.com/containous/go-bindata/releases/download/v1.0.0/go-bindata \ - && chmod +x /usr/local/bin/go-bindata - -# Download dep binary to bin folder in $GOPATH -RUN mkdir -p /usr/local/bin \ - && curl -fsSL -o /usr/local/bin/dep https://github.com/golang/dep/releases/download/v${DEP_VERSION}/dep-linux-amd64 \ - && chmod +x /usr/local/bin/dep # Download docker RUN mkdir -p /usr/local/bin \ && curl -fL https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VERSION}.tgz \ | tar -xzC /usr/local/bin --transform 's#^.+/##x' +# Download go-bindata binary to bin folder in $GOPATH +RUN mkdir -p /usr/local/bin \ + && curl -fsSL -o /usr/local/bin/go-bindata https://github.com/containous/go-bindata/releases/download/v1.0.0/go-bindata \ + && chmod +x /usr/local/bin/go-bindata + +# Download golangci-lint binary to bin folder in $GOPATH +RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.17.1 + +# Download golangci-lint and misspell binary to bin folder in $GOPATH +RUN GO111MODULE=off go get github.com/client9/misspell/cmd/misspell + +# Download goreleaser binary to bin folder in $GOPATH +RUN curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh + WORKDIR /go/src/github.com/containous/traefik + +# Download go modules +COPY go.mod . +COPY go.sum . +RUN GO111MODULE=on GOPROXY=https://proxy.golang.org go mod download + COPY . /go/src/github.com/containous/traefik diff --git a/exp.Dockerfile b/exp.Dockerfile index 3b8801cf2..ecee5414f 100644 --- a/exp.Dockerfile +++ b/exp.Dockerfile @@ -24,6 +24,12 @@ RUN mkdir -p /usr/local/bin \ && chmod +x /usr/local/bin/go-bindata WORKDIR /go/src/github.com/containous/traefik + +# Download go modules +COPY go.mod . +COPY go.sum . +RUN GO111MODULE=on GOPROXY=https://proxy.golang.org go mod download + COPY . /go/src/github.com/containous/traefik RUN rm -rf /go/src/github.com/containous/traefik/static/ diff --git a/script/binary b/script/binary index 40bf4f941..82c6ebe3b 100755 --- a/script/binary +++ b/script/binary @@ -28,7 +28,7 @@ fi # Build binaries # shellcheck disable=SC2086 CGO_ENABLED=0 GOGC=off go build ${FLAGS[*]} -ldflags "-s -w \ - -X github.com/containous/traefik/pkg/version.Version=$VERSION \ - -X github.com/containous/traefik/pkg/version.Codename=$CODENAME \ - -X github.com/containous/traefik/pkg/version.BuildDate=$DATE" \ + -X github.com/containous/traefik/pkg/v2/version.Version=$VERSION \ + -X github.com/containous/traefik/pkg/v2/version.Codename=$CODENAME \ + -X github.com/containous/traefik/pkg/v2/version.BuildDate=$DATE" \ -a -installsuffix nocgo -o dist/traefik ./cmd/traefik diff --git a/script/make.sh b/script/make.sh index cad63e6d4..6f670ff3b 100755 --- a/script/make.sh +++ b/script/make.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash set -e +export GO111MODULE=on +export GOPROXY=https://proxy.golang.org + # List of bundles to create when no argument is passed DEFAULT_BUNDLES=( generate diff --git a/script/prune-dep.sh b/script/prune-dep.sh deleted file mode 100755 index 2653b5adc..000000000 --- a/script/prune-dep.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -set -o pipefail -set -o nounset - -echo "Prune dependencies" - -find vendor -name '*_test.go' -exec rm {} \; - -find vendor -type f \( ! -iname 'licen[cs]e*' \ - -a ! -iname '*notice*' \ - -a ! -iname '*patent*' \ - -a ! -iname '*copying*' \ - -a ! -iname '*unlicense*' \ - -a ! -iname '*copyright*' \ - -a ! -iname '*copyleft*' \ - -a ! -iname '*legal*' \ - -a ! -iname 'disclaimer*' \ - -a ! -iname 'third-party*' \ - -a ! -iname 'thirdparty*' \ - -a ! -iname '*.go' \ - -a ! -iname '*.c' \ - -a ! -iname '*.s' \ - -a ! -iname '*.pl' \ - -a ! -iname '*.cc' \ - -a ! -iname '*.cpp' \ - -a ! -iname '*.cxx' \ - -a ! -iname '*.h' \ - -a ! -iname '*.hh' \ - -a ! -iname '*.hpp' \ - -a ! -iname '*.hxx' \ - -a ! -wholename 'vendor/k8s.io/code-generator/*' \ - -a ! -iname '*.s' \) -exec rm -f {} + - -find . -type d \( -iname '*Godeps*' \) -exec rm -rf {} + - -find vendor -type l \( ! -iname 'licen[cs]e*' \ - -a ! -iname '*notice*' \ - -a ! -iname '*patent*' \ - -a ! -iname '*copying*' \ - -a ! -iname '*unlicense*' \ - -a ! -iname '*copyright*' \ - -a ! -iname '*copyleft*' \ - -a ! -iname '*legal*' \ - -a ! -iname 'disclaimer*' \ - -a ! -iname 'third-party*' \ - -a ! -iname 'thirdparty*' \ - -a ! -iname '*.go' \ - -a ! -iname '*.c' \ - -a ! -iname '*.S' \ - -a ! -iname '*.cc' \ - -a ! -iname '*.cpp' \ - -a ! -iname '*.cxx' \ - -a ! -iname '*.h' \ - -a ! -iname '*.hh' \ - -a ! -iname '*.hpp' \ - -a ! -iname '*.hxx' \ - -a ! -iname '*.s' \) -exec rm -f {} + diff --git a/script/update-generated-crd-code.sh b/script/update-generated-crd-code.sh index 25b40b204..81dbee5ad 100755 --- a/script/update-generated-crd-code.sh +++ b/script/update-generated-crd-code.sh @@ -2,6 +2,7 @@ HACK_DIR="$( cd "$( dirname "${0}" )" && pwd -P)"; export HACK_DIR REPO_ROOT=${HACK_DIR}/.. +TRAEFIK_MODULE_VERSION=v2 rm -rf "${REPO_ROOT}"/vendor go mod vendor @@ -9,16 +10,19 @@ chmod +x "${REPO_ROOT}"/vendor/k8s.io/code-generator/*.sh "${REPO_ROOT}"/vendor/k8s.io/code-generator/generate-groups.sh \ all \ - github.com/containous/traefik/pkg/provider/kubernetes/crd/generated \ - github.com/containous/traefik/pkg/provider/kubernetes/crd \ + github.com/containous/traefik/${TRAEFIK_MODULE_VERSION}/pkg/provider/kubernetes/crd/generated \ + github.com/containous/traefik/${TRAEFIK_MODULE_VERSION}/pkg/provider/kubernetes/crd \ traefik:v1alpha1 \ --go-header-file "${HACK_DIR}"/boilerplate.go.tmpl \ "$@" deepcopy-gen \ ---input-dirs github.com/containous/traefik/pkg/config/dynamic \ ---input-dirs github.com/containous/traefik/pkg/tls \ ---input-dirs github.com/containous/traefik/pkg/types \ +--input-dirs github.com/containous/traefik/${TRAEFIK_MODULE_VERSION}/pkg/config/dynamic \ +--input-dirs github.com/containous/traefik/${TRAEFIK_MODULE_VERSION}/pkg/tls \ +--input-dirs github.com/containous/traefik/${TRAEFIK_MODULE_VERSION}/pkg/types \ +--output-package github.com/containous/traefik \ -O zz_generated.deepcopy --go-header-file "${HACK_DIR}"/boilerplate.go.tmpl +cp -r "${REPO_ROOT}"/"${TRAEFIK_MODULE_VERSION:?}"/* "${REPO_ROOT}"; rm -rf "${REPO_ROOT}"/"${TRAEFIK_MODULE_VERSION:?}" + rm -rf "${REPO_ROOT}"/vendor diff --git a/script/validate-vendor b/script/validate-vendor index 580ca7253..8c9b0815e 100755 --- a/script/validate-vendor +++ b/script/validate-vendor @@ -4,26 +4,11 @@ set -o pipefail set -o nounset SCRIPT_DIR="$( cd "$( dirname "${0}" )" && pwd -P)"; export SCRIPT_DIR -vendor_dir="./vendor/" -# We run dep install to and see if we have a diff afterwards -echo "checking ${vendor_dir} for unintentional changes..." +echo "checking go modules for unintentional changes..." -dep ensure -v -("${SCRIPT_DIR}"/prune-dep.sh) +go mod tidy +git diff --exit-code go.mod +git diff --exit-code go.sum -# Let see if the working directory is clean -diffs="$(git status --porcelain -- ${vendor_dir} 2>/dev/null)" -if [[ "$diffs" ]]; then - { - echo "The result of 'dep ensure' for vendor directory '${vendor_dir}' differs" - echo - echo "$diffs" - echo - echo 'Please vendor your package(s) with dep.' - echo - } >&2 - exit 2 -fi - -echo 'Congratulations! All vendoring changes are done the right way.' +echo 'Congratulations! All go modules changes are done the right way.'