github.com/kyma-project/kyma-environment-broker@v0.0.1/scripts/generic_make_go.mk (about) 1 # Default configuration 2 ifneq ($(strip $(DOCKER_PUSH_REPOSITORY)),) 3 IMG_NAME := $(DOCKER_PUSH_REPOSITORY)$(DOCKER_PUSH_DIRECTORY)/$(APP_NAME) 4 else 5 IMG_NAME := $(APP_NAME) 6 endif 7 8 # Configuration for Kyma Environment Broker cleanup job image 9 ifneq ($(strip $(DOCKER_PUSH_REPOSITORY)),) 10 CLEANUP_IMG_NAME := $(DOCKER_PUSH_REPOSITORY)$(DOCKER_PUSH_DIRECTORY)/$(APP_CLEANUP_NAME) 11 else 12 CLEANUP_IMG_NAME := $(APP_CLEANUP_NAME) 13 endif 14 15 # Configuration for Kyma Environment Broker Subaccount cleaner job image 16 ifneq ($(strip $(DOCKER_PUSH_REPOSITORY)),) 17 SUBACCOUNT_CLEANUP_IMG_NAME := $(DOCKER_PUSH_REPOSITORY)$(DOCKER_PUSH_DIRECTORY)/$(APP_SUBACCOUNT_CLEANUP_NAME) 18 else 19 SUBACCOUNT_CLEANUP_IMG_NAME := $(APP_SUBACCOUNT_CLEANUP_NAME) 20 endif 21 22 # Configuration for Kyma Environment Broker subscription cleanup job image 23 ifneq ($(strip $(DOCKER_PUSH_REPOSITORY)),) 24 SUBSCRIPTION_CLEANUP_IMG_NAME := $(DOCKER_PUSH_REPOSITORY)$(DOCKER_PUSH_DIRECTORY)/$(APP_SUBSCRIPTION_CLEANUP_NAME) 25 else 26 SUBSCRIPTION_CLEANUP_IMG_NAME := $(APP_SUBSCRIPTION_CLEANUP_NAME) 27 endif 28 29 # Configuration for Kyma Environment Broker trial cleanup job image 30 ifneq ($(strip $(DOCKER_PUSH_REPOSITORY)),) 31 TRIAL_CLEANUP_IMG_NAME := $(DOCKER_PUSH_REPOSITORY)$(DOCKER_PUSH_DIRECTORY)/$(APP_TRIAL_CLEANUP_NAME) 32 else 33 TRIAL_CLEANUP_IMG_NAME := $(APP_TRIAL_CLEANUP_NAME) 34 endif 35 36 TAG := $(DOCKER_TAG) 37 # BASE_PKG is a root package of the component 38 BASE_PKG := github.com/kyma-project/control-plane 39 # IMG_GOPATH is a path to go path in the container 40 IMG_GOPATH := /workspace/go 41 # IMG_GOCACHE is a path to go cache in the container 42 IMG_GOCACHE := /root/.cache/go-build 43 # VERIFY_IGNORE is a grep pattern to exclude files and directories from verification 44 VERIFY_IGNORE := /vendor\|/automock 45 46 # Other variables 47 # LOCAL_DIR in a local path to scripts folder 48 LOCAL_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) 49 # COMPONENT_DIR is a local path to commponent 50 COMPONENT_DIR = $(shell pwd) 51 # COMPONENT_NAME is equivalent to the name of the component as defined in it's helm chart 52 COMPONENT_NAME = $(shell basename $(COMPONENT_DIR)) 53 # WORKSPACE_LOCAL_DIR is a path to the scripts folder in the container 54 WORKSPACE_LOCAL_DIR = $(IMG_GOPATH)/src/$(BASE_PKG)/scripts 55 # WORKSPACE_COMPONENT_DIR is a path to commponent in hte container 56 WORKSPACE_COMPONENT_DIR = $(IMG_GOPATH)/src/$(BASE_PKG)/$(APP_PATH) 57 # FILES_TO_CHECK is a command used to determine which files should be verified 58 FILES_TO_CHECK = find . -type f -name "*.go" | grep -v "$(VERIFY_IGNORE)" 59 # DIRS_TO_CHECK is a command used to determine which directories should be verified 60 DIRS_TO_CHECK = go list ./... | grep -v "$(VERIFY_IGNORE)" 61 # DIRS_TO_IGNORE is a command used to determine which directories should not be verified 62 DIRS_TO_IGNORE = go list ./... | grep "$(VERIFY_IGNORE)" 63 # DEPLOYMENT_NAME matches the component's deployment name in the cluster 64 DEPLOYMENT_NAME="kcp-"$(COMPONENT_NAME) 65 # NAMESPACE defines the namespace into which the component is deployed 66 NAMESPACE="kcp-system" 67 68 # Base docker configuration 69 DOCKER_CREATE_OPTS := -v $(LOCAL_DIR):$(WORKSPACE_LOCAL_DIR):delegated --rm -w $(WORKSPACE_COMPONENT_DIR) $(BUILDPACK) 70 71 # Check if go is available 72 ifneq (,$(shell go version 2>/dev/null)) 73 DOCKER_CREATE_OPTS := -v $(shell go env GOCACHE):$(IMG_GOCACHE):delegated -v $(shell go env GOPATH)/pkg/dep:$(IMG_GOPATH)/pkg/dep:delegated $(DOCKER_CREATE_OPTS) 74 endif 75 76 .DEFAULT_GOAL := verify 77 78 # Check if running with TTY 79 ifeq (1, $(shell [ -t 0 ] && echo 1)) 80 DOCKER_INTERACTIVE := -i 81 DOCKER_CREATE_OPTS := -t $(DOCKER_CREATE_OPTS) 82 else 83 DOCKER_INTERACTIVE_START := --attach 84 endif 85 86 # Buildpack directives 87 define buildpack-mount 88 .PHONY: $(1)-local $(1) 89 $(1): 90 @echo make $(1) 91 @docker run $(DOCKER_INTERACTIVE) \ 92 -v $(COMPONENT_DIR):$(WORKSPACE_COMPONENT_DIR):delegated \ 93 $(DOCKER_CREATE_OPTS) make $(1)-local 94 endef 95 96 define buildpack-cp-ro 97 .PHONY: $(1)-local $(1) 98 $(1): 99 @echo make $(1) 100 $$(eval container = $$(shell docker create $(DOCKER_CREATE_OPTS) make $(1)-local)) 101 @docker cp $(COMPONENT_DIR)/. $$(container):$(WORKSPACE_COMPONENT_DIR)/ 102 @docker start $(DOCKER_INTERACTIVE_START) $(DOCKER_INTERACTIVE) $$(container) 103 endef 104 105 .PHONY: verify format release check-gqlgen 106 107 # You may add additional targets/commands to be run on format and verify. Declare the target again in your makefile, 108 # using two double colons. For example to run errcheck on verify add this to your makefile: 109 # 110 # verify:: errcheck 111 # 112 verify:: test check-imports check-fmt errcheck 113 format:: imports fmt 114 115 release: resolve dep-status verify 116 117 docker-create-opts: 118 @echo $(DOCKER_CREATE_OPTS) 119 120 # Targets mounting sources to buildpack 121 MOUNT_TARGETS = build resolve ensure dep-status check-imports imports check-fmt fmt errcheck vet generate gqlgen 122 $(foreach t,$(MOUNT_TARGETS),$(eval $(call buildpack-mount,$(t)))) 123 124 # Builds new Docker image into Minikube's Docker Registry 125 build-to-minikube: 126 @eval $$(minikube docker-env) && docker build -t $(IMG_NAME) . 127 128 build-local: 129 env CGO_ENABLED=0 go build -o $(APP_NAME) ./$(ENTRYPOINT) 130 rm $(APP_NAME) 131 132 resolve-local: 133 dep ensure -vendor-only -v 134 135 ensure-local: 136 dep ensure -v 137 138 dep-status-local: 139 dep status -v 140 141 check-imports-local: 142 @if [ -n "$$(goimports -l $$($(FILES_TO_CHECK)))" ]; then \ 143 echo "✗ some files are not properly formatted or contain not formatted imports. To repair run make imports"; \ 144 goimports -l $$($(FILES_TO_CHECK)); \ 145 exit 1; \ 146 fi; 147 148 imports-local: 149 goimports -w -l $$($(FILES_TO_CHECK)) 150 151 check-fmt-local: 152 @if [ -n "$$(gofmt -l $$($(FILES_TO_CHECK)))" ]; then \ 153 gofmt -l $$($(FILES_TO_CHECK)); \ 154 echo "✗ some files are not properly formatted. To repair run make fmt"; \ 155 exit 1; \ 156 fi; 157 158 fmt-local: 159 go fmt $$($(DIRS_TO_CHECK)) 160 161 errcheck-local: 162 errcheck -blank -asserts -ignorepkg '$$($(DIRS_TO_CHECK) | tr '\n' ',')' -ignoregenerated ./... 163 164 vet-local: 165 go vet $$($(DIRS_TO_CHECK)) 166 167 generate-local: 168 go genrate ./... 169 170 gqlgen-local: 171 ./gqlgen.sh 172 173 check-gqlgen: 174 @echo make gqlgen-check 175 @if [ -n "$$(git status -s pkg/graphql)" ]; then \ 176 echo -e "${RED}✗ gqlgen.sh modified some files, schema and code are out-of-sync${NC}"; \ 177 git status -s pkg/graphql; \ 178 exit 1; \ 179 fi; 180 181 182 # Targets copying sources to buildpack 183 COPY_TARGETS = test 184 $(foreach t,$(COPY_TARGETS),$(eval $(call buildpack-cp-ro,$(t)))) 185 186 test-local: 187 go test ./... 188 189 .PHONY: list 190 list: 191 @$(MAKE) -pRrq -f $(COMPONENT_DIR)/Makefile : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' 192 193 .PHONY: exec 194 exec: 195 @docker run $(DOCKER_INTERACTIVE) \ 196 -v $(COMPONENT_DIR):$(WORKSPACE_COMPONENT_DIR):delegated \ 197 $(DOCKER_CREATE_OPTS) bash 198 199 # Sets locally built image for a given component in Minikube cluster 200 deploy-on-minikube: build-to-minikube 201 kubectl set image -n $(NAMESPACE) deployment/$(DEPLOYMENT_NAME) $(COMPONENT_NAME)=$(DEPLOYMENT_NAME):latest 202 kubectl rollout restart -n $(NAMESPACE) deployment/$(DEPLOYMENT_NAME)