-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
68 lines (56 loc) · 2.11 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
# Use for ldflags to compile binary with more information
#DATE := $(shell date "+%Y-%m-%d@%H:%M:%S")
#GITBRANCH := $(shell git rev-parse --abbrev-ref HEAD)
#GITCOMMIT := $(shell git rev-parse HEAD)
VERSION := "v0.1.0"
PROJECTNAME := cloudlycke-cloud-controller-manager
# Go related vars
GOVER = 1.13
GOCMD = go
GOBASE := $(shell pwd)
GOBIN := $(GOBASE)/bin
LDFLAGS_LINUX := -ldflags "-s -w -X=cloudlycke.io/cloudlycke/pkg/version.Version=$(VERSION)"
# Environment info
GOARCH=amd64
OS := linux
# Make make silent
MAKEFLAGS += --silent
# Docker vars
DOCKER_HUB_REPOSITORY := mikejoh
DEFAULT_VERSION_TAG := latest
# Commands
## test: Run all tests recursively, be verbose and output test coverage (in percent)
.PHONY: test
test:
@$(GOCMD) test ./... -v -cover
## clean: Clean the working directory.
.PHONY: clean
clean:
@echo " > Cleaning the working directory..."
@rm -rf ./bin/
## build-linux: Build Linux amd64 binary locally.
.PHONY: build-linux
build-linux:
@echo " $(LDFLAGS_LINUX) "
@echo " > Building Linux binary..."
@CGO_ENABLED=0 GOOS=linux GOARCH=$(GOARCH) $(GOCMD) build $(LDFLAGS_LINUX) -o ./bin/$(PROJECTNAME) ./cmd/$(wildcard *.go)
## build-linux-docker: Build Linux amd64 binary locally but through a Docker container.
.PHONY: build-linux-docker
build-linux-docker:
@echo " $(LDFLAGS_LINUX) "
@echo " > Build Linux binary in a Docker container..."
@docker run --rm -it -v $(GOBASE):/$(PROJECTNAME) -w="/$(PROJECTNAME)" golang:$(GOVER)-alpine sh -c "CGO_ENABLED=0 GOOS=linux GOARCH=$(GOARCH) $(GOCMD) build $(LDFLAGS_LINUX) -o $(PROJECTNAME) $(wildcard *.go)"
## Build Docker image
.PHONY: docker-build
docker-build:
@echo " > Building $(PROJECTNAME) Docker image"
@docker build . -t $(DOCKER_HUB_REPOSITORY)/$(PROJECTNAME):$(DEFAULT_VERSION_TAG)
## Push Docker image to Docker registry
.PHONY: docker-push
docker-push:
@echo " > Pushing $(PROJECTNAME) Docker image"
@docker push $(DOCKER_HUB_REPOSITORY)/$(PROJECTNAME):$(DEFAULT_VERSION_TAG)
## Build and compile binary, build Docker image, push to Docker registry.
.PHONY: release
release: build-linux docker-build docker-push
@echo " Releasing $(PROJECTNAME)"