2019-05-07 10:00:07 -05:00
|
|
|
SHELL := /bin/bash
|
|
|
|
|
2020-05-04 21:59:56 -07:00
|
|
|
GIT_VERSION ?= v0.1.0
|
|
|
|
GIT_MODULE ?= opendev.org/airship/airshipctl/pkg/version
|
|
|
|
|
2020-08-24 09:48:29 -05:00
|
|
|
GO_FLAGS := -ldflags '-extldflags "-static"' -tags=netgo -trimpath
|
2020-05-04 21:59:56 -07:00
|
|
|
GO_FLAGS += -ldflags "-X ${GIT_MODULE}.gitVersion=${GIT_VERSION}"
|
2020-11-02 16:39:50 +04:00
|
|
|
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
|
2021-01-20 09:38:31 -06:00
|
|
|
ifeq (,$(shell go env GOBIN 2> /dev/null))
|
|
|
|
GOBIN = $(shell go env GOPATH 2> /dev/null)/bin
|
2020-11-02 16:39:50 +04:00
|
|
|
else
|
2021-01-20 09:38:31 -06:00
|
|
|
GOBIN = $(shell go env GOBIN 2> /dev/null)
|
2020-11-02 16:39:50 +04:00
|
|
|
endif
|
2019-05-17 09:44:03 -05:00
|
|
|
|
2019-07-09 13:52:24 -05:00
|
|
|
BINDIR := bin
|
|
|
|
EXECUTABLE_CLI := airshipctl
|
2019-10-22 16:22:39 -05:00
|
|
|
TOOLBINDIR := tools/bin
|
2019-04-26 11:33:16 -05:00
|
|
|
|
2019-05-01 12:00:04 -05:00
|
|
|
# linting
|
2019-10-22 16:22:39 -05:00
|
|
|
LINTER := $(TOOLBINDIR)/golangci-lint
|
2019-07-10 14:06:18 -05:00
|
|
|
LINTER_CONFIG := .golangci.yaml
|
2019-05-01 12:00:04 -05:00
|
|
|
|
2019-06-26 11:41:22 -05:00
|
|
|
# docker
|
2019-07-09 13:52:24 -05:00
|
|
|
DOCKER_MAKE_TARGET := build
|
2021-04-08 13:18:42 +02:00
|
|
|
DOCKER_CMD_FLAGS :=
|
2019-07-09 13:52:24 -05:00
|
|
|
|
|
|
|
# docker image options
|
|
|
|
DOCKER_REGISTRY ?= quay.io
|
2020-05-12 23:58:13 -07:00
|
|
|
DOCKER_FORCE_CLEAN ?= true
|
2019-07-09 13:52:24 -05:00
|
|
|
DOCKER_IMAGE_NAME ?= airshipctl
|
|
|
|
DOCKER_IMAGE_PREFIX ?= airshipit
|
2020-11-10 10:33:12 -06:00
|
|
|
DOCKER_IMAGE_TAG ?= latest
|
2019-07-11 10:39:36 -05:00
|
|
|
DOCKER_IMAGE ?= $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_PREFIX)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)
|
2019-10-02 11:05:59 -05:00
|
|
|
DOCKER_TARGET_STAGE ?= release
|
2020-02-12 15:52:52 -06:00
|
|
|
PUBLISH ?= false
|
2021-04-08 13:18:42 +02:00
|
|
|
# use this variables to override base images in internal build process
|
|
|
|
ifneq ($(strip $(DOCKER_BASE_GO_IMAGE)),)
|
|
|
|
DOCKER_CMD_FLAGS += --build-arg GO_IMAGE=$(strip $(DOCKER_BASE_GO_IMAGE))
|
|
|
|
endif
|
|
|
|
ifneq ($(strip $(DOCKER_BASE_RELEASE_IMAGE)),)
|
|
|
|
DOCKER_CMD_FLAGS += --build-arg RELEASE_IMAGE=$(strip $(DOCKER_BASE_RELEASE_IMAGE))
|
|
|
|
endif
|
2020-11-10 16:56:28 +01:00
|
|
|
# use this variable for image labels added in internal build process
|
|
|
|
LABEL ?= org.airshipit.build=community
|
|
|
|
COMMIT ?= $(shell git rev-parse HEAD)
|
2019-06-26 11:41:22 -05:00
|
|
|
|
2019-04-26 15:43:23 -05:00
|
|
|
# go options
|
2019-10-16 16:42:01 -05:00
|
|
|
PKG ?= ./...
|
|
|
|
TESTS ?= .
|
|
|
|
TEST_FLAGS ?=
|
|
|
|
COVER_FLAGS ?=
|
|
|
|
COVER_PROFILE ?= cover.out
|
2020-07-10 10:43:28 -05:00
|
|
|
COVER_EXCLUDE ?= (zz_generated|errors)
|
2019-05-07 10:00:07 -05:00
|
|
|
|
2019-12-12 13:03:27 -06:00
|
|
|
# proxy options
|
|
|
|
PROXY ?= http://proxy.foo.com:8000
|
|
|
|
NO_PROXY ?= localhost,127.0.0.1,.svc.cluster.local
|
|
|
|
USE_PROXY ?= false
|
|
|
|
|
2020-10-09 18:06:21 +04:00
|
|
|
# docker build flags
|
2021-04-08 13:18:42 +02:00
|
|
|
DOCKER_CMD_FLAGS += --network=host
|
2020-10-09 18:06:21 +04:00
|
|
|
DOCKER_CMD_FLAGS += --force-rm=$(DOCKER_FORCE_CLEAN)
|
|
|
|
|
|
|
|
DOCKER_PROXY_FLAGS := --build-arg http_proxy=$(PROXY)
|
|
|
|
DOCKER_PROXY_FLAGS += --build-arg https_proxy=$(PROXY)
|
|
|
|
DOCKER_PROXY_FLAGS += --build-arg HTTP_PROXY=$(PROXY)
|
|
|
|
DOCKER_PROXY_FLAGS += --build-arg HTTPS_PROXY=$(PROXY)
|
|
|
|
DOCKER_PROXY_FLAGS += --build-arg no_proxy=$(NO_PROXY)
|
|
|
|
DOCKER_PROXY_FLAGS += --build-arg NO_PROXY=$(NO_PROXY)
|
|
|
|
|
|
|
|
ifeq ($(USE_PROXY), true)
|
|
|
|
DOCKER_CMD_FLAGS += $(DOCKER_PROXY_FLAGS)
|
|
|
|
endif
|
|
|
|
|
2020-01-08 09:45:02 -06:00
|
|
|
# Godoc server options
|
|
|
|
GD_PORT ?= 8080
|
|
|
|
|
2020-05-12 17:47:43 +00:00
|
|
|
# Documentation location
|
|
|
|
DOCS_DIR ?= docs
|
|
|
|
|
2020-05-27 15:43:34 -05:00
|
|
|
# document validation options
|
|
|
|
UNAME != uname
|
|
|
|
export KIND_URL ?= https://kind.sigs.k8s.io/dl/v0.8.1/kind-$(UNAME)-amd64
|
2020-08-24 09:27:43 -05:00
|
|
|
KUBECTL_VERSION ?= v1.18.6
|
2020-05-27 15:43:34 -05:00
|
|
|
export KUBECTL_URL ?= https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl
|
|
|
|
|
2020-10-09 18:06:21 +04:00
|
|
|
# Plugins options
|
|
|
|
PLUGINS_DIR := krm-functions
|
|
|
|
PLUGINS := $(subst $(PLUGINS_DIR)/,,$(wildcard $(PLUGINS_DIR)/*))
|
|
|
|
PLUGINS_IMAGE_TGT := $(foreach tgt,$(PLUGINS),docker-image-$(tgt))
|
2021-04-08 13:18:42 +02:00
|
|
|
# use this variables to override base images in internal build process
|
|
|
|
ifneq ($(strip $(DOCKER_BASE_PLUGINS_BUILD_IMAGE)),)
|
|
|
|
DOCKER_CMD_FLAGS += --build-arg PLUGINS_BUILD_IMAGE=$(strip $(DOCKER_BASE_PLUGINS_BUILD_IMAGE))
|
|
|
|
endif
|
|
|
|
ifneq ($(strip $(DOCKER_BASE_PLUGINS_RELEASE_IMAGE)),)
|
|
|
|
DOCKER_CMD_FLAGS += --build-arg PLUGINS_RELEASE_IMAGE=$(strip $(DOCKER_BASE_PLUGINS_RELEASE_IMAGE))
|
|
|
|
endif
|
|
|
|
|
2020-10-09 18:06:21 +04:00
|
|
|
|
|
|
|
$(PLUGINS):
|
|
|
|
@CGO_ENABLED=0 go build -o $(BINDIR)/$@ $(GO_FLAGS) ./$(PLUGINS_DIR)/$@/
|
|
|
|
|
2020-01-08 09:45:02 -06:00
|
|
|
.PHONY: depend
|
|
|
|
depend:
|
2019-06-26 11:41:22 -05:00
|
|
|
@go mod download
|
|
|
|
|
2019-04-26 11:33:16 -05:00
|
|
|
.PHONY: build
|
2020-01-08 09:45:02 -06:00
|
|
|
build: depend
|
2019-10-02 19:57:33 +00:00
|
|
|
@CGO_ENABLED=0 go build -o $(BINDIR)/$(EXECUTABLE_CLI) $(GO_FLAGS)
|
2019-04-26 11:33:16 -05:00
|
|
|
|
2020-01-08 09:45:02 -06:00
|
|
|
.PHONY: install
|
|
|
|
install: depend
|
|
|
|
install:
|
|
|
|
@CGO_ENABLED=0 go install .
|
|
|
|
|
2019-04-26 11:33:16 -05:00
|
|
|
.PHONY: test
|
2019-05-30 10:02:54 -05:00
|
|
|
test: lint
|
2019-07-11 08:29:15 -05:00
|
|
|
test: cover
|
2020-05-05 22:37:18 -05:00
|
|
|
test: check-copyright
|
2019-04-26 11:33:16 -05:00
|
|
|
|
|
|
|
.PHONY: unit-tests
|
2019-10-02 11:05:59 -05:00
|
|
|
unit-tests: TESTFLAGS += -race -v
|
|
|
|
unit-tests:
|
2019-05-01 12:00:04 -05:00
|
|
|
@echo "Performing unit test step..."
|
2019-10-02 19:57:33 +00:00
|
|
|
@go test -run $(TESTS) $(PKG) $(TESTFLAGS) $(COVER_FLAGS)
|
2019-05-01 12:00:04 -05:00
|
|
|
@echo "All unit tests passed"
|
2019-04-26 11:33:16 -05:00
|
|
|
|
2019-07-11 08:29:15 -05:00
|
|
|
.PHONY: cover
|
2020-06-08 23:17:23 +04:00
|
|
|
cover: COVER_FLAGS = -covermode=atomic -coverprofile=fullcover.out
|
2019-07-11 08:29:15 -05:00
|
|
|
cover: unit-tests
|
2020-06-08 23:17:23 +04:00
|
|
|
@grep -vE "$(COVER_EXCLUDE)" fullcover.out > $(COVER_PROFILE)
|
2019-07-11 08:29:15 -05:00
|
|
|
@./tools/coverage_check $(COVER_PROFILE)
|
|
|
|
|
2020-01-08 09:45:02 -06:00
|
|
|
.PHONY: fmt
|
|
|
|
fmt: lint
|
|
|
|
|
2019-04-26 11:33:16 -05:00
|
|
|
.PHONY: lint
|
2019-11-07 15:28:04 -06:00
|
|
|
lint: tidy
|
2019-10-22 16:22:39 -05:00
|
|
|
lint: $(LINTER)
|
2019-05-01 12:00:04 -05:00
|
|
|
@echo "Performing linting step..."
|
2020-01-07 12:03:26 -06:00
|
|
|
@./tools/whitespace_linter
|
2019-10-22 16:22:39 -05:00
|
|
|
@./$(LINTER) run --config $(LINTER_CONFIG)
|
2019-05-01 12:00:04 -05:00
|
|
|
@echo "Linting completed successfully"
|
2019-04-26 11:33:16 -05:00
|
|
|
|
2019-11-07 15:28:04 -06:00
|
|
|
.PHONY: tidy
|
|
|
|
tidy:
|
|
|
|
@echo "Checking that go.mod is up to date..."
|
|
|
|
@./tools/gomod_check
|
|
|
|
@echo "go.mod is up to date"
|
|
|
|
|
2020-05-28 15:34:44 -05:00
|
|
|
.PHONY: golint
|
|
|
|
golint:
|
|
|
|
@./tools/golint
|
|
|
|
|
2020-01-08 09:45:02 -06:00
|
|
|
.PHONY: images
|
|
|
|
images: docker-image
|
2020-10-09 18:06:21 +04:00
|
|
|
images: $(PLUGINS_IMAGE_TGT)
|
2020-01-08 09:45:02 -06:00
|
|
|
|
2019-06-26 11:41:22 -05:00
|
|
|
.PHONY: docker-image
|
|
|
|
docker-image:
|
2020-10-09 18:06:21 +04:00
|
|
|
@docker build . $(DOCKER_CMD_FLAGS) \
|
2020-11-10 16:56:28 +01:00
|
|
|
--label $(LABEL) \
|
|
|
|
--label "org.opencontainers.image.revision=$(COMMIT)" \
|
|
|
|
--label "org.opencontainers.image.created=$(shell date --rfc-3339=seconds --utc)" \
|
|
|
|
--label "org.opencontainers.image.title=$(DOCKER_IMAGE_NAME)" \
|
2020-10-09 18:06:21 +04:00
|
|
|
--target $(DOCKER_TARGET_STAGE) \
|
|
|
|
--build-arg MAKE_TARGET=$(DOCKER_MAKE_TARGET) \
|
|
|
|
--tag $(DOCKER_IMAGE)
|
2020-02-12 15:52:52 -06:00
|
|
|
ifeq ($(PUBLISH), true)
|
|
|
|
@docker push $(DOCKER_IMAGE)
|
|
|
|
endif
|
2019-12-12 13:03:27 -06:00
|
|
|
|
2021-03-14 22:39:09 -05:00
|
|
|
# Use specific Dockerfile instead of general one to make image for kubeval-validator and toolbox
|
2021-03-23 16:39:40 +04:00
|
|
|
docker-image-toolbox: DOCKER_CMD_FLAGS+=-f krm-functions/toolbox/Dockerfile
|
2021-03-14 22:39:09 -05:00
|
|
|
docker-image-kubeval-validator: DOCKER_CMD_FLAGS+=-f krm-functions/kubeval-validator/image/Dockerfile
|
2020-10-09 18:06:21 +04:00
|
|
|
.PHONY: $(PLUGINS_IMAGE_TGT)
|
|
|
|
$(PLUGINS_IMAGE_TGT):
|
|
|
|
$(eval plugin_name=$(subst docker-image-,,$@))
|
|
|
|
@docker build . $(DOCKER_CMD_FLAGS) \
|
2020-11-10 16:56:28 +01:00
|
|
|
--label $(LABEL) \
|
|
|
|
--label "org.opencontainers.image.revision=$(COMMIT)" \
|
|
|
|
--label "org.opencontainers.image.created=$(shell date --rfc-3339=seconds --utc)" \
|
|
|
|
--label "org.opencontainers.image.title=$(DOCKER_IMAGE_NAME)" \
|
2020-10-09 18:06:21 +04:00
|
|
|
--target $(DOCKER_TARGET_STAGE) \
|
|
|
|
--build-arg MAKE_TARGET=$(plugin_name) \
|
|
|
|
--build-arg BINARY=$(plugin_name) \
|
|
|
|
--tag $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_PREFIX)/$(plugin_name):$(DOCKER_IMAGE_TAG)
|
|
|
|
ifeq ($(PUBLISH), true)
|
|
|
|
@docker push $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_PREFIX)/$(plugin_name):$(DOCKER_IMAGE_TAG)
|
|
|
|
endif
|
2019-07-09 13:52:24 -05:00
|
|
|
|
|
|
|
.PHONY: print-docker-image-tag
|
|
|
|
print-docker-image-tag:
|
|
|
|
@echo "$(DOCKER_IMAGE)"
|
2019-06-26 11:41:22 -05:00
|
|
|
|
2020-03-03 11:25:27 -05:00
|
|
|
.PHONY: docker-image-test-suite
|
2020-11-24 22:10:14 -08:00
|
|
|
docker-image-test-suite: DOCKER_MAKE_TARGET = "cover update-golden generate check-git-diff"
|
2020-03-03 11:25:27 -05:00
|
|
|
docker-image-test-suite: DOCKER_TARGET_STAGE = builder
|
|
|
|
docker-image-test-suite: docker-image
|
|
|
|
|
2019-06-26 11:41:22 -05:00
|
|
|
.PHONY: docker-image-unit-tests
|
2019-07-11 08:29:15 -05:00
|
|
|
docker-image-unit-tests: DOCKER_MAKE_TARGET = cover
|
2019-10-02 11:05:59 -05:00
|
|
|
docker-image-unit-tests: DOCKER_TARGET_STAGE = builder
|
2019-06-26 11:41:22 -05:00
|
|
|
docker-image-unit-tests: docker-image
|
|
|
|
|
|
|
|
.PHONY: docker-image-lint
|
2020-11-04 16:14:51 +00:00
|
|
|
docker-image-lint: DOCKER_MAKE_TARGET = "lint check-copyright"
|
2019-10-02 11:05:59 -05:00
|
|
|
docker-image-lint: DOCKER_TARGET_STAGE = builder
|
2019-06-26 11:41:22 -05:00
|
|
|
docker-image-lint: docker-image
|
|
|
|
|
2020-05-28 15:34:44 -05:00
|
|
|
.PHONY: docker-image-golint
|
|
|
|
docker-image-golint: DOCKER_MAKE_TARGET = golint
|
|
|
|
docker-image-golint: DOCKER_TARGET_STAGE = builder
|
|
|
|
docker-image-golint: docker-image
|
|
|
|
|
2019-04-26 11:33:16 -05:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
@rm -fr $(BINDIR)
|
2019-07-11 08:29:15 -05:00
|
|
|
@rm -fr $(COVER_PROFILE)
|
2019-04-26 11:33:16 -05:00
|
|
|
|
|
|
|
.PHONY: docs
|
|
|
|
docs:
|
2020-05-08 15:17:24 +00:00
|
|
|
tox
|
2020-01-08 09:45:02 -06:00
|
|
|
|
|
|
|
.PHONY: godoc
|
|
|
|
godoc:
|
|
|
|
@go install golang.org/x/tools/cmd/godoc
|
|
|
|
@echo "Follow this link to package documentation: http://localhost:${GD_PORT}/pkg/opendev.org/airship/airshipctl/"
|
2020-02-12 09:20:21 -06:00
|
|
|
@godoc -http=":${GD_PORT}"
|
2020-01-08 09:45:02 -06:00
|
|
|
|
2020-05-12 17:47:43 +00:00
|
|
|
.PHONY: cli-docs
|
|
|
|
cli-docs:
|
|
|
|
@echo "Generating CLI documentation..."
|
|
|
|
@go run $(DOCS_DIR)/tools/generate_cli_docs.go
|
|
|
|
@echo "CLI documentation generated"
|
|
|
|
|
2020-01-08 09:45:02 -06:00
|
|
|
.PHONY: releasenotes
|
|
|
|
releasenotes:
|
2019-04-26 11:33:16 -05:00
|
|
|
@echo "TODO"
|
2019-05-01 16:56:42 -05:00
|
|
|
|
2019-10-22 16:22:39 -05:00
|
|
|
$(TOOLBINDIR):
|
|
|
|
mkdir -p $(TOOLBINDIR)
|
|
|
|
|
|
|
|
$(LINTER): $(TOOLBINDIR)
|
|
|
|
./tools/install_linter
|
|
|
|
|
2019-05-01 16:56:42 -05:00
|
|
|
.PHONY: update-golden
|
2019-07-11 10:39:36 -05:00
|
|
|
update-golden: delete-golden
|
2019-10-02 11:05:59 -05:00
|
|
|
update-golden: TESTFLAGS += -update
|
2019-06-25 16:31:11 -05:00
|
|
|
update-golden: PKG = opendev.org/airship/airshipctl/cmd/...
|
2019-07-11 10:39:36 -05:00
|
|
|
update-golden: unit-tests
|
2020-05-12 17:47:43 +00:00
|
|
|
update-golden: cli-docs
|
2019-07-11 10:39:36 -05:00
|
|
|
|
|
|
|
# The delete-golden target is a utility for update-golden
|
|
|
|
.PHONY: delete-golden
|
|
|
|
delete-golden:
|
|
|
|
@find . -type f -name "*.golden" -delete
|
2020-03-03 11:25:27 -05:00
|
|
|
|
|
|
|
# Used by gates after unit-tests and update-golden targets to ensure no files are deleted.
|
|
|
|
.PHONY: check-git-diff
|
|
|
|
check-git-diff:
|
2020-05-04 21:59:56 -07:00
|
|
|
@./tools/git_diff_check
|
2020-05-05 22:37:18 -05:00
|
|
|
|
|
|
|
# add-copyright is a utility to add copyright header to missing files
|
|
|
|
.PHONY: add-copyright
|
|
|
|
add-copyright:
|
|
|
|
@./tools/add_license.sh
|
|
|
|
|
|
|
|
# check-copyright is a utility to check if copyright header is present on all files
|
|
|
|
.PHONY: check-copyright
|
|
|
|
check-copyright:
|
|
|
|
@./tools/check_copyright
|
2020-05-27 15:43:34 -05:00
|
|
|
|
|
|
|
# Validate YAMLs for all sites
|
|
|
|
.PHONY: validate-docs
|
|
|
|
validate-docs:
|
|
|
|
@./tools/validate_docs
|
2020-11-02 16:39:50 +04:00
|
|
|
|
|
|
|
# Generate code
|
|
|
|
generate: controller-gen
|
|
|
|
$(CONTROLLER_GEN) object:headerFile="tools/license_go.txt" paths="./..."
|
|
|
|
|
|
|
|
# find or download controller-gen
|
|
|
|
# download controller-gen if necessary
|
|
|
|
controller-gen:
|
|
|
|
ifeq (, $(shell which controller-gen))
|
|
|
|
@{ \
|
|
|
|
set -e ;\
|
|
|
|
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
|
|
|
|
cd $$CONTROLLER_GEN_TMP_DIR ;\
|
|
|
|
go mod init tmp ;\
|
|
|
|
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.5 ;\
|
|
|
|
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
|
|
|
|
}
|
|
|
|
CONTROLLER_GEN=$(GOBIN)/controller-gen
|
|
|
|
else
|
|
|
|
CONTROLLER_GEN=$(shell which controller-gen)
|
|
|
|
endif
|