2017-08-02 17:27:17 +00:00
|
|
|
# Copyright 2017 Heptio Inc.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
# project related vars
|
|
|
|
ROOT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
|
|
|
|
PROJECT = ark
|
2017-09-13 19:22:53 +00:00
|
|
|
VERSION ?= v0.4.0
|
2017-08-02 17:27:17 +00:00
|
|
|
GOTARGET = github.com/heptio/$(PROJECT)
|
|
|
|
OUTPUT_DIR = $(ROOT_DIR)/_output
|
|
|
|
BIN_DIR = $(OUTPUT_DIR)/bin
|
2017-08-24 01:51:11 +00:00
|
|
|
GIT_SHA=$(shell git rev-parse --short HEAD)
|
|
|
|
GIT_DIRTY=$(shell git status --porcelain $(ROOT_DIR) 2> /dev/null)
|
2017-09-13 14:16:16 +00:00
|
|
|
ifeq ($(GIT_DIRTY),)
|
|
|
|
GIT_TREE_STATE := clean
|
|
|
|
else
|
|
|
|
GIT_TREE_STATE := dirty
|
2017-08-24 01:51:11 +00:00
|
|
|
endif
|
2017-08-02 17:27:17 +00:00
|
|
|
|
|
|
|
# docker related vars
|
|
|
|
REGISTRY ?= gcr.io/heptio-images
|
2017-08-16 21:03:05 +00:00
|
|
|
BUILD_IMAGE ?= gcr.io/heptio-images/golang:1.8-alpine3.6
|
2017-10-20 18:03:29 +00:00
|
|
|
LDFLAGS = -X $(GOTARGET)/pkg/buildinfo.Version=$(VERSION)
|
2017-09-13 14:16:16 +00:00
|
|
|
LDFLAGS += -X $(GOTARGET)/pkg/buildinfo.DockerImage=$(REGISTRY)/$(PROJECT)
|
|
|
|
LDFLAGS += -X $(GOTARGET)/pkg/buildinfo.GitSHA=$(GIT_SHA)
|
|
|
|
LDFLAGS += -X $(GOTARGET)/pkg/buildinfo.GitTreeState=$(GIT_TREE_STATE)
|
2017-08-02 17:27:17 +00:00
|
|
|
# go build -i installs compiled packages so they can be reused later.
|
|
|
|
# This speeds up recompiles.
|
2017-09-13 14:16:16 +00:00
|
|
|
BUILDCMD = go build -i -v -ldflags "$(LDFLAGS)"
|
2017-08-02 17:27:17 +00:00
|
|
|
BUILDMNT = /go/src/$(GOTARGET)
|
|
|
|
EXTRA_MNTS ?=
|
|
|
|
|
|
|
|
# test related vars
|
|
|
|
TESTARGS ?= -timeout 60s
|
|
|
|
TEST_PKGS ?= ./cmd/... ./pkg/...
|
|
|
|
SKIP_TESTS ?=
|
|
|
|
|
|
|
|
# what we're building
|
|
|
|
BINARIES = ark
|
|
|
|
|
|
|
|
local: $(BINARIES)
|
|
|
|
|
|
|
|
$(BINARIES):
|
|
|
|
mkdir -p $(BIN_DIR)
|
|
|
|
$(BUILDCMD) -o $(BIN_DIR)/$@ $(GOTARGET)/cmd/$@
|
|
|
|
|
2017-08-24 01:51:11 +00:00
|
|
|
fmt:
|
|
|
|
gofmt -w=true $$(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./pkg/generated/*")
|
|
|
|
goimports -w=true -d $$(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./pkg/generated/*")
|
|
|
|
|
2017-08-02 17:27:17 +00:00
|
|
|
test:
|
|
|
|
ifneq ($(SKIP_TESTS), 1)
|
|
|
|
# go test -i installs compiled packages so they can be reused later
|
|
|
|
# This speeds up retests.
|
|
|
|
go test -i -v $(TEST_PKGS)
|
|
|
|
go test $(TEST_PKGS) $(TESTARGS)
|
|
|
|
endif
|
|
|
|
|
|
|
|
verify:
|
|
|
|
ifneq ($(SKIP_TESTS), 1)
|
|
|
|
${ROOT_DIR}/hack/verify-generated-docs.sh
|
|
|
|
${ROOT_DIR}/hack/verify-generated-clientsets.sh
|
|
|
|
${ROOT_DIR}/hack/verify-generated-listers.sh
|
|
|
|
${ROOT_DIR}/hack/verify-generated-informers.sh
|
|
|
|
endif
|
|
|
|
|
2017-08-24 01:51:11 +00:00
|
|
|
update: fmt
|
2017-08-02 17:27:17 +00:00
|
|
|
${ROOT_DIR}/hack/update-generated-clientsets.sh
|
|
|
|
${ROOT_DIR}/hack/update-generated-listers.sh
|
|
|
|
${ROOT_DIR}/hack/update-generated-informers.sh
|
2017-08-23 17:27:54 +00:00
|
|
|
${ROOT_DIR}/hack/update-generated-docs.sh
|
2017-08-02 17:27:17 +00:00
|
|
|
|
|
|
|
all: cbuild container
|
|
|
|
|
|
|
|
cbuild:
|
2017-10-20 18:03:29 +00:00
|
|
|
@docker run --rm \
|
|
|
|
-v $(ROOT_DIR):$(BUILDMNT) \
|
|
|
|
$(EXTRA_MNTS) \
|
|
|
|
-w $(BUILDMNT) \
|
|
|
|
-e SKIP_TESTS=$(SKIP_TESTS) \
|
|
|
|
$(BUILD_IMAGE) \
|
|
|
|
/bin/sh -c " \
|
|
|
|
VERSION=$(VERSION) \
|
|
|
|
make local verify test \
|
|
|
|
"
|
2017-08-02 17:27:17 +00:00
|
|
|
|
|
|
|
container: cbuild
|
2017-10-20 18:03:29 +00:00
|
|
|
@docker build -t $(REGISTRY)/$(PROJECT):latest -t $(REGISTRY)/$(PROJECT):$(VERSION) .
|
2017-08-02 17:27:17 +00:00
|
|
|
|
|
|
|
container-local: $(BINARIES)
|
2017-10-20 18:03:29 +00:00
|
|
|
@docker build -t $(REGISTRY)/$(PROJECT):latest -t $(REGISTRY)/$(PROJECT):$(VERSION) .
|
2017-08-02 17:27:17 +00:00
|
|
|
|
|
|
|
push:
|
|
|
|
docker -- push $(REGISTRY)/$(PROJECT):$(VERSION)
|
|
|
|
|
2017-08-24 01:51:11 +00:00
|
|
|
.PHONY: all local container cbuild push test verify update fmt $(BINARIES)
|
2017-08-02 17:27:17 +00:00
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -rf $(OUTPUT_DIR)
|
2017-10-20 18:03:29 +00:00
|
|
|
@docker rmi $(REGISTRY)/$(PROJECT):latest $(REGISTRY)/$(PROJECT):$(VERSION) 2>/dev/null || :
|