2019-05-23 04:41:24 +00:00
|
|
|
.DEFAULT_GOAL: build
|
2019-05-29 21:44:21 +00:00
|
|
|
|
2019-11-18 19:41:37 +00:00
|
|
|
##################################
|
|
|
|
# DEFAULTS
|
|
|
|
##################################
|
2020-08-11 16:32:51 +00:00
|
|
|
GIT_VERSION := $(shell git describe --always --tags)
|
2020-01-11 02:52:11 +00:00
|
|
|
GIT_BRANCH := $(shell git branch | grep \* | cut -d ' ' -f2)
|
|
|
|
GIT_HASH := $(GIT_BRANCH)/$(shell git log -1 --pretty=format:"%H")
|
|
|
|
TIMESTAMP := $(shell date '+%Y-%m-%d_%I:%M:%S%p')
|
|
|
|
|
2020-05-19 00:10:35 +00:00
|
|
|
REGISTRY?=index.docker.io
|
2019-11-18 19:41:37 +00:00
|
|
|
REPO=$(REGISTRY)/nirmata/kyverno
|
2020-05-15 20:11:28 +00:00
|
|
|
IMAGE_TAG?=$(GIT_VERSION)
|
2019-11-18 19:41:37 +00:00
|
|
|
GOOS ?= $(shell go env GOOS)
|
2020-01-14 18:24:05 +00:00
|
|
|
PACKAGE ?=github.com/nirmata/kyverno
|
2019-11-18 19:41:37 +00:00
|
|
|
LD_FLAGS="-s -w -X $(PACKAGE)/pkg/version.BuildVersion=$(GIT_VERSION) -X $(PACKAGE)/pkg/version.BuildHash=$(GIT_HASH) -X $(PACKAGE)/pkg/version.BuildTime=$(TIMESTAMP)"
|
2019-05-29 21:44:21 +00:00
|
|
|
|
2019-11-18 19:41:37 +00:00
|
|
|
##################################
|
|
|
|
# KYVERNO
|
|
|
|
##################################
|
2019-05-29 21:44:21 +00:00
|
|
|
|
2019-11-18 19:41:37 +00:00
|
|
|
KYVERNO_PATH:= cmd/kyverno
|
2019-12-30 23:50:47 +00:00
|
|
|
build: kyverno
|
2020-02-03 21:38:24 +00:00
|
|
|
PWD := $(CURDIR)
|
2019-05-23 04:41:24 +00:00
|
|
|
|
2019-11-18 19:41:37 +00:00
|
|
|
##################################
|
|
|
|
# INIT CONTAINER
|
|
|
|
##################################
|
|
|
|
INITC_PATH := cmd/initContainer
|
|
|
|
INITC_IMAGE := kyvernopre
|
2020-08-14 19:21:06 +00:00
|
|
|
initContainer: fmt vet
|
2019-11-18 19:41:37 +00:00
|
|
|
GOOS=$(GOOS) go build -o $(PWD)/$(INITC_PATH)/kyvernopre -ldflags=$(LD_FLAGS) $(PWD)/$(INITC_PATH)/main.go
|
2019-05-23 04:41:24 +00:00
|
|
|
|
2019-11-18 19:41:37 +00:00
|
|
|
.PHONY: docker-build-initContainer docker-tag-repo-initContainer docker-push-initContainer
|
2019-05-29 21:44:21 +00:00
|
|
|
|
2019-11-18 19:41:37 +00:00
|
|
|
docker-publish-initContainer: docker-build-initContainer docker-tag-repo-initContainer docker-push-initContainer
|
|
|
|
|
|
|
|
docker-build-initContainer:
|
|
|
|
CGO_ENABLED=0 GOOS=linux go build -o $(PWD)/$(INITC_PATH)/kyvernopre -ldflags=$(LD_FLAGS) $(PWD)/$(INITC_PATH)/main.go
|
|
|
|
echo $(PWD)/$(INITC_PATH)/
|
|
|
|
@docker build -f $(PWD)/$(INITC_PATH)/Dockerfile -t $(REGISTRY)/nirmata/$(INITC_IMAGE):$(IMAGE_TAG) $(PWD)/$(INITC_PATH)/
|
2019-05-23 04:41:24 +00:00
|
|
|
|
2019-11-18 19:41:37 +00:00
|
|
|
docker-tag-repo-initContainer:
|
|
|
|
@docker tag $(REGISTRY)/nirmata/$(INITC_IMAGE):$(IMAGE_TAG) $(REGISTRY)/nirmata/$(INITC_IMAGE):latest
|
2019-05-23 04:41:24 +00:00
|
|
|
|
2019-11-18 19:41:37 +00:00
|
|
|
docker-push-initContainer:
|
|
|
|
@docker push $(REGISTRY)/nirmata/$(INITC_IMAGE):$(IMAGE_TAG)
|
|
|
|
@docker push $(REGISTRY)/nirmata/$(INITC_IMAGE):latest
|
2019-05-29 21:44:21 +00:00
|
|
|
|
2019-11-18 19:41:37 +00:00
|
|
|
##################################
|
|
|
|
# KYVERNO CONTAINER
|
|
|
|
##################################
|
|
|
|
.PHONY: docker-build-kyverno docker-tag-repo-kyverno docker-push-kyverno
|
|
|
|
KYVERNO_PATH := cmd/kyverno
|
|
|
|
KYVERNO_IMAGE := kyverno
|
2020-05-17 16:51:46 +00:00
|
|
|
|
|
|
|
local:
|
2020-05-26 17:36:56 +00:00
|
|
|
go build -ldflags=$(LD_FLAGS) $(PWD)/$(KYVERNO_PATH)
|
|
|
|
go build -ldflags=$(LD_FLAGS) $(PWD)/$(CLI_PATH)
|
2020-05-17 16:51:46 +00:00
|
|
|
|
2020-08-14 19:21:06 +00:00
|
|
|
kyverno: fmt vet
|
2019-12-30 23:50:47 +00:00
|
|
|
GOOS=$(GOOS) go build -o $(PWD)/$(KYVERNO_PATH)/kyverno -ldflags=$(LD_FLAGS) $(PWD)/$(KYVERNO_PATH)/main.go
|
|
|
|
|
2019-11-18 19:41:37 +00:00
|
|
|
docker-publish-kyverno: docker-build-kyverno docker-tag-repo-kyverno docker-push-kyverno
|
2019-05-29 21:44:21 +00:00
|
|
|
|
2019-11-18 19:41:37 +00:00
|
|
|
docker-build-kyverno:
|
2019-12-30 23:50:47 +00:00
|
|
|
CGO_ENABLED=0 GOOS=linux go build -o $(PWD)/$(KYVERNO_PATH)/kyverno -ldflags=$(LD_FLAGS) $(PWD)/$(KYVERNO_PATH)/main.go
|
2019-11-18 19:41:37 +00:00
|
|
|
@docker build -f $(PWD)/$(KYVERNO_PATH)/Dockerfile -t $(REGISTRY)/nirmata/$(KYVERNO_IMAGE):$(IMAGE_TAG) $(PWD)/$(KYVERNO_PATH)
|
2019-06-05 01:05:10 +00:00
|
|
|
|
2019-11-18 19:41:37 +00:00
|
|
|
docker-tag-repo-kyverno:
|
2020-08-05 16:11:23 +00:00
|
|
|
@echo "docker tag $(REGISTRY)/nirmata/$(KYVERNO_IMAGE):$(IMAGE_TAG) $(REGISTRY)/nirmata/$(KYVERNO_IMAGE):latest"
|
2019-11-18 19:41:37 +00:00
|
|
|
@docker tag $(REGISTRY)/nirmata/$(KYVERNO_IMAGE):$(IMAGE_TAG) $(REGISTRY)/nirmata/$(KYVERNO_IMAGE):latest
|
2019-06-05 01:05:10 +00:00
|
|
|
|
2019-11-18 19:41:37 +00:00
|
|
|
docker-push-kyverno:
|
|
|
|
@docker push $(REGISTRY)/nirmata/$(KYVERNO_IMAGE):$(IMAGE_TAG)
|
|
|
|
@docker push $(REGISTRY)/nirmata/$(KYVERNO_IMAGE):latest
|
2019-06-05 01:05:10 +00:00
|
|
|
|
2020-07-20 14:35:06 +00:00
|
|
|
##################################
|
2020-08-06 06:26:31 +00:00
|
|
|
|
2020-07-20 14:35:06 +00:00
|
|
|
# Generate Docs for types.go
|
|
|
|
##################################
|
|
|
|
|
|
|
|
generate-api-docs:
|
|
|
|
go run github.com/ahmetb/gen-crd-api-reference-docs -api-dir ./pkg/api -config documentation/api/config.json -template-dir documentation/api/template -out-file documentation/index.html
|
|
|
|
|
2019-06-05 01:05:10 +00:00
|
|
|
|
2019-11-18 19:41:37 +00:00
|
|
|
##################################
|
|
|
|
# CLI
|
|
|
|
##################################
|
2020-02-20 03:13:05 +00:00
|
|
|
CLI_PATH := cmd/cli/kubectl-kyverno
|
2019-11-18 19:41:37 +00:00
|
|
|
cli:
|
2020-02-20 03:13:05 +00:00
|
|
|
GOOS=$(GOOS) go build -o $(PWD)/$(CLI_PATH)/kyverno -ldflags=$(LD_FLAGS) $(PWD)/$(CLI_PATH)/main.go
|
2019-06-05 01:05:10 +00:00
|
|
|
|
2019-06-07 18:50:12 +00:00
|
|
|
|
2020-08-06 06:26:31 +00:00
|
|
|
##################################
|
2020-08-11 16:32:51 +00:00
|
|
|
docker-publish-all: docker-publish-initContainer docker-publish-kyverno
|
|
|
|
|
|
|
|
docker-build-all: docker-build-initContainer docker-build-kyverno
|
|
|
|
|
|
|
|
ci:
|
2020-08-06 06:26:31 +00:00
|
|
|
echo "kustomize input"
|
|
|
|
chmod a+x $(PWD)/scripts/ci.sh
|
|
|
|
$(PWD)/scripts/ci.sh
|
2020-08-11 00:16:13 +00:00
|
|
|
|
|
|
|
|
2020-08-06 06:26:31 +00:00
|
|
|
##################################
|
|
|
|
|
2019-11-18 19:41:37 +00:00
|
|
|
##################################
|
|
|
|
# Testing & Code-Coverage
|
|
|
|
##################################
|
2019-06-07 18:50:12 +00:00
|
|
|
|
|
|
|
## variables
|
|
|
|
BIN_DIR := $(GOPATH)/bin
|
|
|
|
GO_ACC := $(BIN_DIR)/go-acc
|
|
|
|
CODE_COVERAGE_FILE:= coverage
|
|
|
|
CODE_COVERAGE_FILE_TXT := $(CODE_COVERAGE_FILE).txt
|
|
|
|
CODE_COVERAGE_FILE_HTML := $(CODE_COVERAGE_FILE).html
|
|
|
|
|
|
|
|
## targets
|
|
|
|
$(GO_ACC):
|
|
|
|
@echo " downloading testing tools"
|
|
|
|
go get -v github.com/ory/go-acc
|
|
|
|
$(eval export PATH=$(GO_ACC):$(PATH))
|
|
|
|
# go test provides code coverage per packages only.
|
|
|
|
# go-acc merges the result for pks so that it be used by
|
|
|
|
# go tool cover for reporting
|
|
|
|
|
|
|
|
# go get downloads and installs the binary
|
|
|
|
# we temporarily add the GO_ACC to the path
|
|
|
|
test-all: $(GO_ACC)
|
|
|
|
@echo " running unit tests"
|
|
|
|
go-acc ./... -o $(CODE_COVERAGE_FILE_TXT)
|
|
|
|
|
|
|
|
code-cov-report: $(CODE_COVERAGE_FILE_TXT)
|
|
|
|
# transform to html format
|
|
|
|
@echo " generating code coverage report"
|
|
|
|
go tool cover -html=coverage.txt
|
2020-06-04 18:45:37 +00:00
|
|
|
if [ -a $(CODE_COVERAGE_FILE_HTML) ]; then open $(CODE_COVERAGE_FILE_HTML); fi;
|
|
|
|
|
2020-08-06 05:16:10 +00:00
|
|
|
# Test E2E
|
|
|
|
test-e2e:
|
|
|
|
$(eval export E2E="ok")
|
|
|
|
go test ./test/e2e/... -v
|
|
|
|
$(eval export E2E="")
|
|
|
|
|
2020-06-05 20:42:53 +00:00
|
|
|
# godownloader create downloading script for kyverno-cli
|
2020-06-04 18:45:37 +00:00
|
|
|
godownloader:
|
2020-06-05 20:42:53 +00:00
|
|
|
godownloader .goreleaser.yml --repo nirmata/kyverno -o ./scripts/install-cli.sh --source="raw"
|
|
|
|
|
|
|
|
# kustomize-crd will create install.yaml
|
|
|
|
kustomize-crd:
|
2020-06-05 20:44:47 +00:00
|
|
|
# Create CRD for helm deployment Helm
|
2020-06-05 20:42:53 +00:00
|
|
|
kustomize build ./definitions/crds > ./charts/kyverno/crds/crds.yaml
|
2020-06-05 20:44:47 +00:00
|
|
|
# Generate install.yaml that have all resources for kyverno
|
2020-06-05 20:42:53 +00:00
|
|
|
kustomize build ./definitions > ./definitions/install.yaml
|
2020-06-05 20:44:47 +00:00
|
|
|
# Generate install_debug.yaml that for developer testing
|
2020-08-12 14:54:45 +00:00
|
|
|
kustomize build ./definitions/debug > ./definitions/install_debug.yaml
|
|
|
|
|
|
|
|
# guidance https://github.com/nirmata/kyverno/wiki/Generate-a-Release
|
|
|
|
release:
|
|
|
|
# update image tag
|
|
|
|
cd ./definitions && kustomize edit set image nirmata/kyverno=nirmata/kyverno:$(IMAGE_TAG)
|
|
|
|
cd ./definitions && kustomize edit set image nirmata/kyvernopre=nirmata/kyvernopre:$(IMAGE_TAG)
|
|
|
|
|
|
|
|
kustomize build ./definitions > ./definitions/install.yaml
|
|
|
|
kustomize build ./definitions > ./definitions/release/install.yaml
|
2020-08-14 19:21:06 +00:00
|
|
|
|
|
|
|
# Run go fmt against code
|
|
|
|
fmt:
|
|
|
|
go fmt ./...
|
|
|
|
|
|
|
|
vet:
|
|
|
|
go vet ./...
|
|
|
|
|