Skip to content

Commit

Permalink
Remove duplication around Go modules settings (#2580)
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot authored Jul 31, 2019
1 parent a58b312 commit 1df9667
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ jobs:
env:
- TEST_TYPE=unit # this is not used, just purely for nice UI distinction on Travis
- GO111MODULE=on
- GOFLAGS="-mod=vendor"
script:
- go build -mod=vendor -o out/skaffold.exe cmd/skaffold/skaffold.go
- go test -mod=vendor -short -timeout 60s ./...
- go build -o out/skaffold.exe cmd/skaffold/skaffold.go
- go test -short -timeout 60s ./...
- os: linux
env:
- TEST_TYPE=integration # this is not used, just purely for nice UI distinction on Travis
Expand Down
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
GOOS ?= $(shell go env GOOS)
GOARCH = amd64
GO111MODULE = on
BUILD_DIR ?= ./out
ORG := github.com/GoogleContainerTools
PROJECT := skaffold
Expand All @@ -39,6 +38,11 @@ ifeq "$(strip $(VERSION))" ""
override VERSION = $(shell git describe --always --tags --dirty)
endif

# Force using Go Modules and always read the dependencies from
# the `vendor` folder.
export GO111MODULE = on
export GOFLAGS = -mod=vendor

GO_GCFLAGS := "all=-trimpath=${PWD}"
GO_ASMFLAGS := "all=-trimpath=${PWD}"

Expand All @@ -50,7 +54,6 @@ GO_BUILD_TAGS_linux := "osusergo netgo static_build"
GO_BUILD_TAGS_darwin := ""
GO_BUILD_TAGS_windows := ""


GO_LDFLAGS = -X $(VERSION_PACKAGE).version=$(VERSION)
GO_LDFLAGS += -X $(VERSION_PACKAGE).buildDate=$(shell date +'%Y-%m-%dT%H:%M:%SZ')
GO_LDFLAGS += -X $(VERSION_PACKAGE).gitCommit=$(COMMIT)
Expand All @@ -66,7 +69,7 @@ $(BUILD_DIR)/$(PROJECT): $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH)
cp $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH) $@

$(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH): $(GO_FILES) $(BUILD_DIR)
GO111MODULE=$(GO111MODULE) GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go build -mod=vendor -tags $(GO_BUILD_TAGS_$(GOOS)) -ldflags $(GO_LDFLAGS_$(GOOS)) -gcflags $(GO_GCFLAGS) -asmflags $(GO_ASMFLAGS) -o $@ $(BUILD_PACKAGE)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go build -tags $(GO_BUILD_TAGS_$(GOOS)) -ldflags $(GO_LDFLAGS_$(GOOS)) -gcflags $(GO_GCFLAGS) -asmflags $(GO_ASMFLAGS) -o $@ $(BUILD_PACKAGE)

$(BUILD_DIR)/$(PROJECT)-%-$(GOARCH): $(GO_FILES) $(BUILD_DIR)
docker build --build-arg PROJECT=$(REPOPATH) \
Expand Down Expand Up @@ -96,15 +99,15 @@ cross: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(pla

.PHONY: test
test: $(BUILD_DIR)
@ GO111MODULE=$(GO111MODULE) ./hack/test.sh
@ ./hack/test.sh

.PHONY: quicktest
quicktest:
GO111MODULE=$(GO111MODULE) go test -mod=vendor -short -timeout=60s ./...
go test -short -timeout=60s ./...

.PHONY: install
install: $(GO_FILES) $(BUILD_DIR)
GO111MODULE=$(GO111MODULE) GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go install -mod=vendor -tags $(GO_BUILD_TAGS_$(GOOS)) -ldflags $(GO_LDFLAGS_$(GOOS)) -gcflags $(GO_GCFLAGS) -asmflags $(GO_ASMFLAGS) $(BUILD_PACKAGE)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go install -tags $(GO_BUILD_TAGS_$(GOOS)) -ldflags $(GO_LDFLAGS_$(GOOS)) -gcflags $(GO_GCFLAGS) -asmflags $(GO_ASMFLAGS) $(BUILD_PACKAGE)

.PHONY: integration
integration: install
Expand All @@ -115,7 +118,7 @@ ifeq ($(GCP_ONLY),true)
--project $(GCP_PROJECT)
endif
kubectl get nodes -oyaml
GO111MODULE=$(GO111MODULE) GCP_ONLY=$(GCP_ONLY) go test -mod=vendor -v $(REPOPATH)/integration -timeout 20m $(INTEGRATION_TEST_ARGS)
GCP_ONLY=$(GCP_ONLY) go test -v $(REPOPATH)/integration -timeout 20m $(INTEGRATION_TEST_ARGS)

.PHONY: release
release: cross $(BUILD_DIR)/VERSION
Expand Down
1 change: 0 additions & 1 deletion deploy/webhook/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ COPY --from=download-hugo /hugo /usr/local/bin/
COPY --from=download-kubectl /kubectl /usr/local/bin/

FROM golang:1.12 as webhook
ENV GO111MODULE on
WORKDIR /skaffold
COPY . .
RUN go build -mod=vendor -o /webhook webhook/webhook.go
Expand Down
2 changes: 1 addition & 1 deletion hack/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ GREEN='\033[0;32m'
RESET='\033[0m'

echo "Running go tests..."
go test -mod=vendor -count=1 -race -cover -short -timeout=60s -coverprofile=out/coverage.txt -coverpkg="./pkg/...,./cmd/..." ./... | awk -v FAIL="${RED}FAIL${RESET}" '! /no test files/ { gsub("FAIL", FAIL, $0); print $0 }'
go test -count=1 -race -cover -short -timeout=60s -coverprofile=out/coverage.txt -coverpkg="./pkg/...,./cmd/..." ./... | awk -v FAIL="${RED}FAIL${RESET}" '! /no test files/ { gsub("FAIL", FAIL, $0); print $0 }'

GO_TEST_EXIT_CODE=${PIPESTATUS[0]}
if [[ $GO_TEST_EXIT_CODE -ne 0 ]]; then
Expand Down

0 comments on commit 1df9667

Please sign in to comment.