forked from open-cluster-management-io/clusteradm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
136 lines (108 loc) · 5.2 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
# Copyright Contributors to the Open Cluster Management project
BEFORE_SCRIPT := $(shell build/before-make.sh)
SCRIPTS_PATH ?= build
# Install software dependencies
INSTALL_DEPENDENCIES ?= ${SCRIPTS_PATH}/install-dependencies.sh
GOPATH := ${shell go env GOPATH}
GOOS := ${shell go env GOOS}
GOARCH := ${shell go env GOARCH}
SOURCE_GIT_LATEST_TAG ?= $(shell git describe --tags `git rev-list --tags --max-count=1`)
SOURCE_GIT_TAG ?=$(shell git describe --long --tags --abbrev=7 --match 'v[0-9]*' || echo 'v0.0.0-unknown-$(SOURCE_GIT_COMMIT)')
SOURCE_GIT_COMMIT ?=$(shell git rev-parse --short "HEAD^{commit}" 2>/dev/null)
SOURCE_GIT_TREE_STATE ?=$(shell ( ( [ ! -d ".git/" ] || git diff --quiet ) && echo 'clean' ) || echo 'dirty')
GO_LD_EXTRAFLAGS ?=
define version-ldflags
-X open-cluster-management.io/clusteradm/pkg/version.versionFromGit="$(SOURCE_GIT_TAG)" \
-X open-cluster-management.io/clusteradm/pkg/version.commitFromGit="$(SOURCE_GIT_COMMIT)" \
-X open-cluster-management.io/clusteradm/pkg/version.gitTreeState="$(SOURCE_GIT_TREE_STATE)" \
-X open-cluster-management.io/clusteradm/pkg/version.buildDate="$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')"
endef
GO_LD_FLAGS ?=-ldflags "$(call version-ldflags,$(GO_PACKAGE)/pkg/version) $(GO_LD_EXTRAFLAGS)"
export PROJECT_DIR = $(shell 'pwd')
export PROJECT_NAME = $(shell basename ${PROJECT_DIR})
export GOPACKAGES = $(shell go list ./... | grep -v /vendor | grep -v /build | grep -v /test )
.PHONY: clean
clean: clean-test clean-e2e
.PHONY: verify
verify:
go install github.com/golangci/golangci-lint/cmd/[email protected]
go vet ./...
golangci-lint run --timeout=3m --modules-download-mode vendor -E gofmt ./...
.PHONY: deps
deps:
@$(INSTALL_DEPENDENCIES)
.PHONY: build
build:
rm -f bin/clusteradm
CGO_ENABLED=0 go build -ldflags="-s -w" -o bin/clusteradm cmd/clusteradm/clusteradm.go
.PHONY:
build-bin:
@rm -rf bin
@mkdir -p bin
GOOS=darwin GOARCH=amd64 go build $(GO_LD_FLAGS) -gcflags=-trimpath=x/y -o bin/clusteradm ./cmd/clusteradm/clusteradm.go && tar -czf bin/clusteradm_darwin_amd64.tar.gz LICENSE -C bin/ clusteradm
GOOS=darwin GOARCH=arm64 go build $(GO_LD_FLAGS) -gcflags=-trimpath=x/y -o bin/clusteradm ./cmd/clusteradm/clusteradm.go && tar -czf bin/clusteradm_darwin_arm64.tar.gz LICENSE -C bin/ clusteradm
# add CGO_ENABLED flag for linux/amd64 to support different version of glibc
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build $(GO_LD_FLAGS) -gcflags=-trimpath=x/y -o bin/clusteradm ./cmd/clusteradm/clusteradm.go && tar -czf bin/clusteradm_linux_amd64.tar.gz LICENSE -C bin/ clusteradm
GOOS=linux GOARCH=arm64 go build $(GO_LD_FLAGS) -gcflags=-trimpath=x/y -o bin/clusteradm ./cmd/clusteradm/clusteradm.go && tar -czf bin/clusteradm_linux_arm64.tar.gz LICENSE -C bin/ clusteradm
GOOS=linux GOARCH=ppc64le go build $(GO_LD_FLAGS) -gcflags=-trimpath=x/y -o bin/clusteradm ./cmd/clusteradm/clusteradm.go && tar -czf bin/clusteradm_linux_ppc64le.tar.gz LICENSE -C bin/ clusteradm
GOOS=linux GOARCH=s390x go build $(GO_LD_FLAGS) -gcflags=-trimpath=x/y -o bin/clusteradm ./cmd/clusteradm/clusteradm.go && tar -czf bin/clusteradm_linux_s390x.tar.gz LICENSE -C bin/ clusteradm
GOOS=windows GOARCH=amd64 go build $(GO_LD_FLAGS) -gcflags=-trimpath=x/y -o bin/clusteradm.exe ./cmd/clusteradm/clusteradm.go && zip -q bin/clusteradm_windows_amd64.zip LICENSE -j bin/clusteradm.exe
.PHONY: build-krew
build-krew: krew-tools
docker run -v ${PROJECT_DIR}/.krew.yaml:/tmp/template-file.yaml rajatjindal/krew-release-bot:v0.0.40 \
krew-release-bot template --tag ${SOURCE_GIT_LATEST_TAG} --template-file /tmp/template-file.yaml > krew-manifest.yaml;
KREW=/tmp/krew-${GOOS}\_$(GOARCH) && \
KREW_ROOT=`mktemp -d` KREW_OS=darwin KREW_ARCH=amd64 $$KREW install --manifest=krew-manifest.yaml && \
KREW_ROOT=`mktemp -d` KREW_OS=linux KREW_ARCH=amd64 $$KREW install --manifest=krew-manifest.yaml && \
KREW_ROOT=`mktemp -d` KREW_OS=linux KREW_ARCH=arm64 $$KREW install --manifest=krew-manifest.yaml && \
KREW_ROOT=`mktemp -d` KREW_OS=windows KREW_ARCH=amd64 $$KREW install --manifest=krew-manifest.yaml;
.PHONY: krew-tools
krew-tools:
ifeq (, $(shell which /tmp/krew-$(GOOS)\_$(GOARCH)))
@( \
set -x; cd /tmp && \
KREW=krew-$(GOOS)\_$(GOARCH); \
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/$$KREW.tar.gz" && \
tar zxvf $$KREW.tar.gz \
)
endif
.PHONY: install
install: build
.PHONY: plugin
plugin: build
cp ${GOPATH}/bin/clusteradm ${GOPATH}/bin/oc-clusteradm
cp ${GOPATH}/bin/clusteradm ${GOPATH}/bin/kubectl-clusteradm
.PHONY: check
## Runs a set of required checks
check: check-copyright
.PHONY: check-copyright
check-copyright:
@build/check-copyright.sh
.PHONY: test
test: deps
@build/run-unit-tests.sh
.PHONY: clean-test
clean-test:
-rm -r ./test/unit/coverage
-rm -r ./test/unit/tmp
-rm -r ./test/out
include ./test/integration-test.mk
include ./test/e2e/e2e-test.mk
# Update vendor
.PHONY: vendor
vendor:
go mod tidy
go mod vendor
# Copy CRDs
.PHONY: copy-crd
copy-crd: vendor
bash -x build/copy-crds.sh
IMAGE_REGISTRY?=ghcr.io/kluster-manager
IMAGE_TAG?=latest
export IMAGE_NAME?=$(IMAGE_REGISTRY)/clusteradm:$(IMAGE_TAG)
image:
docker build -f Dockerfile -t $(IMAGE_NAME) .
.PHONY: image
push:
docker push $(IMAGE_NAME)
.PHONY: push