-
Notifications
You must be signed in to change notification settings - Fork 25
/
Makefile
68 lines (52 loc) · 2.71 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
.PHONY: clean lint build.local build.linux build.osx build.docker build.push
BINARY ?= clm
VERSION ?= $(shell git describe --tags --always --dirty)
IMAGE ?= registry-write.opensource.zalan.do/teapot/cluster-lifecycle-manager
TAG ?= $(VERSION)
SOURCES = $(shell find . -name '*.go')
GO ?= go
SPEC = docs/cluster-registry.yaml
CR_CLIENT = pkg/cluster-registry
DOCKERFILE ?= Dockerfile
GOPKGS = $(shell $(GO) list ./...)
GO_SWAGGER = ./build/swagger
BUILD_FLAGS ?= -v
LDFLAGS ?= -X main.version=$(VERSION) -w -s
default: build.local
clean:
rm -rf build
rm -rf $(CR_CLIENT)
rm -rf $(AWS_INSTANCE_DATA)
test: $(CR_CLIENT) $(AWS_INSTANCE_DATA)
$(GO) test -v -race -coverprofile=profile.cov $(GOPKGS)
$(GO) vet -v $(GOPKGS)
lint: $(CR_CLIENT) $(SOURCES) $(AWS_INSTANCE_DATA)
$(GO) mod download
golangci-lint -v run ./...
fmt:
$(GO) fmt $(GOPKGS)
$(AWS_DATA_SRC):
mkdir -p $(dir $@)
curl -L -s --fail https://www.ec2instances.info/instances.json | jq '[.[] | {instance_type, vCPU, memory, storage: (if .storage == null then null else .storage | {devices, size, nvme_ssd} end)}] | sort_by(.instance_type)' > "$@"
$(CR_CLIENT): $(SPEC)
mkdir -p $@
go run github.com/go-swagger/go-swagger/cmd/swagger generate client --name cluster-registry --principal oauth.User --spec docs/cluster-registry.yaml --target ./$(CR_CLIENT)
build.local: build/$(BINARY)
build.linux: build/linux/$(BINARY)
build.osx: build/osx/$(BINARY)
build.linux.amd64: build/linux/amd64/$(BINARY)
build.linux.arm64: build/linux/arm64/$(BINARY)
build/$(BINARY): $(CR_CLIENT) $(SOURCES) $(AWS_INSTANCE_DATA)
CGO_ENABLED=0 $(GO) build -o build/$(BINARY) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" ./cmd/$(BINARY)
build/linux/$(BINARY): $(CR_CLIENT) $(SOURCES) $(AWS_INSTANCE_DATA)
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GO) build $(BUILD_FLAGS) -o build/linux/$(BINARY) -ldflags "$(LDFLAGS)" ./cmd/$(BINARY)
build/linux/amd64/%: go.mod $(SOURCES)
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GO) build $(BUILD_FLAGS) -o build/linux/amd64/$(notdir $@) -ldflags "$(LDFLAGS)" ./cmd/$(notdir $@)
build/linux/arm64/%: go.mod $(SOURCES)
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 $(GO) build $(BUILD_FLAGS) -o build/linux/arm64/$(notdir $@) -ldflags "$(LDFLAGS)" ./cmd/$(notdir $@)
build/osx/$(BINARY): $(CR_CLIENT) $(SOURCES) $(AWS_INSTANCE_DATA)
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 $(GO) build $(BUILD_FLAGS) -o build/osx/$(BINARY) -ldflags "$(LDFLAGS)" ./cmd/$(BINARY)
build.docker: build.linux
docker build --rm -t "$(IMAGE):$(TAG)" -f $(DOCKERFILE) --build-arg TARGETARCH= .
build.push: build.docker
docker push "$(IMAGE):$(TAG)"