Skip to content

Commit

Permalink
Migrate to Go modules (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
liranbg authored Apr 5, 2020
1 parent 5e5378c commit 73a2108
Show file tree
Hide file tree
Showing 7,815 changed files with 280 additions and 2,689,549 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*

!go.mod
!go.sum

!cmd/
!pkg/
!vendor/
!test/

**/Dockerfile
36 changes: 36 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
linters:
disable-all: true
enable:
- deadcode
- goconst
- gofmt
- golint
- gosimple
- ineffassign
- interfacer
- misspell
- staticcheck
- unconvert
- varcheck
- vet
- vetshadow
- errcheck

run:

# timeout for analysis
timeout: 5m

# include test files or not, default is true
tests: false

skip-dirs:
- test

issues:

# List of regexps of issue texts to exclude
exclude:
- "comment on"
- "error should be the last"
- "should have comment"
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ addons:

language: go
go_import_path: github.com/v3io/scaler
go: "1.11"
go: "1.14"

cache:
directories:
- $GOPATH/pkg/mod

script:
- go get github.com/v3io/scaler-types
- make lint test

after_success:
Expand Down
76 changes: 24 additions & 52 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
GO_VERSION := $(shell go version | cut -d " " -f 3)
GOPATH ?= $(shell go env GOPATH)
OS_NAME = $(shell uname)

Expand All @@ -8,7 +7,7 @@ SCALER_DEFAULT_ARCH := $(shell go env GOARCH)

ifeq ($(OS_NAME), Linux)
SCALER_DEFAULT_TEST_HOST := $(shell docker network inspect bridge | grep "Gateway" | grep -o '"[^"]*"$$')
# On EC2 we don't have gateway, use default
# On EC2 we don't have gateway, use default
ifeq ($(SCALER_DEFAULT_TEST_HOST),)
SCALER_DEFAULT_TEST_HOST := "172.17.0.1"
endif
Expand All @@ -32,6 +31,9 @@ DLX_DOCKER_REPO = quay.io/v3io/dlx
# Docker build
#

.PHONY: docker-images
docker-images: autoscaler-onbuild dlx-onbuild

.PHONY: autoscaler-onbuild
autoscaler-onbuild:
@echo Building autoscaler-onbuild
Expand All @@ -42,9 +44,6 @@ dlx-onbuild:
@echo Building dlx-onbuild
docker build -f cmd/dlx/Dockerfile -t $(DLX_DOCKER_REPO):$(SCALER_LABEL) .

.PHONY: docker-images
docker-images: autoscaler-onbuild dlx-onbuild

.PHONY: push-docker-images
push-docker-images:
@echo Pushing images
Expand All @@ -56,77 +55,45 @@ push-docker-images:
#

# tools get built with the specified OS/arch and inject version
GO_BUILD_TOOL_WORKDIR = /go/src/github.com/v3io/scaler
GO_BUILD_TOOL = docker run \
--volume $(shell pwd):$(GO_BUILD_TOOL_WORKDIR) \
--volume $(shell pwd)/../logger:$(GO_BUILD_TOOL_WORKDIR)/../logger \
--volume $(GOPATH)/bin:/go/bin \
--workdir $(GO_BUILD_TOOL_WORKDIR) \
--env GOOS=$(SCALER_OS) \
--env GOARCH=$(SCALER_ARCH) \
golang:1.10 \
go build -a \
-installsuffix cgo \
-ldflags="$(GO_LINK_FLAGS_INJECT_VERSION)"

GO_BUILD_TOOL_WORKDIR = /scaler

.PHONY: lint
lint:
lint: modules
@echo Installing linters...
go get -u github.com/pavius/impi/cmd/impi
go get -u gopkg.in/alecthomas/gometalinter.v2
@$(GOPATH)/bin/gometalinter.v2 --install
@test -e $(GOPATH)/bin/impi || \
curl -s https://api.github.com/repos/pavius/impi/releases/latest \
| grep -i "browser_download_url.*impi.*$(OS_NAME)" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget -O $(GOPATH)/bin/impi -qi -
@test -e $(GOPATH)/bin/golangci-lint || \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.24.0

@echo Verifying imports...
$(GOPATH)/bin/impi \
chmod +x $(GOPATH)/bin/impi && $(GOPATH)/bin/impi \
--local github.com/v3io/scaler/ \
--scheme stdLocalThirdParty \
--skip pkg/platform/kube/apis \
--skip pkg/platform/kube/client \
./cmd/... ./pkg/...

@echo Linting...
@$(GOPATH)/bin/gometalinter.v2 \
--deadline=300s \
--disable-all \
--enable-gc \
--enable=deadcode \
--enable=goconst \
--enable=gofmt \
--enable=golint \
--enable=gosimple \
--enable=ineffassign \
--enable=interfacer \
--enable=misspell \
--enable=staticcheck \
--enable=unconvert \
--enable=varcheck \
--enable=vet \
--enable=vetshadow \
--enable=errcheck \
--exclude="_test.go" \
--exclude="comment on" \
--exclude="error should be the last" \
--exclude="should have comment" \
--skip=pkg/platform/kube/apis \
--skip=pkg/platform/kube/client \
./cmd/... ./pkg/...

$(GOPATH)/bin/golangci-lint run -v
@echo Done.

.PHONY: test-undockerized
test-undockerized: ensure-gopath
test-undockerized: modules
go test -v ./pkg/... -p 1

.PHONY: test
test: ensure-gopath
test:
docker build --file $(SCALER_DOCKER_TEST_DOCKERFILE_PATH) \
--tag $(SCALER_DOCKER_TEST_TAG) .

docker run --rm --volume /var/run/docker.sock:/var/run/docker.sock \
--volume $(shell pwd):$(GO_BUILD_TOOL_WORKDIR) \
--volume /tmp:/tmp \
--workdir /go/src/github.com/v3io/scaler \
--workdir $(GO_BUILD_TOOL_WORKDIR) \
--env SCALER_TEST_HOST=$(SCALER_TEST_HOST) \
$(SCALER_DOCKER_TEST_TAG) \
/bin/bash -c "make test-undockerized"
Expand All @@ -136,3 +103,8 @@ ensure-gopath:
ifndef GOPATH
$(error GOPATH must be set)
endif

.PHONY: modules
modules: ensure-gopath
@echo Getting go modules
@go mod download
17 changes: 11 additions & 6 deletions cmd/autoscaler/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
FROM golang:1.10-alpine3.7
FROM golang:1.14-alpine3.11 AS builder

RUN apk --update --no-cache add \
git \
gcc \
musl-dev

WORKDIR /go/src/github.com/v3io/scaler
WORKDIR /autoscaler

COPY go.mod go.sum ./

RUN go mod download

COPY . .

RUN go get github.com/v3io/scaler-types
RUN GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-s -w" -o autoscaler cmd/autoscaler/main.go

FROM alpine:3.11

RUN mkdir -p /home/v3io/bin \
&& GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-s -w" -o /home/v3io/bin/autoscaler cmd/autoscaler/main.go \
&& rm -rf /go/src/github/v3io/scaler
COPY --from=builder /autoscaler/autoscaler /home/v3io/bin/autoscaler
7 changes: 6 additions & 1 deletion cmd/autoscaler/app/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ func Run(kubeconfigPath string,
func createAutoScaler(restConfig *rest.Config,
resourceScaler scaler_types.ResourceScaler,
options scaler_types.AutoScalerOptions) (*autoscaler.Autoscaler, error) {
rootLogger, err := nucliozap.NewNuclioZap("scaler", "console", os.Stdout, os.Stderr, nucliozap.DebugLevel)
rootLogger, err := nucliozap.NewNuclioZap("scaler",
"console",
nil,
os.Stdout,
os.Stderr,
nucliozap.DebugLevel)
if err != nil {
return nil, errors.Wrap(err, "Failed to initialize root logger")
}
Expand Down
17 changes: 11 additions & 6 deletions cmd/dlx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
FROM golang:1.10-alpine3.7
FROM golang:1.14-alpine3.11 AS builder

RUN apk --update --no-cache add \
git \
gcc \
musl-dev

WORKDIR /go/src/github.com/v3io/scaler
WORKDIR /dlx

COPY go.mod go.sum ./

RUN go mod download

COPY . .

RUN go get github.com/v3io/scaler-types
RUN GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-s -w" -o dlx cmd/dlx/main.go

FROM alpine:3.11

RUN mkdir -p /home/v3io/bin \
&& GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-s -w" -o /home/v3io/bin/dlx cmd/dlx/main.go \
&& rm -rf /go/src/github/v3io/scaler
COPY --from=builder /dlx/dlx /home/v3io/bin/dlx
7 changes: 6 additions & 1 deletion cmd/dlx/app/dlx.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ func Run(kubeconfigPath string,
}

func createDLX(resourceScaler scaler_types.ResourceScaler, options scaler_types.DLXOptions) (*dlx.DLX, error) {
rootLogger, err := nucliozap.NewNuclioZap("scaler", "console", os.Stdout, os.Stderr, nucliozap.DebugLevel)
rootLogger, err := nucliozap.NewNuclioZap("scaler",
"console",
nil,
os.Stdout,
os.Stderr,
nucliozap.DebugLevel)
if err != nil {
return nil, errors.Wrap(err, "Failed to initialize root logger")
}
Expand Down
39 changes: 39 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module github.com/v3io/scaler

go 1.14

require (
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gogo/protobuf v1.2.1 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/golang/protobuf v1.3.5 // indirect
github.com/googleapis/gnostic v0.4.1 // indirect
github.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/json-iterator/go v1.1.7 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/nuclio/errors v0.0.2
github.com/nuclio/logger v0.0.1
github.com/nuclio/zap v0.0.2
github.com/pavius/zap v1.4.2-0.20180228181622-8d52692529b8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/pflag v1.0.3 // indirect
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.5.1
github.com/v3io/scaler-types v1.5.0
go.uber.org/atomic v1.4.0 // indirect
go.uber.org/multierr v1.1.0 // indirect
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
k8s.io/api v0.0.0-20180713172427-0f11257a8a25 // indirect
k8s.io/apimachinery v0.0.0-20180619225948-e386b2658ed2
k8s.io/client-go v7.0.0+incompatible
k8s.io/metrics v0.0.0-20190116212108-c656f2547d11
)
Loading

0 comments on commit 73a2108

Please sign in to comment.