-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
76 lines (53 loc) · 1.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
# Image URL to use all building/pushing image targets
IMG ?= knode:latest
DEPLOY ?= default
# Directories
TOOLS_DIR := $(PWD)/hack/tools
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
BIN_DIR := bin
# Binaries
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize
all: knode
# Run tests
test: lint
go test ./... -coverprofile cover.out
# Binaries
knode: lint-full
go build -o bin/knode main.go
$(GOLANGCI_LINT): $(TOOLS_DIR)/go.mod # Build golangci-lint from tools folder.
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint
$(KUSTOMIZE): $(TOOLS_DIR)/go.mod # Build kustomize from tools folder.
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/kustomize sigs.k8s.io/kustomize/kustomize/v3
# Deploy in the configured Kubernetes cluster in ~/.kube/config
deploy: $(KUSTOMIZE)
cd config/knode && $(KUSTOMIZE) edit set image knode=${IMG}
$(KUSTOMIZE) build config/$(DEPLOY) | kubectl apply -f -
# Linting
.PHONY: lint lint-full
lint: $(GOLANGCI_LINT) ## Lint codebase
$(GOLANGCI_LINT) run -v
lint-full: $(GOLANGCI_LINT) ## Run slower linters to detect possible issues
$(GOLANGCI_LINT) run -v --fast=false
# Build the docker image
docker-build:
docker build . -t ${IMG}
# Push the docker image
docker-push:
docker push ${IMG}
# Release
RELEASE_DIR := out
$(RELEASE_DIR):
mkdir -p $(RELEASE_DIR)/
.PHONY: release
release: release-containers release-manifests
.PHONY: release-manifests
release-manifests: $(KUSTOMIZE) $(RELEASE_DIR)
cd config/knode && $(KUSTOMIZE) edit set image knode=${IMG}
$(KUSTOMIZE) build config/default > $(RELEASE_DIR)/knode-default.yaml
$(KUSTOMIZE) build config/tmpdir > $(RELEASE_DIR)/knode-tmpdir.yaml
$(KUSTOMIZE) build config/kubelet > $(RELEASE_DIR)/knode-kubelet.yaml
$(KUSTOMIZE) build config/containerd > $(RELEASE_DIR)/knode-containerd.yaml
.PHONY: release-containers
release-containers: $(RELEASE_DIR)
$(MAKE) docker-build docker-push