2019-05-03 11:03:39 +00:00
|
|
|
export GO111MODULE=on
|
2019-05-16 17:07:58 +00:00
|
|
|
.PHONY: push container clean container-name container-latest push-latest fmt lint test unit vendor header generate client deepcopy informer lister openapi manifest manfest-latest manifest-annotate manifest manfest-latest manifest-annotate
|
2019-01-18 01:50:10 +00:00
|
|
|
|
2019-05-16 17:07:58 +00:00
|
|
|
ARCH ?= amd64
|
|
|
|
ALL_ARCH := amd64 arm arm64
|
|
|
|
DOCKER_ARCH := "" arm "arm64 armv8"
|
|
|
|
IMAGE_ARCH := amd64 armhf arm64
|
|
|
|
BINS := $(addprefix bin/$(ARCH)/,kg kgctl)
|
2019-01-18 01:50:10 +00:00
|
|
|
PROJECT := kilo
|
|
|
|
PKG := github.com/squat/$(PROJECT)
|
|
|
|
REGISTRY ?= index.docker.io
|
|
|
|
IMAGE ?= squat/$(PROJECT)
|
|
|
|
|
|
|
|
TAG := $(shell git describe --abbrev=0 --tags HEAD 2>/dev/null)
|
|
|
|
COMMIT := $(shell git rev-parse HEAD)
|
|
|
|
VERSION := $(COMMIT)
|
|
|
|
ifneq ($(TAG),)
|
|
|
|
ifeq ($(COMMIT), $(shell git rev-list -n1 $(TAG)))
|
|
|
|
VERSION := $(TAG)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
DIRTY := $(shell test -z "$$(git diff --shortstat 2>/dev/null)" || echo -dirty)
|
|
|
|
VERSION := $(VERSION)$(DIRTY)
|
|
|
|
LD_FLAGS := -ldflags '-X $(PKG)/pkg/version.Version=$(VERSION)'
|
|
|
|
SRC := $(shell find . -type f -name '*.go' -not -path "./vendor/*")
|
|
|
|
GO_FILES ?= $$(find . -name '*.go' -not -path './vendor/*')
|
|
|
|
GO_PKGS ?= $$(go list ./... | grep -v "$(PKG)/vendor")
|
|
|
|
|
2019-05-16 22:23:51 +00:00
|
|
|
CLIENT_GEN_BINARY := bin/client-gen
|
|
|
|
DEEPCOPY_GEN_BINARY := bin/deepcopy-gen
|
|
|
|
INFORMER_GEN_BINARY := bin/informer-gen
|
|
|
|
LISTER_GEN_BINARY := bin/lister-gen
|
|
|
|
OPENAPI_GEN_BINARY := bin/openapi-gen
|
|
|
|
GOLINT_BINARY := bin/golint
|
2019-05-03 10:53:40 +00:00
|
|
|
|
2019-03-20 23:27:40 +00:00
|
|
|
BUILD_IMAGE ?= golang:1.12.1-alpine
|
2019-01-18 01:50:10 +00:00
|
|
|
|
|
|
|
build: $(BINS)
|
|
|
|
|
2019-05-16 17:07:58 +00:00
|
|
|
build-%:
|
|
|
|
@$(MAKE) --no-print-directory ARCH=$* build
|
|
|
|
|
|
|
|
container-latest-%:
|
|
|
|
@$(MAKE) --no-print-directory ARCH=$* container-latest
|
|
|
|
|
|
|
|
container-%:
|
|
|
|
@$(MAKE) --no-print-directory ARCH=$* container
|
|
|
|
|
|
|
|
push-latest-%:
|
|
|
|
@$(MAKE) --no-print-directory ARCH=$* push-latest
|
|
|
|
|
|
|
|
push-%:
|
|
|
|
@$(MAKE) --no-print-directory ARCH=$* push
|
|
|
|
|
|
|
|
all-build: $(addprefix build-, $(ALL_ARCH))
|
|
|
|
|
|
|
|
all-container: $(addprefix container-, $(ALL_ARCH))
|
|
|
|
|
|
|
|
all-push: $(addprefix push-, $(ALL_ARCH))
|
|
|
|
|
|
|
|
all-container-latest: $(addprefix container-latest-, $(ALL_ARCH))
|
|
|
|
|
|
|
|
all-push-latest: $(addprefix push-latest-, $(ALL_ARCH))
|
|
|
|
|
2019-05-03 10:53:40 +00:00
|
|
|
generate: client deepcopy informer lister openapi
|
|
|
|
|
|
|
|
client: pkg/k8s/clientset/versioned/typed/kilo/v1alpha1/peer.go
|
|
|
|
pkg/k8s/clientset/versioned/typed/kilo/v1alpha1/peer.go: .header pkg/k8s/apis/kilo/v1alpha1/types.go $(CLIENT_GEN_BINARY)
|
|
|
|
$(CLIENT_GEN_BINARY) \
|
|
|
|
--clientset-name versioned \
|
|
|
|
--input-base "" \
|
|
|
|
--input $(PKG)/pkg/k8s/apis/kilo/v1alpha1 \
|
|
|
|
--output-base $(CURDIR) \
|
|
|
|
--output-package $(PKG)/pkg/k8s/clientset \
|
|
|
|
--go-header-file=.header \
|
|
|
|
--logtostderr
|
2019-05-16 22:23:51 +00:00
|
|
|
rm -r pkg/k8s/clientset || true
|
2019-05-03 10:53:40 +00:00
|
|
|
mv $(PKG)/pkg/k8s/clientset pkg/k8s
|
2019-05-16 22:23:51 +00:00
|
|
|
rm -r github.com || true
|
2019-05-03 10:53:40 +00:00
|
|
|
go fmt ./pkg/k8s/clientset/...
|
|
|
|
|
|
|
|
deepcopy: pkg/k8s/apis/kilo/v1alpha1/zz_generated.deepcopy.go
|
|
|
|
pkg/k8s/apis/kilo/v1alpha1/zz_generated.deepcopy.go: .header pkg/k8s/apis/kilo/v1alpha1/types.go $(DEEPCOPY_GEN_BINARY)
|
|
|
|
$(DEEPCOPY_GEN_BINARY) \
|
|
|
|
--input-dirs ./$(@D) \
|
|
|
|
--go-header-file=.header \
|
|
|
|
--logtostderr \
|
|
|
|
--output-base $(CURDIR) \
|
2019-05-03 11:03:39 +00:00
|
|
|
--output-file-base zz_generated.deepcopy
|
|
|
|
mv $(PKG)/$@ $@ || true
|
|
|
|
rm -r github.com || true
|
2019-05-03 10:53:40 +00:00
|
|
|
go fmt $@
|
|
|
|
|
|
|
|
informer: pkg/k8s/informers/kilo/v1alpha1/peer.go
|
|
|
|
pkg/k8s/informers/kilo/v1alpha1/peer.go: .header pkg/k8s/apis/kilo/v1alpha1/types.go $(INFORMER_GEN_BINARY)
|
|
|
|
$(INFORMER_GEN_BINARY) \
|
|
|
|
--input-dirs $(PKG)/pkg/k8s/apis/kilo/v1alpha1 \
|
|
|
|
--go-header-file=.header \
|
|
|
|
--logtostderr \
|
|
|
|
--versioned-clientset-package $(PKG)/pkg/k8s/clientset/versioned \
|
|
|
|
--listers-package $(PKG)/pkg/k8s/listers \
|
|
|
|
--output-base $(CURDIR) \
|
|
|
|
--output-package $(PKG)/pkg/k8s/informers \
|
|
|
|
--single-directory
|
2019-05-16 22:23:51 +00:00
|
|
|
rm -r pkg/k8s/informers || true
|
2019-05-03 10:53:40 +00:00
|
|
|
mv $(PKG)/pkg/k8s/informers pkg/k8s
|
2019-05-16 22:23:51 +00:00
|
|
|
rm -r github.com || true
|
2019-05-03 10:53:40 +00:00
|
|
|
go fmt ./pkg/k8s/informers/...
|
|
|
|
|
|
|
|
lister: pkg/k8s/listers/kilo/v1alpha1/peer.go
|
|
|
|
pkg/k8s/listers/kilo/v1alpha1/peer.go: .header pkg/k8s/apis/kilo/v1alpha1/types.go $(LISTER_GEN_BINARY)
|
|
|
|
$(LISTER_GEN_BINARY) \
|
|
|
|
--input-dirs $(PKG)/pkg/k8s/apis/kilo/v1alpha1 \
|
|
|
|
--go-header-file=.header \
|
|
|
|
--logtostderr \
|
|
|
|
--output-base $(CURDIR) \
|
|
|
|
--output-package $(PKG)/pkg/k8s/listers
|
2019-05-16 22:23:51 +00:00
|
|
|
rm -r pkg/k8s/listers || true
|
2019-05-03 10:53:40 +00:00
|
|
|
mv $(PKG)/pkg/k8s/listers pkg/k8s
|
2019-05-16 22:23:51 +00:00
|
|
|
rm -r github.com || true
|
2019-05-03 10:53:40 +00:00
|
|
|
go fmt ./pkg/k8s/listers/...
|
|
|
|
|
|
|
|
openapi: pkg/k8s/apis/kilo/v1alpha1/openapi_generated.go
|
|
|
|
pkg/k8s/apis/kilo/v1alpha1/openapi_generated.go: pkg/k8s/apis/kilo/v1alpha1/types.go $(OPENAPI_GEN_BINARY)
|
|
|
|
$(OPENAPI_GEN_BINARY) \
|
2019-05-03 11:03:39 +00:00
|
|
|
--input-dirs $(PKG)/$(@D),k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/api/core/v1 \
|
2019-05-03 10:53:40 +00:00
|
|
|
--output-base $(CURDIR) \
|
|
|
|
--output-package ./$(@D) \
|
|
|
|
--logtostderr \
|
|
|
|
--report-filename /dev/null \
|
|
|
|
--go-header-file=.header
|
|
|
|
go fmt $@
|
|
|
|
|
2019-01-18 01:50:10 +00:00
|
|
|
$(BINS): $(SRC) go.mod
|
2019-05-16 17:07:58 +00:00
|
|
|
@mkdir -p bin/$(ARCH)
|
2019-01-18 01:50:10 +00:00
|
|
|
@echo "building: $@"
|
|
|
|
@docker run --rm \
|
|
|
|
-u $$(id -u):$$(id -g) \
|
|
|
|
-v $$(pwd):/$(PROJECT) \
|
|
|
|
-w /$(PROJECT) \
|
|
|
|
$(BUILD_IMAGE) \
|
|
|
|
/bin/sh -c " \
|
2019-05-16 17:07:58 +00:00
|
|
|
GOARCH=$(ARCH) \
|
2019-01-18 01:50:10 +00:00
|
|
|
GOOS=linux \
|
2019-03-20 23:27:40 +00:00
|
|
|
GOCACHE=/$(PROJECT)/.cache \
|
2019-01-18 01:50:10 +00:00
|
|
|
CGO_ENABLED=0 \
|
|
|
|
go build -mod=vendor -o $@ \
|
|
|
|
$(LD_FLAGS) \
|
|
|
|
./cmd/$(@F)/... \
|
|
|
|
"
|
|
|
|
|
|
|
|
fmt:
|
|
|
|
@echo $(GO_PKGS)
|
|
|
|
gofmt -w -s $(GO_FILES)
|
|
|
|
|
2019-05-16 22:23:51 +00:00
|
|
|
lint: header $(GOLINT_BINARY)
|
2019-01-18 01:50:10 +00:00
|
|
|
@echo 'go vet $(GO_PKGS)'
|
2019-02-06 16:26:44 +00:00
|
|
|
@vet_res=$$(GO111MODULE=on go vet -mod=vendor $(GO_PKGS) 2>&1); if [ -n "$$vet_res" ]; then \
|
2019-01-18 01:50:10 +00:00
|
|
|
echo ""; \
|
|
|
|
echo "Go vet found issues. Please check the reported issues"; \
|
|
|
|
echo "and fix them if necessary before submitting the code for review:"; \
|
|
|
|
echo "$$vet_res"; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
2019-05-16 22:23:51 +00:00
|
|
|
@echo '$(GOLINT_BINARY) $(GO_PKGS)'
|
|
|
|
@lint_res=$$($(GOLINT_BINARY) $(GO_PKGS)); if [ -n "$$lint_res" ]; then \
|
2019-01-18 01:50:10 +00:00
|
|
|
echo ""; \
|
|
|
|
echo "Golint found style issues. Please check the reported issues"; \
|
|
|
|
echo "and fix them if necessary before submitting the code for review:"; \
|
|
|
|
echo "$$lint_res"; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
@echo 'gofmt -d -s $(GO_FILES)'
|
|
|
|
@fmt_res=$$(gofmt -d -s $(GO_FILES)); if [ -n "$$fmt_res" ]; then \
|
|
|
|
echo ""; \
|
|
|
|
echo "Gofmt found style issues. Please check the reported issues"; \
|
|
|
|
echo "and fix them if necessary before submitting the code for review:"; \
|
|
|
|
echo "$$fmt_res"; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
unit:
|
2019-02-06 16:26:44 +00:00
|
|
|
go test -mod=vendor --race ./...
|
2019-01-18 01:50:10 +00:00
|
|
|
|
|
|
|
test: lint unit
|
|
|
|
|
|
|
|
header: .header
|
|
|
|
@HEADER=$$(sed "s/YEAR/$$(date '+%Y')/" .header); \
|
2019-05-03 10:53:40 +00:00
|
|
|
HEADER_LEN=$$(wc -l .header | awk '{print $$1}'); \
|
2019-01-18 01:50:10 +00:00
|
|
|
FILES=; \
|
|
|
|
for f in $(GO_FILES); do \
|
2019-05-03 10:53:40 +00:00
|
|
|
for i in 0 1 2 3 4 5; do \
|
|
|
|
FILE=$$(tail -n +$$i $$f | head -n $$HEADER_LEN); \
|
|
|
|
[ "$$FILE" = "$$HEADER" ] && continue 2; \
|
|
|
|
done; \
|
|
|
|
FILES="$$FILES$$f "; \
|
2019-01-18 01:50:10 +00:00
|
|
|
done; \
|
|
|
|
if [ -n "$$FILES" ]; then \
|
|
|
|
printf 'the following files are missing the license header: %s\n' "$$FILES"; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
|
2019-05-16 17:07:58 +00:00
|
|
|
container: .container-$(ARCH)-$(VERSION) container-name
|
|
|
|
.container-$(ARCH)-$(VERSION): $(BINS) Dockerfile
|
|
|
|
@i=0; for a in $(ALL_ARCH); do [ "$$a" = $(ARCH) ] && break; i=$$((i+1)); done; \
|
|
|
|
ia=""; \
|
|
|
|
j=0; for a in $(IMAGE_ARCH); do [ "$$i" -eq "$$j" ] && ia="$$a" && break; j=$$((j+1)); done; \
|
|
|
|
docker build -t $(IMAGE):$(ARCH)-$(VERSION) --build-arg FROM=multiarch/alpine:$$ia-v3.9 --build-arg GOARCH=$(ARCH) .
|
|
|
|
@docker images -q $(IMAGE):$(ARCH)-$(VERSION) > $@
|
2019-01-18 01:50:10 +00:00
|
|
|
|
2019-05-16 17:07:58 +00:00
|
|
|
container-latest: .container-$(ARCH)-$(VERSION)
|
|
|
|
@docker tag $(IMAGE):$(ARCH)-$(VERSION) $(IMAGE):$(ARCH)-latest
|
|
|
|
@echo "container: $(IMAGE):$(ARCH)-latest"
|
2019-01-18 01:50:10 +00:00
|
|
|
|
|
|
|
container-name:
|
2019-05-16 17:07:58 +00:00
|
|
|
@echo "container: $(IMAGE):$(ARCH)-$(VERSION)"
|
|
|
|
|
|
|
|
manifest: .manifest-$(VERSION) manifest-name
|
|
|
|
.manifest-$(VERSION): Dockerfile $(addprefix push-, $(ALL_ARCH))
|
|
|
|
@docker manifest create --amend $(IMAGE):$(VERSION) $(addsuffix -$(VERSION), $(addprefix squat/$(PROJECT):, $(ALL_ARCH)))
|
|
|
|
@$(MAKE) --no-print-directory manifest-annotate
|
|
|
|
@docker manifest push $(IMAGE):$(VERSION) > $@
|
|
|
|
|
|
|
|
manifest-latest: .manifest-$(VERSION) $(addprefix push-latest-, $(ALL_ARCH))
|
|
|
|
@docker manifest create --amend $(IMAGE):latest $(addsuffix -latest, $(addprefix squat/$(PROJECT):, $(ALL_ARCH)))
|
|
|
|
@$(MAKE) --no-print-directory manifest-annotate
|
|
|
|
@docker manifest push $(IMAGE):latest
|
|
|
|
@echo "manifest: $(IMAGE):latest"
|
|
|
|
|
|
|
|
manifest-annotate:
|
|
|
|
@i=0; \
|
|
|
|
for a in $(ALL_ARCH); do \
|
|
|
|
annotate=; \
|
|
|
|
j=0; for da in $(DOCKER_ARCH); do \
|
|
|
|
if [ "$$j" -eq "$$i" ] && [ -n "$$da" ]; then \
|
|
|
|
annotate="docker manifest annotate $(IMAGE):$(VERSION) $(IMAGE):$$a-$(VERSION) --os linux --arch"; \
|
|
|
|
k=0; for ea in $$da; do \
|
|
|
|
[ "$$k" = 0 ] && annotate="$$annotate $$ea"; \
|
|
|
|
[ "$$k" != 0 ] && annotate="$$annotate --variant $$ea"; \
|
|
|
|
k=$$((k+1)); \
|
|
|
|
done; \
|
|
|
|
$$annotate; \
|
|
|
|
fi; \
|
|
|
|
j=$$((j+1)); \
|
|
|
|
done; \
|
|
|
|
i=$$((i+1)); \
|
|
|
|
done
|
|
|
|
|
|
|
|
manifest-name:
|
|
|
|
@echo "manifest: $(IMAGE_ROOT):$(VERSION)"
|
|
|
|
|
|
|
|
push: .push-$(ARCH)-$(VERSION) push-name
|
|
|
|
.push-$(ARCH)-$(VERSION): .container-$(ARCH)-$(VERSION)
|
|
|
|
@docker push $(REGISTRY)/$(IMAGE):$(ARCH)-$(VERSION)
|
|
|
|
@docker images -q $(IMAGE):$(ARCH)-$(VERSION) > $@
|
2019-01-18 01:50:10 +00:00
|
|
|
|
|
|
|
push-latest: container-latest
|
2019-05-16 17:07:58 +00:00
|
|
|
@docker push $(REGISTRY)/$(IMAGE):$(ARCH)-latest
|
|
|
|
@echo "pushed: $(IMAGE):$(ARCH)-latest"
|
2019-01-18 01:50:10 +00:00
|
|
|
|
|
|
|
push-name:
|
2019-05-16 17:07:58 +00:00
|
|
|
@echo "pushed: $(IMAGE):$(ARCH)-$(VERSION)"
|
2019-01-18 01:50:10 +00:00
|
|
|
|
|
|
|
clean: container-clean bin-clean
|
|
|
|
rm -r .cache
|
|
|
|
|
|
|
|
container-clean:
|
|
|
|
rm -rf .container-* .push-*
|
|
|
|
|
|
|
|
bin-clean:
|
|
|
|
rm -rf bin
|
|
|
|
|
|
|
|
vendor:
|
|
|
|
go mod tidy
|
|
|
|
go mod vendor
|
2019-05-03 10:53:40 +00:00
|
|
|
|
|
|
|
$(CLIENT_GEN_BINARY):
|
2019-05-16 22:23:51 +00:00
|
|
|
go build -mod=vendor -o $@ k8s.io/code-generator/cmd/client-gen
|
2019-05-03 10:53:40 +00:00
|
|
|
|
|
|
|
$(DEEPCOPY_GEN_BINARY):
|
2019-05-16 22:23:51 +00:00
|
|
|
go build -mod=vendor -o $@ k8s.io/code-generator/cmd/deepcopy-gen
|
2019-05-03 10:53:40 +00:00
|
|
|
|
|
|
|
$(INFORMER_GEN_BINARY):
|
2019-05-16 22:23:51 +00:00
|
|
|
go build -mod=vendor -o $@ k8s.io/code-generator/cmd/informer-gen
|
2019-05-03 10:53:40 +00:00
|
|
|
|
|
|
|
$(LISTER_GEN_BINARY):
|
2019-05-16 22:23:51 +00:00
|
|
|
go build -mod=vendor -o $@ k8s.io/code-generator/cmd/lister-gen
|
2019-05-03 10:53:40 +00:00
|
|
|
|
|
|
|
$(OPENAPI_GEN_BINARY):
|
2019-05-16 22:23:51 +00:00
|
|
|
go build -mod=vendor -o $@ k8s.io/kube-openapi/cmd/openapi-gen
|
|
|
|
|
|
|
|
$(GOLINT_BINARY):
|
|
|
|
go build -mod=vendor -o $@ golang.org/x/lint/golint
|