-
Notifications
You must be signed in to change notification settings - Fork 16
/
Makefile
159 lines (129 loc) · 5.46 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
IMAGE_NAME=kube-compare
PACKAGE_NAME := github.com/openshift/kube-compare
GOLANG_CROSS_VERSION ?= v1.22.7
# Default values for GOOS and GOARCH
GOOS ?= linux
GOARCH ?= amd64
# These tags make sure we can statically link and avoid shared dependencies
GO_BUILD_FLAGS :=-tags 'include_gcs include_oss containers_image_openpgp gssapi'
GO_BUILD_FLAGS_DARWIN :=-tags 'include_gcs include_oss containers_image_openpgp'
GO_BUILD_FLAGS_WINDOWS :=-tags 'include_gcs include_oss containers_image_openpgp'
GO_BUILD_FLAGS_LINUX_CROSS :=-tags 'include_gcs include_oss containers_image_openpgp'
OUTPUT_DIR :=_output
GO_BUILD_BINDIR ?=$(OUTPUT_DIR)/bin
CROSS_BUILD_BINDIR ?=$(OUTPUT_DIR)/bin
# Default locations for `make install`
PREFIX ?= /usr/local
DESTDIR ?= $(PREFIX)/bin
# Autodetect $ENGINE if not set (podman first, then docker)
ifeq ($(origin ENGINE), undefined)
ENGINE = podman
ifeq ($(shell which $(ENGINE) 2>/dev/null), )
ENGINE = docker
endif
endif
# Container-engine-specific options:
ifeq ($(ENGINE), docker)
CONTAINER_MOUNTOPT=
CONTAINER_SOCKETOPT="-v /var/run/docker.sock:/var/run/docker.sock"
else ifeq ($(ENGINE), podman)
CONTAINER_MOUNTOPT=:Z
CONTAINER_SOCKETOPT=
endif
# Build based on OS and Arch. Full list available in https://pkg.go.dev/internal/platform#pkg-variables
.PHONY: build
build:
mkdir -p $(GO_BUILD_BINDIR)
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -mod=vendor $(GO_BUILD_FLAGS) -o $(GO_BUILD_BINDIR)/kubectl-cluster_compare ./cmd/kubectl-cluster_compare.go
# Install the plugin and completion script in /usr/local/bin
.PHONY: install
install:
install kubectl_complete-cluster_compare $(DESTDIR)
install $(GO_BUILD_BINDIR)/kubectl-cluster_compare $(DESTDIR)
.PHONY: test
test:
go test --race ./pkg/*
.PHONY: test-report-creator
test-report-creator:
go test --race ./addon-tools/report-creator/*/
.PHONY: build-report-creator
build-report-creator:
go build ./addon-tools/report-creator/report-creator.go
.PHONY: build-helm-convert
build-helm-convert:
go build ./addon-tools/helm-convert/helm-convert.go
.PHONY: test-helm-convert
test-helm-convert:
go test --race ./addon-tools/helm-convert/*/
.PHONY: golangci-lint
golangci-lint: ## Run golangci-lint against code.
@echo "Running golangci-lint"
hack/golangci-lint.sh
# markdownlint rules, following: https://github.com/openshift/enhancements/blob/master/Makefile
.PHONY: markdownlint-image
markdownlint-image: ## Build local container markdownlint-image
$(ENGINE) image build -f ./hack/markdownlint.Dockerfile --tag $(IMAGE_NAME)-markdownlint:latest ./hack
.PHONY: markdownlint-image-clean
markdownlint-image-clean: ## Remove locally cached markdownlint-image
$(ENGINE) image rm $(IMAGE_NAME)-markdownlint:latest
# markdownlint main
markdownlint: markdownlint-image ## run the markdown linter
$(ENGINE) run \
--rm=true \
--env RUN_LOCAL=true \
--env VALIDATE_MARKDOWN=true \
--env PULL_BASE_SHA=$(PULL_BASE_SHA) \
-v $$(pwd):/workdir$(CONTAINER_MOUNTOPT) \
$(IMAGE_NAME)-markdownlint:latest
.PHONY: image-build
image-build:
$(ENGINE) build . -t $(IMAGE_NAME):latest
.PHONY: release-dry-run
release-dry-run:
@$(ENGINE) run \
--rm \
-e CGO_ENABLED=1 \
$(CONTAINER_SOCKETOPT) \
-v `pwd`:/go/src/$(PACKAGE_NAME)$(CONTAINER_MOUNTOPT) \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --clean --skip=validate --skip=publish
.PHONY: release
release:
@$(ENGINE) run \
--rm \
-e GITHUB_TOKEN=$(GITHUB_TOKEN) \
-e CGO_ENABLED=1 \
-v `pwd`:/go/src/$(PACKAGE_NAME)$(CONTAINER_MOUNTOPT) \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --clean
.PHONY: cross-build-darwin-amd64
cross-build-darwin-amd64:
+@GOOS=darwin GOARCH=amd64 GO_BUILD_FLAGS="$(GO_BUILD_FLAGS_DARWIN)" GO_BUILD_BINDIR=$(CROSS_BUILD_BINDIR)/darwin_amd64 $(MAKE) --no-print-directory build
.PHONY: cross-build-darwin-arm64
cross-build-darwin-arm64:
+@GOOS=darwin GOARCH=arm64 GO_BUILD_FLAGS="$(GO_BUILD_FLAGS_DARWIN)" GO_BUILD_BINDIR=$(CROSS_BUILD_BINDIR)/darwin_arm64 $(MAKE) --no-print-directory build
.PHONY: cross-build-windows-amd64
cross-build-windows-amd64:
+@GOOS=windows GOARCH=amd64 GO_BUILD_FLAGS="$(GO_BUILD_FLAGS_WINDOWS)" GO_BUILD_BINDIR=$(CROSS_BUILD_BINDIR)/windows_amd64 $(MAKE) --no-print-directory build
.PHONY: cross-build-linux-amd64
cross-build-linux-amd64:
+@GOOS=linux GOARCH=amd64 GO_BUILD_FLAGS="$(GO_BUILD_FLAGS_LINUX_CROSS)" GO_BUILD_BINDIR=$(CROSS_BUILD_BINDIR)/linux_amd64 $(MAKE) --no-print-directory build
.PHONY: cross-build-linux-arm64
cross-build-linux-arm64:
+@GOOS=linux GOARCH=arm64 GO_BUILD_FLAGS="$(GO_BUILD_FLAGS_LINUX_CROSS)" GO_BUILD_BINDIR=$(CROSS_BUILD_BINDIR)/linux_arm64 $(MAKE) --no-print-directory build
.PHONY: cross-build-linux-ppc64le
cross-build-linux-ppc64le:
+@GOOS=linux GOARCH=ppc64le GO_BUILD_FLAGS="$(GO_BUILD_FLAGS_LINUX_CROSS)" GO_BUILD_BINDIR=$(CROSS_BUILD_BINDIR)/linux_ppc64le $(MAKE) --no-print-directory build
.PHONY: cross-build-linux-s390x
cross-build-linux-s390x:
+@GOOS=linux GOARCH=s390x GO_BUILD_FLAGS="$(GO_BUILD_FLAGS_LINUX_CROSS)" GO_BUILD_BINDIR=$(CROSS_BUILD_BINDIR)/linux_s390x $(MAKE) --no-print-directory build
.PHONY: cross-build
cross-build: cross-build-darwin-amd64 cross-build-darwin-arm64 cross-build-windows-amd64 cross-build-linux-amd64 cross-build-linux-arm64 cross-build-linux-ppc64le cross-build-linux-s390x
.PHONY: clean-cross-build
clean-cross-build:
$(RM) -r '$(GO_BUILD_BINDIR)'
if [ -d '$(OUTPUT_DIR)' ]; then \
$(RM) -r '$(OUTPUT_DIR)'; \
fi