-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
104 lines (85 loc) · 3.15 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
EXECUTABLE=kubelink
VERSION=$(shell cat VERSION)
RELEASE := true
NAME := kubelink
REPOSITORY := github.com/mandelsoft/kubelink
#REGISTRY := eu.gcr.io/gardener-project
REGISTRY := ghcr.io/
IMAGEORG := mandelsoft
IMAGE_PREFIX := $(REGISTRY)$(IMAGEORG)
REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
HACK_DIR := $(REPO_ROOT)/hack
VERSION := $(shell cat "$(REPO_ROOT)/VERSION")
GITVERVS ?= $(shell git describe --exact-match 2> /dev/null || \
git describe --match=$(git rev-parse --short=8 HEAD) --always --dirty --abbrev=8)
COMMIT := $(shell git describe --match=$(git rev-parse HEAD) --always --dirty --abbrev=8)
ifeq ($(RELEASE),true)
IMAGE_TAG := $(VERSION)
else
IMAGE_TAG := $(VERSION)-$(COMMIT)
endif
LD_FLAGS := "-w -X main.Version=$(IMAGE_TAG)"
VERSION_VAR := github.com/gardener/controller-manager-library/pkg/controllermanager.Version
.PHONY: all
ifeq ($(RELEASE),true)
all: generate release
else
all: generate dev
endif
.PHONY: revendor
revendor:
@GO111MODULE=on go mod vendor
@GO111MODULE=on go mod tidy
.PHONY: check
check:
@.ci/check
.PHONY: dev
dev:
@echo target: release
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go install \
-mod=vendor \
-ldflags "-X $(VERSION_VAR)=$(VERSION)-$(COMMIT)" \
./cmd/$(NAME)
.PHONY: build-local
build-local:
CGO_ENABLED=0 GO111MODULE=on go build -o $(EXECUTABLE) \
-mod=vendor \
-ldflags "-X $(VERSION_VAR)=$(VERSION)-$(COMMIT)" \
./cmd/$(NAME)
.PHONY: release-all
release-all: generate release
.PHONY: release
release:
@echo target: release
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go install \
-a \
-mod=vendor \
-ldflags "-w -X $(VERSION_VAR)=$(VERSION)" \
./cmd/$(NAME)
.PHONY: test
test:
GO111MODULE=on go test -mod=vendor ./pkg/...
.PHONY: generate
generate:
@go generate ./pkg/...
### Docker commands
.PHONY: docker-login
docker-login:
@gcloud auth activate-service-account --key-file .kube-secrets/gcr/gcr-readwrite.json
.PHONY: images-dev
images-dev:
@docker build -t $(IMAGE_PREFIX)/$(NAME):$(VERSION)-$(COMMIT) -t $(IMAGE_PREFIX)/$(NAME):latest -f Dockerfile -m 6g --build-arg TARGETS=dev --target $(NAME) .
@docker push $(IMAGE_PREFIX)/$(NAME):latest
.PHONY: push-dev
push-dev:
@docker push $(IMAGE_PREFIX)/$(NAME):latest
.PHONY: images-release
images-release:
@docker build -t $(IMAGE_PREFIX)/$(NAME):$(VERSION) -t $(IMAGE_PREFIX)/$(NAME):latest -f Dockerfile -m 6g --build-arg TARGETS=release --target $(NAME) .
@docker push $(IMAGE_PREFIX)/$(NAME):latest
@docker push $(IMAGE_PREFIX)/$(NAME):$(VERSION)
.PHONY: images-release-all
images-release-all:
@docker build -t $(IMAGE_PREFIX)/$(NAME):$(VERSION) -t $(IMAGE_PREFIX)/$(NAME):latest -f Dockerfile -m 6g --build-arg TARGETS=release-all --target $(NAME) .
@docker push $(IMAGE_PREFIX)/$(NAME):latest
@docker push $(IMAGE_PREFIX)/$(NAME):$(VERSION)