-
Notifications
You must be signed in to change notification settings - Fork 30
/
Makefile
82 lines (63 loc) · 2.56 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
# To avoid poluting the Makefile, versions and checksums for tooling and
# dependencies are defined at hack/make/deps.mk.
include hack/make/deps.mk
# Include logic that can be reused across projects.
include hack/make/build.mk
include hack/make/tools.mk
# Define target platforms, image builder and the fully qualified image name.
TARGET_PLATFORMS ?= linux/amd64,linux/arm64
REPO ?= rancher
IMAGE = $(REPO)/cis-operator:$(TAG)
TARGET_BIN ?= build/bin/cis-operator
ARCH ?= $(shell docker info --format '{{.ClientInfo.Arch}}')
# TARGET_ARCHS defines all GOARCH used for releasing binaries.
TARGET_ARCHS = arm64 amd64
BUILD_ACTION = --load
.DEFAULT_GOAL := ci
ci: build test validate e2e ## run the targets needed to validate a PR in CI.
clean: ## clean up project.
rm -rf bin build
test: ## run unit tests.
@echo "Running tests"
$(GO) test -race -cover ./...
.PHONY: build
build: ## build project and output binary to TARGET_BIN.
CGO_ENABLED=0 $(GO) build -trimpath -tags "$(GO_TAGS)" -ldflags "$(LINKFLAGS)" -o $(TARGET_BIN)
test-image:
# Instead of loading image, target all platforms, effectivelly testing
# the build for the target architectures.
$(MAKE) build-image BUILD_ACTION="--platform=$(TARGET_PLATFORMS)"
build-image: buildx-machine ## build (and load) the container image targeting the current platform.
$(IMAGE_BUILDER) build -f package/Dockerfile \
--builder $(MACHINE) $(IMAGE_ARGS) \
--build-arg VERSION=$(VERSION) -t "$(IMAGE)" $(BUILD_ACTION) .
@echo "Built $(IMAGE)"
push-image: buildx-machine ## build the container image targeting all platforms defined by TARGET_PLATFORMS and push to a registry.
$(IMAGE_BUILDER) build -f package/Dockerfile \
--builder $(MACHINE) $(IMAGE_ARGS) $(IID_FILE_FLAG) $(BUILDX_ARGS) \
--build-arg VERSION=$(VERSION) --platform=$(TARGET_PLATFORMS) -t "$(IMAGE)" --push .
@echo "Pushed $(IMAGE)"
e2e: $(K3D) $(KUBECTL) $(HELM) build-image ## Run E2E tests.
K3D=$(K3D) KUBECTL=$(KUBECTL) HELM=$(HELM) VERSION=$(VERSION) \
IMAGE=$(IMAGE) \
./hack/e2e
generate: ## Run code generation logic.
$(GO) generate ./...
validate: validate-lint generate validate-dirty ## Run validation checks.
validate-lint: $(GOLANGCI)
$(GOLANGCI) run --timeout=2m
validate-dirty:
ifdef DIRTY
@echo Git is dirty
@git --no-pager status
@git --no-pager diff
@exit 1
endif
upload: clean ## Build and upload artefacts to the GitHub release.
$(MAKE) $(addsuffix -upload, $(TARGET_ARCHS))
%-upload:
TARGET_BIN=build/bin/cis-operator-$(subst :,/,$*) \
GOARCH=$(subst :,/,$*) GOOS=linux \
$(MAKE) build
TAG=$(TAG) \
./hack/upload-gh $(subst :,/,$*)