forked from gardener/inventory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
133 lines (108 loc) · 3.71 KB
/
Makefile
File metadata and controls
133 lines (108 loc) · 3.71 KB
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
.DEFAULT_GOAL := build
REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
IMAGE ?= europe-docker.pkg.dev/gardener-project/releases/gardener/inventory
LOCAL_BIN ?= $(REPO_ROOT)/bin
TOOLS_BIN ?= $(REPO_ROOT)/bin/tools
BINARY ?= $(LOCAL_BIN)/inventory
SRC_DIRS := $(shell go list -f '{{.Dir}}' ./...)
VERSION := $(shell cat VERSION)
EFFECTIVE_VERSION ?= $(VERSION)-$(shell git rev-parse --short HEAD)
ifneq ($(strip $(shell git status --porcelain 2>/dev/null)),)
EFFECTIVE_VERSION := $(EFFECTIVE_VERSION)-dirty
endif
IMAGE_TAG ?= $(EFFECTIVE_VERSION)
MINIKUBE := $(TOOLS_BIN)/minikube
MINIKUBE_VERSION ?= v1.33.1
# Minikube settings
MINIKUBE_PROFILE ?= inventory
MINIKUBE_DRIVER ?= docker
KUSTOMIZE_OVERLAY ?= local
GOOS = $(shell go env GOOS)
GOARCH = $(shell go env GOARCH)
export PATH := $(abspath $(TOOLS_BIN)):$(PATH)
# Fetch the version of a go module from go.mod
tool_version_file = $(TOOLS_BIN)/.version_$(subst $(TOOLS_BIN)/,,$(1))_$(2)
# download-tool will download a binary package from the given URL.
#
# $1 - name of the tool
# $2 - HTTP URL to download the tool from
define download-tool
@set -e; \
tool=$(1) ;\
echo "Downloading $${tool}" ;\
curl -o $(TOOLS_BIN)/$(1) -sSfL $(2) ;\
chmod +x $(TOOLS_BIN)/$(1)
endef
$(LOCAL_BIN):
mkdir -p $(LOCAL_BIN)
$(TOOLS_BIN):
mkdir -p $(TOOLS_BIN)
$(TOOLS_BIN)/.version_%: | $(TOOLS_BIN)
@version_file=$@; rm -f $${version_file%_*}*
@touch $@
#########################################
# Tools #
#########################################
$(MINIKUBE): $(call tool_version_file,$(MINIKUBE),$(MINIKUBE_VERSION))
$(call download-tool,minikube,https://github.com/kubernetes/minikube/releases/download/$(MINIKUBE_VERSION)/minikube-$(GOOS)-$(GOARCH))
.PHONY: clean-tools-bin
clean-tools-bin:
@rm -f $(TOOLS_BIN)/.version_*
@rm -rf $(TOOLS_BIN)/*
#########################################
# Makefile targets #
#########################################
.PHONY: goimports-reviser
goimports-reviser:
go tool -modfile tools/go.mod \
goimports-reviser \
-set-exit-status \
-rm-unused \
-excludes './deployment,./extra' \
./...
.PHONY: lint
lint:
go tool -modfile tools/go.mod \
golangci-lint run --config=$(REPO_ROOT)/.golangci.yaml ./...
$(BINARY): $(SRC_DIRS) | $(LOCAL_BIN)
go build \
-o $(BINARY) \
-ldflags="-X 'github.com/gardener/inventory/pkg/version.Version=${EFFECTIVE_VERSION}'" \
./cmd/inventory
.PHONY: build
build: $(BINARY)
.PHONY: get
get:
go mod download
.PHONY: test
test:
go test -v -race ./...
.PHONY: test-cover
test-cover:
go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
.PHONY: docker-build
docker-build:
docker build -t $(IMAGE):$(IMAGE_TAG) -t $(IMAGE):latest .
.PHONY: docker-compose-up
docker-compose-up:
docker compose up --build --remove-orphans
.PHONY: kustomize-build
kustomize-build:
go tool -modfile tools/go.mod kustomize build deployment/kustomize/$(KUSTOMIZE_OVERLAY)
.PHONY: minikube-up
minikube-up: $(MINIKUBE)
$(MINIKUBE) -p $(MINIKUBE_PROFILE) start --driver $(MINIKUBE_DRIVER)
$(MAKE) minikube-load-image
@$(MAKE) -s kustomize-build | $(MINIKUBE) -p $(MINIKUBE_PROFILE) kubectl -- apply -f -
.PHONY: minikube-down
minikube-down: $(MINIKUBE)
$(MINIKUBE) delete -p $(MINIKUBE_PROFILE)
.PHONY: minikube-load-image
minikube-load-image: $(MINIKUBE)
$(MAKE) docker-build
docker image save -o image.tar $(IMAGE):latest
$(MINIKUBE) -p $(MINIKUBE_PROFILE) image load --overwrite=true image.tar
rm -f image.tar
.PHONY: update-tools
update-tools:
go get -u -modfile tools/go.mod tool