-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathMakefile
162 lines (133 loc) · 5.38 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
160
161
162
BUILD_DIR := build
SOURCE_DIRS = cmd pkg
PACKAGES := go list ./... | grep -v /vendor | grep -v /out
SHELL='/bin/bash'
REMOTE=github.ibm.com
USER=turbonomic
PROJECT=prometurbo
PROMETURBO_VERSION ?= 8.15.1-SNAPSHOT
bin=prometurbo
DEFAULT_VERSION=latest
REMOTE_URL=$(shell git config --get remote.origin.url)
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
REVISION=$(shell git show -s --format=%cd --date=format:'%Y%m%d%H%M%S000')
YAMLLINT_VERSION := 1.32
PROMETURBO_OPERATOR_CRD_OPERATOR_HUB := deploy/prometurbo-operator/deploy/crds/charts.helm.k8s.io_prometurbos_crd.yaml
.DEFAULT_GOAL := build
GIT_COMMIT=$(shell git rev-parse --short HEAD)
BUILD_TIME=$(shell date -R)
BUILD_TIMESTAMP=$(shell date +'%Y%m%d%H%M%S000')
PROJECT_PATH=$(REMOTE)/$(USER)/$(PROJECT)
VERSION=$(or $(PROMETURBO_VERSION), $(DEFAULT_VERSION))
LDFLAGS='\
-X "$(PROJECT_PATH)/version.GitCommit=$(GIT_COMMIT)" \
-X "$(PROJECT_PATH)/version.BuildTime=$(BUILD_TIME)" \
-X "$(PROJECT_PATH)/version.Version=$(VERSION)"'
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
LINUX_ARCH=amd64 arm64 ppc64le s390x
$(LINUX_ARCH): clean
env GOOS=linux GOARCH=$@ go build -ldflags $(LDFLAGS) -o $(BUILD_DIR)/linux/$@/$(bin) ./cmd
product: $(LINUX_ARCH)
debug-product: clean
env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags $(LDFLAGS) -gcflags "-N -l" -o ${BUILD_DIR}/${bin}_debug ./cmd
build: clean
go build -ldflags $(LDFLAGS) -o ${bin} ./cmd
buildInfo:
$(shell test -f git.properties && rm -rf git.properties)
@echo 'turbo-version.remote.origin.url=$(REMOTE_URL)' >> git.properties
@echo 'turbo-version.commit.id=$(GIT_COMMIT)' >> git.properties
@echo 'turbo-version.branch=$(BRANCH)' >> git.properties
@echo 'turbo-version.branch.version=$(VERSION)' >> git.properties
@echo 'turbo-version.commit.time=$(REVISION)' >> git.properties
@echo 'turbo-version.build.time=$(BUILD_TIMESTAMP)' >> git.properties
debug: clean
go build -ldflags $(LDFLAGS) -gcflags "-N -l" -o ${bin}.debug ./cmd
docker: product
cd build; DOCKER_BUILDKIT=1 docker build -t turbonomic/prometurbo --build-arg $(GIT_COMMIT) --load .
test: clean
@go test -v -race ./pkg/...
.PHONY: fmtcheck
fmtcheck:
@gofmt -s -l $(SOURCE_DIRS) | grep ".*\.go"; if [ "$$?" = "0" ]; then exit 1; fi
.PHONY: vet
vet:
@go vet $(shell $(PACKAGES))
clean:
@rm -rf ${BUILD_DIR}/linux ${bin}
.PHONY: python
PYTHON = $(LOCALBIN)/python3
python: $(PYTHON) ## Install Python locally if necessary. Darwin OS is specific to mac users if running locally
$(PYTHON):
@if ! command -v python3 >/dev/null 2>&1; then \
mkdir -p $(LOCALBIN); \
if [ `uname -s` = "Darwin" ]; then \
brew install python@3; \
else \
sudo apt update && sudo apt install python3; \
fi \
fi
mkdir -p $(dir $(PYTHON))
ln -sf `command -v python3` $(PYTHON)
.PHONY: yamllint
yamllint: python
$(PYTHON) -m pip install yamllint==$(YAMLLINT_VERSION)
yaml-lint-check: yamllint
$(PYTHON) -m yamllint -d '{extends: default, rules: {line-length: {max: 180, level: warning}, indentation: {indent-sequences: whatever}}}' $(PROMETURBO_OPERATOR_CRD_OPERATOR_HUB)
rm -rf ./bin
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
REPO_NAME ?= icr.io/cpopen/turbonomic
.PHONY: multi-archs
multi-archs:
env GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 go build -ldflags $(LDFLAGS) -o ${bin} ./cmd
.PHONY: docker-buildx
docker-buildx:
docker buildx create --name prometurbo-builder
- docker buildx use prometurbo-builder
- docker buildx build --platform=$(PLATFORMS) --label "git-commit=$(GIT_COMMIT)" --label "git-version=$(VERSION)" --provenance=false --push --tag $(REPO_NAME)/$(PROJECT):$(VERSION) -f build/Dockerfile.multi-archs --build-arg VERSION=$(VERSION) .
docker buildx rm prometurbo-builder
root_dir := $(shell pwd)
OUTPUT_DIR := $(root_dir)/_output
HELM ?= $(LOCALBIN)/helm
HELM_REPO := turbonomic-container-platform
HELM_LINTER := docker run --rm --workdir=/data --volume $(root_dir):/data quay.io/helmpack/chart-testing:v3.11.0 ct
.PHONY: helm
helm: $(LOCALBIN) ## Download helm locally if necessary.
@if ! command -v $(HELM) >/dev/null 2>&1 ; then \
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -Lo "helm-v3.16.1-$${OS}-$${ARCH}.tar.gz" "https://get.helm.sh/helm-v3.16.1-$${OS}-$${ARCH}.tar.gz" && \
tar -zxvf "helm-v3.16.1-$${OS}-$${ARCH}.tar.gz" && \
mv $${OS}-$${ARCH}/helm $(LOCALBIN)/ && \
rm -f "helm-v3.16.1-$${OS}-$${ARCH}.tar.gz" && \
rm -rf "$${OS}-$${ARCH}/"; \
fi
$(HELM) version
.PHONY:helm-lint
helm-lint:
$(HELM_LINTER) lint --charts deploy/prometurbo --validate-maintainers=false --target-branch staging
.PHONY:public-repo-update
public-repo-update: helm
@if [[ "$(VERSION)" =~ ^[0-9]+\.[0-9]+\.[0-9]+$$ ]] ; then \
./scripts/travis/public_repo_update.sh ${VERSION}; \
fi
check-upstream-dependencies:
./scripts/travis/check_upstream_dependencies.sh
# Check, Build, and Test:
# - Runs code checks including formatting, linting, and vetting.
# - Builds the project to ensure compilation success.
# - Runs tests to verify code functionality and correctness.
.PHONY: check-build-test
check-build-test:
@echo "Checking, building, and testing..."
make fmtcheck
make vet
make yaml-lint-check
make helm-lint
make product
make test
@echo "Check, build, and test completed."
# Pull Request Build Target
.PHONY: pull-request-build
pull-request-build: check-upstream-dependencies check-build-test