Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile improvements #3369

Merged
merged 5 commits into from
Sep 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 65 additions & 53 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

all: kops

DOCKER_REGISTRY?=gcr.io/must-override
S3_BUCKET?=s3://must-override/
Expand All @@ -22,10 +21,16 @@ LATEST_FILE?=latest-ci.txt
GOPATH_1ST=$(shell go env | grep GOPATH | cut -f 2 -d \")
UNIQUE:=$(shell date +%s)
GOVERSION=1.8.3
BUILD=$(GOPATH_1ST)/src/k8s.io/kops/.build
LOCAL=$(BUILD)/local
BINDATA_TARGETS=upup/models/bindata.go federation/model/bindata.go
BUILD=${GOPATH_1ST}/src/k8s.io/kops/.build
ARTIFACTS=$(BUILD)/artifacts
DIST=$(BUILD)/dist
GOBINDATA=$(LOCAL)/go-bindata
NODEUP=$(LOCAL)/nodeup
UID:=$(shell id -u)
GID:=$(shell id -g)
TESTABLE_PACKAGES:=$(shell go list ./... | egrep -v "k8s.io/kops/cloudmock|k8s.io/kops/vendor")

# See http://stackoverflow.com/questions/18136918/how-to-get-current-relative-directory-of-your-makefile
MAKEDIR:=$(strip $(shell dirname "$(realpath $(lastword $(MAKEFILE_LIST)))"))
Expand All @@ -36,8 +41,9 @@ DNS_CONTROLLER_TAG=1.7.1
KOPS_RELEASE_VERSION = 1.7.1-beta.2
KOPS_CI_VERSION = 1.7.1-beta.3

# kops install location
KOPS = ${GOPATH_1ST}/bin/kops
# kops local location
KOPS = ${LOCAL}/kops

# kops source root directory (without trailing /)
KOPS_ROOT ?= $(patsubst %/,%,$(abspath $(dir $(firstword $(MAKEFILE_LIST)))))

Expand Down Expand Up @@ -84,6 +90,9 @@ ifndef SHASUMCMD
$(error "Neither sha1sum nor shasum command is available")
endif

.PHONY: all
all: ${KOPS}

.PHONY: help
help: # Show this help
@{ \
Expand Down Expand Up @@ -113,24 +122,35 @@ help: # Show this help

.PHONY: clean
clean: # Remove build directory and bindata-generated files
for t in ${BINDATA_TARGETS}; do if test -e $$t; then rm -f $$t; fi; done
if test -e ${BUILD}; then rm -rf ${BUILD}; fi
for t in ${BINDATA_TARGETS}; do if test -e $$t; then rm -fv $$t; fi; done
if test -e ${BUILD}; then rm -rfv ${BUILD}; fi

.PHONY: install
install: ${KOPS}
cp ${KOPS} ${GOPATH_1ST}/bin
cp ${NODEUP} ${GOPATH_1ST}/bin

kops: kops-gobindata # Install kops
go install ${EXTRA_BUILDFLAGS} -ldflags "-X k8s.io/kops.Version=${VERSION} -X k8s.io/kops.GitVersion=${GITSHA} ${EXTRA_LDFLAGS}" k8s.io/kops/cmd/kops/...
.PHONY: kops
kops: ${KOPS}

.PHONY: gobindata-tools
gobindata-tool:
go build ${EXTRA_BUILDFLAGS} -ldflags "${EXTRA_LDFLAGS}" -o ${GOPATH_1ST}/bin/go-bindata k8s.io/kops/vendor/github.com/jteeuwen/go-bindata/go-bindata
${KOPS}: ${BINDATA_TARGETS}
go build ${EXTRA_BUILDFLAGS} -ldflags "-X k8s.io/kops.Version=${VERSION} -X k8s.io/kops.GitVersion=${GITSHA} ${EXTRA_LDFLAGS}" -o $@ k8s.io/kops/cmd/kops/

${GOBINDATA}:
mkdir -p ${LOCAL}
go build ${EXTRA_BUILDFLAGS} -ldflags "${EXTRA_LDFLAGS}" -o $@ k8s.io/kops/vendor/github.com/jteeuwen/go-bindata/go-bindata

.PHONY: gobindata-tool
gobindata-tool: ${GOBINDATA}

.PHONY: kops-gobindata
kops-gobindata: gobindata-tool ${BINDATA_TARGETS}

upup/models/bindata.go:
cd ${GOPATH_1ST}/src/k8s.io/kops; ${GOPATH_1ST}/bin/go-bindata -o $@ -pkg models -ignore="\\.DS_Store" -ignore="bindata\\.go" -ignore="vfs\\.go" -prefix upup/models/ upup/models/...
upup/models/bindata.go: ${GOBINDATA}
cd ${GOPATH_1ST}/src/k8s.io/kops; ${GOBINDATA} -o $@ -pkg models -ignore="\\.DS_Store" -ignore="bindata\\.go" -ignore="vfs\\.go" -prefix upup/models/ upup/models/...

federation/model/bindata.go:
cd ${GOPATH_1ST}/src/k8s.io/kops; ${GOPATH_1ST}/bin/go-bindata -o $@ -pkg model -ignore="\\.DS_Store" -ignore="bindata\\.go" -prefix federation/model/ federation/model/...
federation/model/bindata.go: ${GOBINDATA}
cd ${GOPATH_1ST}/src/k8s.io/kops; ${GOBINDATA} -o $@ -pkg model -ignore="\\.DS_Store" -ignore="bindata\\.go" -prefix federation/model/ federation/model/...

# Build in a docker container with golang 1.X
# Used to test we have not broken 1.X
Expand Down Expand Up @@ -164,40 +184,42 @@ hooks: # Install Git hooks
cp hack/pre-commit.sh .git/hooks/pre-commit

.PHONY: test
test: # Run tests locally
go test k8s.io/kops/pkg/... -args -v=1 -logtostderr
go test k8s.io/kops/nodeup/pkg/... -args -v=1 -logtostderr
go test k8s.io/kops/upup/pkg/... -args -v=1 -logtostderr
go test k8s.io/kops/nodeup/pkg/... -args -v=1 -logtostderr
go test k8s.io/kops/protokube/... -args -v=1 -logtostderr
go test k8s.io/kops/dns-controller/pkg/... -args -v=1 -logtostderr
go test k8s.io/kops/cmd/... -args -v=1 -logtostderr
go test k8s.io/kops/channels/... -args -v=1 -logtostderr
go test k8s.io/kops/util/... -args -v=1 -logtostderr
go test k8s.io/kops/tests/... -args -v=1 -logtostderr
test: ${BINDATA_TARGETS} # Run tests locally
for t in ${TESTABLE_PACKAGES}; do go test -v $$t 2>&1; done

${DIST}/linux/amd64/nodeup: ${BINDATA_TARGETS}
mkdir -p ${DIST}
GOOS=linux GOARCH=amd64 go build -a ${EXTRA_BUILDFLAGS} -o $@ -ldflags "${EXTRA_LDFLAGS} -X k8s.io/kops.Version=${VERSION} -X k8s.io/kops.GitVersion=${GITSHA}" k8s.io/kops/cmd/nodeup

.PHONY: crossbuild-nodeup
crossbuild-nodeup:
mkdir -p .build/dist/
GOOS=linux GOARCH=amd64 go build -a ${EXTRA_BUILDFLAGS} -o .build/dist/linux/amd64/nodeup -ldflags "${EXTRA_LDFLAGS} -X k8s.io/kops.Version=${VERSION} -X k8s.io/kops.GitVersion=${GITSHA}" k8s.io/kops/cmd/nodeup
crossbuild-nodeup: ${DIST}/linux/amd64/nodeup

.PHONY: crossbuild-nodeup-in-docker
crossbuild-nodeup-in-docker:
docker pull golang:${GOVERSION} # Keep golang image up to date
docker run --name=nodeup-build-${UNIQUE} -e STATIC_BUILD=yes -e VERSION=${VERSION} -v ${MAKEDIR}:/go/src/k8s.io/kops golang:${GOVERSION} make -f /go/src/k8s.io/kops/Makefile crossbuild-nodeup
docker cp nodeup-build-${UNIQUE}:/go/.build .

${DIST}/darwin/amd64/kops: ${BINDATA_TARGETS}
mkdir -p ${DIST}
GOOS=darwin GOARCH=amd64 go build -a ${EXTRA_BUILDFLAGS} -o $@ -ldflags "${EXTRA_LDFLAGS} -X k8s.io/kops.Version=${VERSION} -X k8s.io/kops.GitVersion=${GITSHA}" k8s.io/kops/cmd/kops

${DIST}/linux/amd64/kops: ${BINDATA_TARGETS}
mkdir -p ${DIST}
GOOS=linux GOARCH=amd64 go build -a ${EXTRA_BUILDFLAGS} -o $@ -ldflags "${EXTRA_LDFLAGS} -X k8s.io/kops.Version=${VERSION} -X k8s.io/kops.GitVersion=${GITSHA}" k8s.io/kops/cmd/kops

.PHONY: crossbuild
crossbuild:
mkdir -p .build/dist/
GOOS=darwin GOARCH=amd64 go build -a ${EXTRA_BUILDFLAGS} -o .build/dist/darwin/amd64/kops -ldflags "${EXTRA_LDFLAGS} -X k8s.io/kops.Version=${VERSION} -X k8s.io/kops.GitVersion=${GITSHA}" k8s.io/kops/cmd/kops
GOOS=linux GOARCH=amd64 go build -a ${EXTRA_BUILDFLAGS} -o .build/dist/linux/amd64/kops -ldflags "${EXTRA_LDFLAGS} -X k8s.io/kops.Version=${VERSION} -X k8s.io/kops.GitVersion=${GITSHA}" k8s.io/kops/cmd/kops
crossbuild: ${DIST}/darwin/amd64/kops ${DIST}/linux/amd64/kops

.PHONY: crossbuild-in-docker
crossbuild-in-docker:
docker pull golang:${GOVERSION} # Keep golang image up to date
docker run --name=kops-build-${UNIQUE} -e STATIC_BUILD=yes -e VERSION=${VERSION} -v ${MAKEDIR}:/go/src/k8s.io/kops golang:${GOVERSION} make -f /go/src/k8s.io/kops/Makefile crossbuild
docker cp kops-build-${UNIQUE}:/go/.build .
docker start kops-build-${UNIQUE}
docker exec kops-build-${UNIQUE} chown -R ${UID}:${GID} /go/src/k8s.io/kops/.build
docker cp kops-build-${UNIQUE}:/go/src/k8s.io/kops/.build .
docker kill kops-build-${UNIQUE}
docker rm kops-build-${UNIQUE}

.PHONY: kops-dist
kops-dist: crossbuild-in-docker
Expand Down Expand Up @@ -337,16 +359,18 @@ protokube-push: protokube-image
.PHONY: nodeup
nodeup: nodeup-dist

${NODEUP}: ${BINDATA_TARGETS}
go build ${EXTRA_BUILDFLAGS} -ldflags "${EXTRA_LDFLAGS} -X k8s.io/kops.Version=${VERSION} -X k8s.io/kops.GitVersion=${GITSHA}" -o $@ k8s.io/kops/cmd/nodeup

.PHONY: nodeup-gocode
nodeup-gocode: kops-gobindata
go install ${EXTRA_BUILDFLAGS} -ldflags "${EXTRA_LDFLAGS} -X k8s.io/kops.Version=${VERSION} -X k8s.io/kops.GitVersion=${GITSHA}" k8s.io/kops/cmd/nodeup
nodeup-gocode: ${NODEUP}

.PHONY: nodeup-dist
nodeup-dist:
mkdir -p ${DIST}
docker pull golang:${GOVERSION} # Keep golang image up to date
docker run --name=nodeup-build-${UNIQUE} -e STATIC_BUILD=yes -e VERSION=${VERSION} -v ${MAKEDIR}:/go/src/k8s.io/kops golang:${GOVERSION} make -f /go/src/k8s.io/kops/Makefile nodeup-gocode
mkdir -p .build/dist
docker cp nodeup-build-${UNIQUE}:/go/bin/nodeup .build/dist/
docker cp nodeup-build-${UNIQUE}:/go/src/k8s.io/kops/.build/local/nodeup .build/dist/
(${SHASUMCMD} .build/dist/nodeup | cut -d' ' -f1) > .build/dist/nodeup.sha1

.PHONY: dns-controller-gocode
Expand Down Expand Up @@ -418,19 +442,7 @@ verify-goimports:

.PHONY: govet
govet:
go vet \
k8s.io/kops/cmd/... \
k8s.io/kops/pkg/... \
k8s.io/kops/channels/... \
k8s.io/kops/examples/... \
k8s.io/kops/federation/... \
k8s.io/kops/nodeup/... \
k8s.io/kops/util/... \
k8s.io/kops/upup/... \
k8s.io/kops/protokube/... \
k8s.io/kops/dns-controller/... \
k8s.io/kops/tests/...

go vet ${TESTABLE_PACKAGES}

# --------------------------------------------------
# Continuous integration targets
Expand All @@ -444,7 +456,7 @@ verify-gofmt:
hack/verify-gofmt.sh

.PHONY: verify-packages
verify-packages:
verify-packages: ${BINDATA_TARGETS}
hack/verify-packages.sh

.PHONY: verify-gendocs
Expand Down Expand Up @@ -495,7 +507,7 @@ release-github:
# API / embedding examples

.PHONY: examples
examples: # Install kops API example
examples: ${BINDATA_TARGETS} # Install kops API example
go install k8s.io/kops/examples/kops-api-example/...

# -----------------------------------------------------
Expand Down