-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
132 lines (108 loc) · 3.94 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
# Portions of the code in this file are derived from https://github.com/cert-manager/webhook-example/blob/master/Makefile
# Portions of the code in this file are derived from https://gitlab.com/dn13/cert-manager-webhook-oci/-/blob/1.1.0/Makefile
OS ?= $(shell go env GOOS)
ARCH ?= $(shell go env GOARCH)
GO ?= GO111MODULE=on CGO_ENABLED=0 go
GO_LDFLAGS ?= -s -w -extldflags -static
OUT := $(shell pwd)/_out
KUBE_VERSION=1.24.2
DEFAULT_RETRIES:=5
#
# Retry a command a parameterized amount of times.
#
define retry_cmd
for i in `seq 1 $1`; do $2 && break; done
endef
define retry_docker_push
$(call retry_cmd,${DEFAULT_RETRIES},docker push $1)
endef
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
NAME ?= cert-manager-webhook-oci
REPO_NAME:=cert-manager-webhook-oci
BASE_IMAGE ?= ghcr.io/verrazzano/verrazzano-base:v1.0.0-20230327155846-4653b27@sha256:e82f7e630719a9f5a7309c41773385b273ec749f0e1ded96baa1a3f7a7e576e0
CREATE_LATEST_TAG=0
DOCKER_IMAGE_TAG ?= local-$(shell git rev-parse --short HEAD)
SHORT_COMMIT_HASH ?= $(shell git rev-parse --short=8 HEAD)
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
$(shell mkdir -p "$(OUT)")
export TEST_ASSET_ETCD=_test/kubebuilder/bin/etcd
export TEST_ASSET_KUBE_APISERVER=_test/kubebuilder/bin/kube-apiserver
export TEST_ASSET_KUBECTL=_test/kubebuilder/bin/kubectl
.PHONY: rendered-manifest.yaml
rendered-manifest.yaml:
helm template \
cert-manager-webhook-oci \
--set image.repository=$(DOCKER_IMAGE_FULLNAME) \
--set image.tag=$(DOCKER_IMAGE_TAG) \
--namespace cert-manager \
deploy/cert-manager-webhook-oci > "$(OUT)/rendered-manifest.yaml"
#
# Go build related tasks
#
.PHONY: go-build
go-build:
$(GO) build \
-ldflags "${GO_LDFLAGS}" \
-o bin/$(shell uname)_$(shell uname -m)/${NAME} \
main.go
.PHONY: go-build-linux
go-build-linux:
GOOS=linux GOARCH=amd64 $(GO) build \
-ldflags "-s -w ${GO_LDFLAGS}" \
-o bin/linux_amd64/${NAME} \
main.go
.PHONY: go-build-linux-debug
go-build-linux-debug:
GOOS=linux GOARCH=amd64 $(GO) build \
-ldflags "${GO_LDFLAGS}" \
-o out/linux_amd64/${NAME} \
main.go
.PHONY: docker-build
docker-build: go-build-linux docker-build-common
.PHONY: docker-build-common
docker-build-common:
@echo Building ${NAME} image ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}
docker build --pull \
--build-arg BASE_IMAGE=${BASE_IMAGE} \
--build-arg EXEC_NAME=${NAME} \
--build-arg EXEC_DIR=bin/linux_amd64 \
-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