forked from beraldoleal/cloud-api-adaptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
126 lines (101 loc) · 4.54 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
# (C) Copyright Confidential Containers Contributors
# SPDX-License-Identifier: Apache-2.0
.PHONY: all build check fmt vet clean image deploy delete
ARCH ?= $(subst x86_64,amd64,$(shell uname -m))
# Default is dev build. To create release build set RELEASE_BUILD=true
RELEASE_BUILD ?= false
CLOUD_PROVIDER ?=
GOOPTIONS ?= GOOS=linux GOARCH=$(ARCH) CGO_ENABLED=0
GOFLAGS ?=
BINARIES := cloud-api-adaptor agent-protocol-forwarder
SOURCEDIRS := ./cmd ./pkg
PACKAGES := $(shell go list $(addsuffix /...,$(SOURCEDIRS)))
SOURCES := $(shell find $(SOURCEDIRS) -name '*.go' -print)
# End-to-end tests overall run timeout.
TEST_E2E_TIMEOUT ?= 20m
ifeq ($(RELEASE_BUILD),true)
BUILTIN_CLOUD_PROVIDERS ?= aws azure ibmcloud vsphere
else
BUILTIN_CLOUD_PROVIDERS ?= aws azure ibmcloud vsphere libvirt
endif
all: build
build: $(BINARIES)
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
# Targets that depend on .gits-commit can use $(shell cat .git-commit) to get a
# git revision string. They will only be rebuilt if the revision string
# actually changes.
# TODO When a release is created change these steps to use: git describe --abbrev=0 --tags to pull the latest release tag on a specific branch.
.PHONY: .git-commit.tmp
.git-commit: .git-commit.tmp
@cmp $< $@ >/dev/null 2>&1 || cp $< $@
.git-commit.tmp:
@printf "$$(git rev-parse HEAD 2>/dev/null)" >$@
@test -n "$$(git status --porcelain --untracked-files=no)" && echo -dirty >>$@ || true
GOFLAGS += -ldflags="-X 'github.com/confidential-containers/cloud-api-adaptor/cmd.VERSION=$(shell echo "unknown")' \
-X 'github.com/confidential-containers/cloud-api-adaptor/cmd.COMMIT=$(shell cat .git-commit)'"
# Build tags required to build cloud-api-adaptor are derived from BUILTIN_CLOUD_PROVIDERS.
# When libvirt is specified, CGO_ENABLED is set to 1.
space := $() $()
comma := ,
GOFLAGS += -tags=$(subst $(space),$(comma),$(strip $(BUILTIN_CLOUD_PROVIDERS)))
ifneq (,$(filter libvirt,$(BUILTIN_CLOUD_PROVIDERS)))
cloud-api-adaptor: GOOPTIONS := $(subst CGO_ENABLED=0,CGO_ENABLED=1,$(GOOPTIONS))
endif
$(BINARIES): .git-commit $(SOURCES)
$(GOOPTIONS) go build $(GOFLAGS) -o "$@" "cmd/$@/main.go"
##@ Development
.PHONY: escapes
escapes: ## golang memory escapes check
go build $(GOFLAGS) -gcflags="-m -l" ./... 2>&1 | grep "escapes to heap" 1>&2 || true
.PHONY: test
test: ## Run tests.
# Note: sending stderr to stdout so that tools like go-junit-report can
# parse build errors.
go test -v $(GOFLAGS) -cover $(PACKAGES) 2>&1
.PHONY: test-e2e
test-e2e: ## Run end-to-end tests.
go test -v $(GOFLAGS) -timeout $(TEST_E2E_TIMEOUT) -count=1 ./test/e2e
.PHONY: check
check: fmt vet ## Run go vet and go vet against the code.
.PHONY: fmt
fmt: ## Run go fmt against code.
find $(SOURCEDIRS) -name '*.go' -print0 | xargs -0 gofmt -l -s -w
.PHONY: vet
vet: ## Run go vet against code.
go vet $(GOFLAGS) $(PACKAGES)
.PHONY: clean
clean: ## Remove binaries.
rm -fr $(BINARIES) \
.git-commit .git-commit.tmp
##@ Build
.PHONY: image
image: ## Build and push docker image to $registry
hack/build.sh $(shell cat .git-commit)
##@ Deployment
.PHONY: deploy
deploy: ## Deploy cloud-api-adaptor using the operator, according to install/overlays/$(CLOUD_PROVIDER)/kustomization.yaml file.
ifneq ($(CLOUD_PROVIDER),)
kubectl apply -f install/yamls/deploy.yaml
kubectl apply -k install/overlays/$(CLOUD_PROVIDER)
else
$(error CLOUD_PROVIDER is not set)
endif
.PHONY: delete
delete: ## Delete cloud-api-adaptor using the operator, according to install/overlays/$(CLOUD_PROVIDER)/kustomization.yaml file.
ifneq ($(CLOUD_PROVIDER),)
kubectl delete -k install/overlays/$(CLOUD_PROVIDER)
else
$(error CLOUD_PROVIDER is not set)
endif