forked from verrazzano/verrazzano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
225 lines (186 loc) · 7.87 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
221
222
223
224
# Copyright (C) 2020, 2021, 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
SCRIPT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))/../build
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"
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
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
DIST_DIR:=dist
K8S_NAMESPACE:=default
WATCH_NAMESPACE:=
EXTRA_PARAMS=
INTEG_RUN_ID=
ENV_NAME=verrazzano-platform-operator
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
CLUSTER_DUMP_LOCATION ?= platform-operator-integ-cluster-dump
# 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 "${GO_LDFLAGS}" \
-o out/linux_amd64/verrazzano-platform-operator \
main.go
.PHONY: go-install
go-install:
$(GO) install ./...
.PHONY: manifests
manifests: platform-manifests generate-api-proxy-configmap
#
# Docker-related tasks
#
.PHONY: docker-clean
docker-clean:
rm -rf ${DIST_DIR}
.PHONY: docker-build
docker-build: generate-bom go-build-linux
@echo Building verrazzano-platform-operator image ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}
@echo using verrazzano-application-operator image ${VERRAZZANO_APPLICATION_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}" \
-t ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} .
.PHONY: docker-push
docker-push: docker-build
docker tag ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} ${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG}
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;
docker push ${DOCKER_IMAGE_FULLNAME}:latest;
endif
#
# Test-related tasks
#
.PHONY: unit-test
unit-test: go-install
$(GO) test -v ./internal/... ./controllers/... ./apis/...
#
# Test-related tasks
#
# On Jenkins we have pre-created clusters ready to go that are named specifically for the integ-test case
CLUSTER_NAME = verrazzano
VERRAZZANO_NS = verrazzano-install
BUILD_DEPLOY = build/deploy
OPERATOR_YAML ?= ${BUILD_DEPLOY}/operator.yaml
DEPLOY = deploy
OPERATOR_SETUP = test/operatorsetup
CLUSTER_DUMP_LOCATION ?= platform-operator-integ-cluster-dump
KIND_CONFIG ?= kind-config.yaml
.PHONY: integ-test
integ-test: create-cluster generate-operator-yaml
echo 'Load docker image for the verrazzano-platform-operator...'
kind load docker-image --name ${CLUSTER_NAME} ${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG}
echo 'Deploy verrazzano platform operator ...'
kubectl apply -f ${OPERATOR_YAML} || (echo 'Platform operator install failed, capturing kind cluster dump'; ../tools/scripts/k8s-dump-cluster.sh -d ${CLUSTER_DUMP_LOCATION} -r ${CLUSTER_DUMP_LOCATION}/analysis.report; exit 1)
echo 'Run tests...'
ginkgo -v --keepGoing -cover test/integ/... || (echo 'Platform operator tests failed, capturing kind cluster dump'; ../tools/scripts/k8s-dump-cluster.sh -d ${CLUSTER_DUMP_LOCATION} -r ${CLUSTER_DUMP_LOCATION}/analysis.report; exit 1)
.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} ../tools/scripts/generate_operator_yaml.sh > ${OPERATOR_YAML}
.PHONY: cleanup-cluster
cleanup-cluster:
./build/scripts/cleanup.sh ${CLUSTER_NAME}
.PHONY: create-cluster
create-cluster:
kind_clusters=$$(kind get clusters) ; \
if [ -z "$${kind_clusters}" ] || ! kind get clusters | egrep "^${CLUSTER_NAME}\$$" > /dev/null ; then \
echo 'Create cluster...' ;\
echo 'KUBECONFIG=${KUBECONFIG}' ;\
HTTP_PROXY="" HTTPS_PROXY="" http_proxy="" https_proxy="" time kind create cluster -v 1 \
--name ${CLUSTER_NAME} \
--wait 5m \
--config=test/${KIND_CONFIG} ;\
kubectl config set-context kind-${CLUSTER_NAME} ;\
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"; \
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} $(MAKE) generate-operator-yaml ; \
else \
echo "VZ_DEV_IMAGE not defined, please set it to a valid image name/tag"; \
fi
.PHONY: generate-api-proxy-configmap
generate-api-proxy-configmap:
hack/generate-api-proxy-configmap.sh \
../pkg/proxy/conf_lua_template.go \
../pkg/proxy/auth_lua_template.go \
../pkg/proxy/nginx_conf_template.go \
../pkg/proxy/startup_sh_template.go \
../pkg/proxy/reload_sh_template.go \
> helm_config/charts/verrazzano/templates/verrazzano-api-configmap.yaml
.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} ${DOCKER_IMAGE_NAME} ${DOCKER_IMAGE_TAG} out/generated-verrazzano-bom.json