1
+ # Copyright 2021 The Kubernetes Authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ include versions.mk
1
16
2
17
# Image URL to use all building/pushing image targets
3
18
IMG ?= controller:latest
@@ -10,6 +25,20 @@ GOLANGCI_LINT_VER := v1.31.0
10
25
GOLANGCI_LINT_BIN := golangci-lint
11
26
GOLANGCI_LINT := $(TOOLS_BIN_DIR ) /$(GOLANGCI_LINT_BIN ) -$(GOLANGCI_LINT_VER )
12
27
28
+ STAGING_REGISTRY ?= gcr.io/k8s-staging-capi-ibmcloud
29
+ REGISTRY ?= $(STAGING_REGISTRY )
30
+ RELEASE_TAG ?= $(shell git describe --abbrev=0 2>/dev/null)
31
+ PULL_BASE_REF ?= $(RELEASE_TAG ) # PULL_BASE_REF will be provided by Prow
32
+ RELEASE_ALIAS_TAG ?= $(PULL_BASE_REF )
33
+
34
+ TAG ?= dev
35
+ ARCH ?= amd64
36
+ ALL_ARCH ?= amd64 ppc64le
37
+
38
+ # main controller
39
+ CORE_IMAGE_NAME ?= cluster-api-ibmcloud-controller
40
+ CORE_CONTROLLER_IMG ?= $(REGISTRY ) /$(CORE_IMAGE_NAME )
41
+
13
42
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
14
43
ifeq (,$(shell go env GOBIN) )
15
44
GOBIN =$(shell go env GOPATH) /bin
60
89
generate : controller-gen
61
90
$(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
62
91
63
- # Build the docker image
64
- docker-build :
65
- docker build . -t ${IMG}
66
-
67
- # Push the docker image
68
- docker-push :
69
- docker push ${IMG}
70
-
71
92
images : docker-build
72
93
# find or download controller-gen
73
94
# download controller-gen if necessary
@@ -96,3 +117,63 @@ lint: $(GOLANGCI_LINT) ## Lint codebase
96
117
97
118
$(GOLANGCI_LINT ) : # # Build golangci-lint from tools folder.
98
119
GOBIN=$(TOOLS_BIN_DIR ) $(GO_INSTALL ) github.com/golangci/golangci-lint/cmd/golangci-lint $(GOLANGCI_LINT_BIN ) $(GOLANGCI_LINT_VER )
120
+
121
+ # # --------------------------------------
122
+ # # Docker
123
+ # # --------------------------------------
124
+
125
+ .PHONY : docker-build
126
+ docker-build : docker-pull-prerequisites # # Build the docker image for controller-manager
127
+ docker build --build-arg ARCH=$(ARCH ) . -t $(CORE_CONTROLLER_IMG ) -$(ARCH ) :$(TAG )
128
+
129
+ .PHONY : docker-push
130
+ docker-push : # # Push the docker image
131
+ docker push $(CORE_CONTROLLER_IMG ) -$(ARCH ) :$(TAG )
132
+
133
+ .PHONY : docker-pull-prerequisites
134
+ docker-pull-prerequisites :
135
+ docker pull docker.io/docker/dockerfile:1.1-experimental
136
+ docker pull docker.io/library/golang:$(GOLANG_VERSION )
137
+ docker pull gcr.io/distroless/static:latest
138
+
139
+ # # --------------------------------------
140
+ # # Docker - All ARCH
141
+ # # --------------------------------------
142
+
143
+ .PHONY : docker-build-all # # Build all the architecture docker images
144
+ docker-build-all : $(addprefix docker-build-,$(ALL_ARCH ) )
145
+
146
+ docker-build-% :
147
+ $(MAKE ) ARCH=$* docker-build
148
+
149
+ .PHONY : docker-push-all # # Push all the architecture docker images
150
+ docker-push-all : $(addprefix docker-push-,$(ALL_ARCH ) )
151
+ $(MAKE ) docker-push-core-manifest
152
+
153
+ docker-push-% :
154
+ $(MAKE ) ARCH=$* docker-push
155
+
156
+ .PHONY : docker-push-core-manifest
157
+ docker-push-core-manifest : # # Push the fat manifest docker image.
158
+ # # Minimum docker version 18.06.0 is required for creating and pushing manifest images.
159
+ $(MAKE ) docker-push-manifest CONTROLLER_IMG=$(CORE_CONTROLLER_IMG ) MANIFEST_FILE=$(CORE_MANIFEST_FILE )
160
+
161
+ .PHONY : docker-push-manifest
162
+ docker-push-manifest :
163
+ docker manifest create --amend $(CONTROLLER_IMG ) :$(TAG ) $(shell echo $(ALL_ARCH ) | sed -e "s~[^ ]* ~$(CONTROLLER_IMG ) \-&:$(TAG ) ~g")
164
+ @for arch in $(ALL_ARCH ) ; do docker manifest annotate --arch $$ {arch} ${CONTROLLER_IMG} :${TAG} ${CONTROLLER_IMG} -$$ {arch}:${TAG} ; done
165
+ docker manifest push --purge ${CONTROLLER_IMG} :${TAG}
166
+
167
+ # # --------------------------------------
168
+ # # Release
169
+ # # --------------------------------------
170
+
171
+ .PHONY : release-alias-tag
172
+ release-alias-tag : # Adds the tag to the last build tag.
173
+ gcloud container images add-tag -q $(CORE_CONTROLLER_IMG ) :$(TAG ) $(CORE_CONTROLLER_IMG ) :$(RELEASE_ALIAS_TAG )
174
+
175
+ .PHONY : release-staging
176
+ release-staging : # # Builds and push container images to the staging image registry.
177
+ $(MAKE ) docker-build-all
178
+ $(MAKE ) docker-push-all
179
+ $(MAKE ) release-alias-tag
0 commit comments