forked from kubermatic/machine-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
115 lines (90 loc) · 2.95 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
# Copyright 2019 The Machine Controller Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
SHELL = /bin/bash -eu -o pipefail
GO_VERSION ?= 1.20.5
GOOS ?= $(shell go env GOOS)
export CGO_ENABLED := 0
export GIT_TAG ?= $(shell git tag --points-at HEAD)
export GOFLAGS?=-mod=readonly -trimpath
REGISTRY ?= quay.io
REGISTRY_NAMESPACE ?= kubermatic
LDFLAGS ?= -ldflags '-s -w'
IMAGE_TAG = \
$(shell echo $$(git rev-parse HEAD && if [[ -n $$(git status --porcelain) ]]; then echo '-dirty'; fi)|tr -d ' ')
IMAGE_NAME ?= $(REGISTRY)/$(REGISTRY_NAMESPACE)/machine-controller:$(IMAGE_TAG)
OS = amzn2 centos ubuntu rhel flatcar rockylinux
USERDATA_BIN = $(patsubst %, machine-controller-userdata-%, $(OS))
BASE64_ENC = \
$(shell if base64 -w0 <(echo "") &> /dev/null; then echo "base64 -w0"; else echo "base64 -b0"; fi)
.PHONY: all
all: build-machine-controller webhook
.PHONY: build-machine-controller
build-machine-controller: machine-controller $(USERDATA_BIN)
machine-controller-userdata-%: cmd/userdata/% $(shell find cmd/userdata/$* pkg -name '*.go')
GOOS=$(GOOS) go build -v \
$(LDFLAGS) \
-o $@ \
github.com/kubermatic/machine-controller/cmd/userdata/$*
%: cmd/% $(shell find cmd/$* pkg -name '*.go')
GOOS=$(GOOS) go build -v \
$(LDFLAGS) \
-o $@ \
github.com/kubermatic/machine-controller/cmd/$*
.PHONY: clean
clean:
rm -f machine-controller \
webhook \
$(USERDATA_BIN)
.PHONY: lint
lint:
golangci-lint run -v
.PHONY: docker-image
docker-image:
docker build --build-arg GO_VERSION=$(GO_VERSION) -t $(IMAGE_NAME) .
.PHONY: docker-image-publish
docker-image-publish: docker-image
docker push $(IMAGE_NAME)
if [[ -n "$(GIT_TAG)" ]]; then \
$(eval IMAGE_TAG = $(GIT_TAG)) \
docker build -t $(IMAGE_NAME) . && \
docker push $(IMAGE_NAME) && \
$(eval IMAGE_TAG = latest) \
docker build -t $(IMAGE_NAME) . ;\
docker push $(IMAGE_NAME) ;\
fi
.PHONY: test-unit-docker
test-unit-docker:
@docker run --rm \
-v $$PWD:/go/src/github.com/kubermatic/machine-controller \
-v $$PWD/.buildcache:/cache \
-e GOCACHE=/cache \
-w /go/src/github.com/kubermatic/machine-controller \
golang:$(GO_VERSION) \
make test-unit "GOFLAGS=$(GOFLAGS)"
.PHONY: test-unit
test-unit:
go test -v ./...
.PHONY: build-tests
build-tests:
go test -run nope ./...
go test -tags e2e -run nope ./...
.PHONY: check-dependencies
check-dependencies:
go mod verify
.PHONY: download-gocache
download-gocache:
@./hack/ci/download-gocache.sh
.PHONY: shfmt
shfmt:
shfmt -w -sr -i 2 hack