-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
100 lines (80 loc) · 3.22 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
# Project variables
PROJECT_NAME := xelon-cloud-controller-manager
IMAGE_NAME ?= xelonag/xelon-cloud-controller-manager
# Build variables
.DEFAULT_GOAL = test
BUILD_DIR := build
TOOLS_DIR := $(shell pwd)/tools
TOOLS_BIN_DIR := ${TOOLS_DIR}/bin
VERSION ?= $(shell git describe --always)
GIT_COMMIT ?= $(shell git rev-parse HEAD)
ifeq ($(strip $(shell git status --porcelain 2>/dev/null)),)
GIT_TREE_STATE=clean
else
GIT_TREE_STATE=dirty
endif
SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct)
LDFLAGS ?= -X github.com/Xelon-AG/xelon-cloud-controller-manager/internal/xelon.gitCommit=${GIT_COMMIT}
LDFLAGS := $(LDFLAGS) -X github.com/Xelon-AG/xelon-cloud-controller-manager/internal/xelon.gitTreeState=${GIT_TREE_STATE}
LDFLAGS := $(LDFLAGS) -X github.com/Xelon-AG/xelon-cloud-controller-manager/internal/xelon.sourceDateEpoch=${SOURCE_DATE_EPOCH}
LDFLAGS := $(LDFLAGS) -X github.com/Xelon-AG/xelon-cloud-controller-manager/internal/xelon.version=${VERSION}
## tools: Install required tooling.
.PHONY: tools
tools:
@echo "==> Installing required tooling..."
@cd tools && GOBIN=${TOOLS_BIN_DIR} go install github.com/golangci/golangci-lint/cmd/golangci-lint
## clean: Delete the build directory.
.PHONY: clean
clean:
@echo "==> Removing '$(BUILD_DIR)' directory..."
@rm -rf $(BUILD_DIR)
## lint: Lint code with golangci-lint.
.PHONY: lint
lint:
@echo "==> Linting code with 'golangci-lint'..."
@${TOOLS_BIN_DIR}/golangci-lint run
## test: Run all unit tests.
.PHONY: test
test:
@echo "==> Running unit tests..."
@mkdir -p $(BUILD_DIR)
@go test -count=1 -v -cover -coverprofile=$(BUILD_DIR)/coverage.out -parallel=4 ./...
## build: Build binary for linux/amd64 system.
.PHONE: build
build:
@echo "==> Building binary..."
@echo " running go build for GOOS=linux GOARCH=amd64"
@GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -o $(BUILD_DIR)/$(PROJECT_NAME) cmd/xelon-cloud-controller-manager/main.go
## build-docker: Build docker image with included binary.
.PHONE: build-docker
build-docker:
@echo "==> Building docker image $(IMAGE_NAME)..."
@docker build \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg GIT_TREE_STATE=$(GIT_TREE_STATE) \
--build-arg SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH) \
--build-arg VERSION=$(VERSION) \
--tag $(IMAGE_NAME) --file Dockerfile .
## release-docker-dev: Release development docker image.
.PHONE: release-docker-dev
release-docker-dev: build-docker
@echo "==> Tagging docker image $(IMAGE_NAME):dev..."
@docker tag $(IMAGE_NAME) $(IMAGE_NAME):dev
@echo "==> Releasing development docker image $(IMAGE_NAME):dev..."
@docker push $(IMAGE_NAME):dev
## release-docker: Release docker image.
.PHONE: release-docker
release-docker: build-docker
@echo "==> Tagging docker image $(IMAGE_NAME):latest..."
@docker tag $(IMAGE_NAME) $(IMAGE_NAME):latest
@echo "==> Releasing docker image $(IMAGE_NAME):latest..."
@docker push $(IMAGE_NAME):latest
@echo "==> Tagging docker image $(IMAGE_NAME):$(VERSION)..."
@docker tag $(IMAGE_NAME) $(IMAGE_NAME):$(VERSION)
@echo "==> Releasing docker image $(IMAGE_NAME):$(VERSION)..."
@docker push $(IMAGE_NAME):$(VERSION)
help: Makefile
@echo "Usage: make <command>"
@echo ""
@echo "Commands:"
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'