forked from verrazzano/verrazzano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
221 lines (180 loc) · 8.37 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# Copyright (C) 2020, 2023, Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
include ../make/quality.mk
include ../make/generate.mk
include ../make/retry.mk
SCRIPT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))/../build
TOOLS_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))/../tools
NAME:=verrazzano-platform-operator
REPO_NAME:=verrazzano-platform-operator
CONTROLLER_GEN_VERSION ?= $(shell go list -m -f '{{.Version}}' sigs.k8s.io/controller-tools)
CREATE_LATEST_TAG=0
CRD_OPTIONS ?= "crd:crdVersions=v1,maxDescLen=0"
KUBECONFIG ?= ${HOME}/.kube/config
ifndef DOCKER_IMAGE_FULLNAME
DOCKER_IMAGE_NAME ?= ${NAME}-dev
DOCKER_IMAGE_FULLNAME=${DOCKER_IMAGE_NAME}
ifeq ($(MAKECMDGOALS),$(filter $(MAKECMDGOALS),docker-push push-tag))
ifndef DOCKER_REPO
$(error DOCKER_REPO must be defined as the name of the docker repository where image will be pushed)
endif
ifndef DOCKER_NAMESPACE
$(error DOCKER_NAMESPACE must be defined as the name of the docker namespace where image will be pushed)
endif
endif
ifdef DOCKER_NAMESPACE
DOCKER_IMAGE_FULLNAME := ${DOCKER_NAMESPACE}/${DOCKER_IMAGE_FULLNAME}
endif
ifdef DOCKER_REPO
DOCKER_IMAGE_FULLNAME := ${DOCKER_REPO}/${DOCKER_IMAGE_FULLNAME}
endif
endif
DOCKER_IMAGE_TAG ?= local-$(shell git rev-parse --short HEAD)
SHORT_COMMIT_HASH ?= $(shell git rev-parse --short=8 HEAD)
VERRAZZANO_DEV_VERSION ?= $(shell grep verrazzano-development-version ../.verrazzano-development-version | sed -e 's/verrazzano-development-version=//')
VERRAZZANO_VERSION ?= ${VERRAZZANO_DEV_VERSION}-local+${SHORT_COMMIT_HASH}
VERRAZZANO_APPLICATION_OPERATOR_IMAGE ?= verrazzano-application-operator-dev
VERRAZZANO_CLUSTER_OPERATOR_IMAGE ?= verrazzano-cluster-operator-dev
OPERATOR_VERSION = ${DOCKER_IMAGE_TAG}
ifdef RELEASE_VERSION
OPERATOR_VERSION = ${RELEASE_VERSION}
endif
ifndef RELEASE_BRANCH
RELEASE_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
endif
VZ_BASE_IMAGE ?= ghcr.io/verrazzano/verrazzano-base:v1.0.0-20230327155846-4653b27
DIST_DIR:=dist
GO ?= GO111MODULE=on GOPRIVATE=github.com/verrazzano go
GO_LDFLAGS ?= -extldflags -static -X main.buildVersion=${BUILDVERSION} -X main.buildDate=${BUILDDATE}
CRD_PATH=helm_config/charts/verrazzano-platform-operator/crds
SHELL = bash
# Run against the configured Kubernetes cluster in ~/.kube/config
.PHONY: run
run:
$(GO) run main.go --kubeconfig=${KUBECONFIG} --zap-log-level=debug
# Install CRDs into a cluster
.PHONY: install-crds
install-crds:
kubectl apply -f ${CRD_PATH}
# Uninstall CRDs from a cluster
.PHONY: uninstall-crds
uninstall-crds:
kubectl delete -f ${CRD_PATH}
#
# Go build related tasks
#
.PHONY: go-build
go-build:
$(GO) build \
-ldflags "${GO_LDFLAGS}" \
-o out/$(shell uname)_$(shell uname -m)/verrazzano-platform-operator \
main.go
.PHONY: go-build-linux
go-build-linux:
GOOS=linux GOARCH=amd64 $(GO) build \
-ldflags "-s -w ${GO_LDFLAGS}" \
-o out/linux_amd64/verrazzano-platform-operator \
main.go
.PHONY: go-build-linux-debug
go-build-linux-debug:
GOOS=linux GOARCH=amd64 $(GO) build \
-ldflags "${GO_LDFLAGS}" \
-o out/linux_amd64/verrazzano-platform-operator \
main.go
.PHONY: go-install
go-install:
$(GO) install ./...
manifests: export EXP_CRD_PATH ?= experimental/crds
.PHONY: manifests
manifests: platform-manifests
# Generate mocks
.PHONY: mock-gen
mock-gen:
mockgen --build_flags=--mod=mod -destination=mocks/component_mock.go -package=mocks -copyright_file=hack/boilerplate.go.txt github.com/verrazzano/verrazzano/platform-operator/controllers/verrazzano/component/spi ComponentContext,ComponentInfo,ComponentInstaller,ComponentUpgrader,Component
mockgen --build_flags=--mod=mod -destination=mocks/controller_mock.go -package=mocks -copyright_file=hack/boilerplate.go.txt sigs.k8s.io/controller-runtime/pkg/client Client,StatusWriter
mockgen --build_flags=--mod=mod -destination=mocks/runtime_controller_mock.go -package=mocks -copyright_file=hack/boilerplate.go.txt sigs.k8s.io/controller-runtime/pkg/controller Controller
#
# Docker-related tasks
#
.PHONY: docker-clean
docker-clean:
rm -rf ${DIST_DIR}
.PHONY: docker-build
docker-build: generate-bom go-build-linux docker-build-common
.PHONY: docker-build-debug
docker-build-debug: generate-bom go-build-linux-debug docker-build-common
.PHONY: docker-build-common
docker-build-common:
@echo Building verrazzano-platform-operator image ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}
@echo using verrazzano-application-operator image ${VERRAZZANO_APPLICATION_OPERATOR_IMAGE}
@echo using verrazzano-cluster-operator image ${VERRAZZANO_CLUSTER_OPERATOR_IMAGE}
# the TPL file needs to be copied into this dir so it is in the docker build context
cp ../THIRD_PARTY_LICENSES.txt .
docker build --pull -f Dockerfile \
--build-arg VERRAZZANO_APPLICATION_OPERATOR_IMAGE="${VERRAZZANO_APPLICATION_OPERATOR_IMAGE}" \
--build-arg BASE_IMAGE="${VZ_BASE_IMAGE}" \
-t ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} .
.PHONY: docker-push
docker-push: docker-build docker-push-common
.PHONY: docker-push-debug
docker-push-debug: docker-build-debug docker-push-common
.PHONY: docker-push-common
docker-push-common:
docker tag ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} ${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG}
$(call retry_docker_push,${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG})
ifeq ($(CREATE_LATEST_TAG), "1")
docker tag ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} ${DOCKER_IMAGE_FULLNAME}:latest;
$(call retry_docker_push,${DOCKER_IMAGE_FULLNAME}:latest);
endif
#
# Test-related tasks
#
.PHONY: unit-test
unit-test: go-install
$(GO) test ./internal/... ./controllers/... ./apis/...
CLUSTER_NAME ?= verrazzano
BUILD_DEPLOY = build/deploy
OPERATOR_YAML ?= ${BUILD_DEPLOY}/operator.yaml
.PHONY: generate-operator-yaml
generate-operator-yaml:
OPERATOR_DIR=$$(dirname ${OPERATOR_YAML}) ; \
mkdir -p $${OPERATOR_DIR} ; \
env DOCKER_IMAGE=${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG} IMAGE_PULL_SECRETS=${IMAGE_PULL_SECRETS} APP_OPERATOR_IMAGE=${VERRAZZANO_APPLICATION_OPERATOR_IMAGE} CLUSTER_OPERATOR_IMAGE=${VERRAZZANO_CLUSTER_OPERATOR_IMAGE} ../tools/scripts/generate_operator_yaml.sh > ${OPERATOR_YAML}
.PHONY: generate-local-operator-yaml
generate-local-operator-yaml:
OPERATOR_DIR=$$(dirname ${OPERATOR_YAML}) ; \
mkdir -p $${OPERATOR_DIR} ; \
env DOCKER_IMAGE=${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} IMAGE_PULL_SECRETS=${IMAGE_PULL_SECRETS} APP_OPERATOR_IMAGE=${VERRAZZANO_APPLICATION_OPERATOR_IMAGE} CLUSTER_OPERATOR_IMAGE=${VERRAZZANO_CLUSTER_OPERATOR_IMAGE} ../tools/scripts/generate_operator_yaml.sh > ${OPERATOR_YAML}
.PHONY: load-local-operators
load-local-operators: generate-local-operator-yaml
kind load docker-image --name ${CLUSTER_NAME} ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}
if [ -n "${APP_OPERATOR_IMAGE}" ] && [[ "${APP_OPERATOR_IMAGE}" == *:* ]] ; then \
kind load docker-image --name ${CLUSTER_NAME} ${APP_OPERATOR_IMAGE}; \
else \
kind load docker-image --name ${CLUSTER_NAME} ${VERRAZZANO_APPLICATION_OPERATOR_IMAGE}:${DOCKER_IMAGE_TAG}; \
fi
.PHONY: delete-cluster
delete-cluster:
kind delete cluster --name ${CLUSTER_NAME}
.PHONY: push-tag
push-tag:
PUBLISH_TAG="${DOCKER_IMAGE_TAG}"; \
echo "Tagging and pushing image ${DOCKER_IMAGE_FULLNAME}:$$PUBLISH_TAG"; \
docker pull "${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG}"; \
docker tag "${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG}" "${DOCKER_IMAGE_FULLNAME}:$$PUBLISH_TAG"; \
$(call retry_docker_push,"${DOCKER_IMAGE_FULLNAME}:$$PUBLISH_TAG")
.PHONY: create-test-deploy
create-test-deploy:
if [ -n "${VZ_DEV_IMAGE}" ]; then \
IMAGE=$$(echo $${VZ_DEV_IMAGE} | cut -f 1 -d :) ; \
IMAGE_TAG=$$(echo $${VZ_DEV_IMAGE} | cut -f 2 -d :) ; \
DOCKER_IMAGE_FULLNAME=$${IMAGE} DOCKER_IMAGE_TAG=$${IMAGE_TAG} VERRAZZANO_APPLICATION_OPERATOR_IMAGE=$${VZ_APP_OP_IMAGE} VERRAZZANO_CLUSTER_OPERATOR_IMAGE=$${VZ_CLUSTER_OP_IMAGE} $(MAKE) generate-operator-yaml ; \
else \
echo "VZ_DEV_IMAGE not defined, please set it to a valid image name/tag"; \
fi
.PHONY: generate-bom
generate-bom:
@echo Generating BOM verrazzano-platform-operator image ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}
@echo verrazzano-application-operator image ${VERRAZZANO_APPLICATION_OPERATOR_IMAGE}
mkdir out || true
../tools/scripts/generate_bom.sh verrazzano-bom.json ${VERRAZZANO_VERSION} ${VERRAZZANO_APPLICATION_OPERATOR_IMAGE} ${VERRAZZANO_CLUSTER_OPERATOR_IMAGE} ${DOCKER_IMAGE_NAME} ${DOCKER_IMAGE_TAG} out/generated-verrazzano-bom.json