forked from turbonomic/prometurbo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
67 lines (51 loc) · 2.01 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
OUTPUT_DIR=build
SOURCE_DIRS = cmd pkg
PACKAGES := go list ./... | grep -v /vendor | grep -v /out
SHELL='/bin/bash'
REMOTE=github.com
USER=turbonomic
PROJECT=prometurbo
bin=prometurbo
DEFAULT_VERSION=latest
.DEFAULT_GOAL := build
GIT_COMMIT=$(shell git rev-parse --short HEAD)
BUILD_TIME=$(shell date -R)
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)"'
LINUX_ARCH=amd64 arm64 ppc64le s390x
$(LINUX_ARCH): clean
env GOOS=linux GOARCH=$@ go build -ldflags $(LDFLAGS) -o $(OUTPUT_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 ${OUTPUT_DIR}/${bin}_debug ./cmd
build: clean
go build -ldflags $(LDFLAGS) -o ${bin} ./cmd
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 ${OUTPUT_DIR}/linux ${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