diff --git a/Makefile b/Makefile index e3833630e76..4e7fe6fc8c4 100644 --- a/Makefile +++ b/Makefile @@ -14,8 +14,8 @@ GOOS ?= $(shell go env GOOS) GOARCH = amd64 BUILD_DIR ?= ./out -ORG := github.com/GoogleContainerTools -PROJECT := skaffold +ORG = github.com/GoogleContainerTools +PROJECT = skaffold REPOPATH ?= $(ORG)/$(PROJECT) RELEASE_BUCKET ?= $(PROJECT) GSC_BUILD_PATH ?= gs://$(RELEASE_BUCKET)/builds/$(COMMIT) @@ -28,10 +28,11 @@ GCP_PROJECT ?= k8s-skaffold GKE_CLUSTER_NAME ?= integration-tests GKE_ZONE ?= us-central1-a -SUPPORTED_PLATFORMS := linux-$(GOARCH) darwin-$(GOARCH) windows-$(GOARCH).exe +SUPPORTED_PLATFORMS = linux-$(GOARCH) darwin-$(GOARCH) windows-$(GOARCH).exe BUILD_PACKAGE = $(REPOPATH)/cmd/skaffold -SKAFFOLD_TEST_PACKAGES := $(shell go list ./... | grep -v diag) +SKAFFOLD_TEST_PACKAGES = $(shell go list ./... | grep -v diag) +GO_FILES = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./pkg/diag/*") VERSION_PACKAGE = $(REPOPATH)/pkg/skaffold/version COMMIT = $(shell git rev-parse HEAD) @@ -45,16 +46,13 @@ endif export GO111MODULE = on export GOFLAGS = -mod=vendor -GO_GCFLAGS := "all=-trimpath=${PWD}" -GO_ASMFLAGS := "all=-trimpath=${PWD}" - LDFLAGS_linux = -static LDFLAGS_darwin = LDFLAGS_windows = -GO_BUILD_TAGS_linux := "osusergo netgo static_build release" -GO_BUILD_TAGS_darwin := "release" -GO_BUILD_TAGS_windows := "release" +GO_BUILD_TAGS_linux = "osusergo netgo static_build release" +GO_BUILD_TAGS_darwin = "release" +GO_BUILD_TAGS_windows = "release" GO_LDFLAGS = -X $(VERSION_PACKAGE).version=$(VERSION) GO_LDFLAGS += -X $(VERSION_PACKAGE).buildDate=$(shell date +'%Y-%m-%dT%H:%M:%SZ') @@ -66,16 +64,23 @@ GO_LDFLAGS_windows =" $(GO_LDFLAGS) -extldflags \"$(LDFLAGS_windows)\"" GO_LDFLAGS_darwin =" $(GO_LDFLAGS) -extldflags \"$(LDFLAGS_darwin)\"" GO_LDFLAGS_linux =" $(GO_LDFLAGS) -extldflags \"$(LDFLAGS_linux)\"" -GO_FILES := $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./pkg/diag/*") -DEPS_DIGEST := $(shell ./hack/skaffold-deps-sha1.sh) +STATIK_FILES = cmd/skaffold/app/cmd/statik/statik.go + +# Build for local development. +$(BUILD_DIR)/$(PROJECT): $(STATIK_FILES) $(GO_FILES) $(BUILD_DIR) + GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go build -tags $(GO_BUILD_TAGS_$(GOOS)) -ldflags $(GO_LDFLAGS_$(GOOS)) -o $@ $(BUILD_PACKAGE) + +.PHONY: install +install: $(BUILD_DIR)/$(PROJECT) + cp $(BUILD_DIR)/$(PROJECT) $(GOPATH)/bin/$(PROJECT) -$(BUILD_DIR)/$(PROJECT): $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH) - cp $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH) $@ +# Build for a release. +.PRECIOUS: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform)) -$(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH): generate-statik $(GO_FILES) $(BUILD_DIR) - 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) +.PHONY: cross +cross: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform).sha256) -$(BUILD_DIR)/$(PROJECT)-%-$(GOARCH): generate-statik $(GO_FILES) $(BUILD_DIR) +$(BUILD_DIR)/$(PROJECT)-%-$(GOARCH): $(STATIK_FILES) $(GO_FILES) $(BUILD_DIR) docker build \ --build-arg PROJECT=$(REPOPATH) \ --build-arg TARGETS=$*/$(GOARCH) \ @@ -99,11 +104,6 @@ $(BUILD_DIR)/VERSION: $(BUILD_DIR) $(BUILD_DIR): mkdir -p $(BUILD_DIR) -.PRECIOUS: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform)) - -.PHONY: cross -cross: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform).sha256) - .PHONY: test test: $(BUILD_DIR) @ ./hack/gotest.sh -count=1 -race -short -timeout=90s $(SKAFFOLD_TEST_PACKAGES) @@ -122,12 +122,8 @@ checks: $(BUILD_DIR) quicktest: @ ./hack/gotest.sh -short -timeout=60s $(SKAFFOLD_TEST_PACKAGES) -.PHONY: install -install: $(GO_FILES) $(BUILD_DIR) - 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: generate-statik install +integration: install ifeq ($(GCP_ONLY),true) gcloud container clusters get-credentials \ $(GKE_CLUSTER_NAME) \ @@ -166,6 +162,7 @@ clean: .PHONY: build_deps build_deps: + $(eval DEPS_DIGEST := $(shell ./hack/skaffold-deps-sha1.sh)) docker build \ -f deploy/skaffold/Dockerfile.deps \ -t gcr.io/$(GCP_PROJECT)/build_deps:$(DEPS_DIGEST) \ @@ -243,6 +240,7 @@ build-docs-preview: generate-schemas: go run hack/schemas/main.go -.PHONY: generate-statik -generate-statik: +# static files + +$(STATIK_FILES): go.mod docs/content/en/schemas/* hack/generate-statik.sh diff --git a/deploy/skaffold/Dockerfile b/deploy/skaffold/Dockerfile index 8906341c250..5d7965be857 100644 --- a/deploy/skaffold/Dockerfile +++ b/deploy/skaffold/Dockerfile @@ -19,5 +19,5 @@ COPY . . FROM builder as release ARG VERSION -RUN make clean && make out/skaffold-linux-amd64 VERSION=$VERSION && mv out/skaffold-linux-amd64 /usr/bin/skaffold +RUN make clean out/skaffold VERSION=$VERSION && mv out/skaffold /usr/bin/skaffold RUN skaffold credits -d /THIRD_PARTY_NOTICES