forked from kubernetes-sigs/cluster-api-provider-vsphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
135 lines (107 loc) · 4.61 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
# Copyright 2018 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Image URL to use all building/pushing image targets
PRODUCTION_IMG ?= gcr.io/cnx-cluster-api/vsphere-cluster-api-provider:latest
CI_IMG ?= gcr.io/cnx-cluster-api/vsphere-cluster-api-provider
CLUSTERCTL_CI_IMG ?= gcr.io/cnx-cluster-api/clusterctl
DEV_IMG ?= # <== NOTE: outside dev, change this!!!
# Retrieves the git hash
VERSION ?= $(shell git describe --exact-match 2> /dev/null || \
git describe --match=$(git rev-parse --short=8 HEAD) --always --dirty --abbrev=8)
all: test manager clusterctl
# Run tests
test: generate fmt vet manifests
go test ./pkg/... ./cmd/... -coverprofile cover.out
# Build manager binary
manager: fmt vet
go build -o bin/manager sigs.k8s.io/cluster-api-provider-vsphere/cmd/manager
# Build the clusterctl binary
clusterctl: fmt vet
go build -o bin/clusterctl sigs.k8s.io/cluster-api-provider-vsphere/cmd/clusterctl
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet
go run ./cmd/manager/main.go
# Install CRDs into a cluster
install: manifests
kubectl apply -f config/crds
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests
kubectl apply -f config/crds
kustomize build config/default | kubectl apply -f -
# Generate manifests e.g. CRD, RBAC etc.
manifests:
go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go all
# Run go fmt against code
fmt:
go fmt ./pkg/... ./cmd/...
# Run go vet against code
vet:
go vet ./pkg/... ./cmd/...
# Generate code
generate:
go generate ./pkg/... ./cmd/...
####################################
# DEVELOPMENT Build and Push targets
####################################
# Create YAML file for deployment
dev-yaml:
@echo "updating kustomize image patch file for manager resource"
sed -i'' -e 's@image: .*@image: '"${DEV_IMG}"'@' ./config/default/vsphere_manager_image_patch.yaml
cmd/clusterctl/examples/vsphere/generate-yaml.sh
# Build the docker image
dev-build: test
docker build . -t ${DEV_IMG}
@echo "updating kustomize image patch file for manager resource"
sed -i'' -e 's@image: .*@image: '"${DEV_IMG}"'@' ./config/default/vsphere_manager_image_patch.yaml
# Push the docker image
dev-push:
docker push ${DEV_IMG}
###################################
# PRODUCTION Build and Push targets
###################################
# Create YAML file for deployment
prod-yaml:
@echo "updating kustomize image patch file for manager resource"
sed -i'' -e 's@image: .*@image: '"${PRODUCTION_IMG}"'@' ./config/default/vsphere_manager_image_patch.yaml
cmd/clusterctl/examples/vsphere/generate-yaml.sh
# Build the docker image
prod-build: test
docker build . -t ${PRODUCTION_IMG}
@echo "updating kustomize image patch file for manager resource"
sed -i'' -e 's@image: .*@image: '"${PRODUCTION_IMG}"'@' ./config/default/vsphere_manager_image_patch.yaml
# Push the docker image
prod-push:
@echo "logging into gcr.io registry with key file"
@docker login -u _json_key --password-stdin gcr.io <"$(GCR_KEY_FILE)"
docker push ${PRODUCTION_IMG}
###################################
# CI Build and Push targets
###################################
# Create YAML file for deployment into CI
ci-yaml:
@echo "updating kustomize image patch file for manager resource"
sed -i'' -e 's@image: .*@image: '"$(CI_IMG):$(VERSION)"'@' ./config/default/vsphere_manager_image_patch.yaml
cmd/clusterctl/examples/vsphere/generate-yaml.sh
ci-image: generate fmt vet manifests
docker build . -t "$(CI_IMG):$(VERSION)"
docker build . -f cmd/clusterctl/Dockerfile -t "$(CLUSTERCTL_CI_IMG):$(VERSION)"
@echo "updating kustomize image patch file for manager resource"
sed -i.tmp -e 's@image: .*@image: '"$(CI_IMG):$(VERSION)"'@' ./config/default/vsphere_manager_image_patch.yaml
ci-push: ci-image
# Log into the registry with a service account file. In CI, GCR_KEY_FILE contains the content and not the file name.
@echo "logging into gcr.io registry with key file"
@echo $$GCR_KEY_FILE | docker login -u _json_key --password-stdin gcr.io
docker push "$(CI_IMG):$(VERSION)"
docker push "$(CLUSTERCTL_CI_IMG):$(VERSION)"
@echo docker logout gcr.io