-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
119 lines (89 loc) · 3.79 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
116
117
118
119
# Makefile for Todolist : Go-200
.DEFAULT_GOAL := all
# -----------------------------------------------------------------
#
# ENV VARIABLE
#
# -----------------------------------------------------------------
# check os for path params
ifeq ($(OS),Windows_NT)
PATHSEP=;
FOLDERSEP=\\
EXTENSION=.exe
# case gopath is empty used the default one
ifeq ($(GOPATH),)
GOPATH=$(USERPROFILE)\go
endif
else
PATHSEP=:
FOLDERSEP=/
EXTENSION=""
# case gopath is empty used the default one
ifeq ($(GOPATH),)
GOPATH=$(HOME)/go
endif
endif
GO=$(firstword $(subst $(PATHSEP), ,$(GOPATH)))
# list of pkgs for the project without vendor
PKGS=$(shell go list ./... | grep -v /vendor/)
DOCKER_IP=$(shell if [ -z "$(DOCKER_MACHINE_NAME)" ]; then echo 'localhost'; else docker-machine ip $(DOCKER_MACHINE_NAME); fi)
export GO15VENDOREXPERIMENT=1
# -----------------------------------------------------------------
# Version
# -----------------------------------------------------------------
# version
VERSION=0.0.2
BUILDDATE=$(shell date -u '+%s')
BUILDHASH=$(shell git rev-parse --short HEAD)
VERSION_FLAG=-ldflags "-X main.Version=$(VERSION) -X main.GitHash=$(BUILDHASH) -X main.BuildStmp=$(BUILDDATE)"
# -----------------------------------------------------------------
# Main targets
# -----------------------------------------------------------------
all: clean build ## Clean and build the project
clean: ## Clean the project
@go clean
@rm -Rf .tmp .DS_Store *.log *.out *.mem *.test build/
build: format ## Build all libraries and binaries
@go build -v $(VERSION_FLAG) -o "$(GO)$(FOLDERSEP)bin$(FOLDERSEP)todolist$(EXTENSION)" todolist.go
format: ## Format all packages
@go fmt $(PKGS)
teardownTest: ## Tear down databases for integration tests
@docker-compose -f docker/databases.yml down
setupTest: teardownTest ## Start databases for integration tests
@docker-compose -f docker/databases.yml up -d
test: setupTest ## Start tests with a databases docker image
@export DB_HOST=$(DOCKER_IP); sleep 2; go test -v $(PKGS); make teardownTest
bench: setupTest ## Start benchmark
@go test -v -run nothing -bench=. -memprofile=prof.mem github.com/Sfeir/golang-200/web ; make teardownTest
benchTool: bench ## Start benchmark tool
@echo "### TIP : type 'top 5' and 'list path_of_the_first_item'"
@go tool pprof --alloc_space web.test prof.mem
lint: ## Lint all packages
@golint dao/...
@golint model/...
@golint web/...
@golint utils/...
@golint ./.
@go vet $(PKGS)
# -----------------------------------------------------------------
# Docker targets
# -----------------------------------------------------------------
dockerBuild: ## Build a docker image of the program
docker build -f docker/Dockerfile -t sfeir/todolist:latest .
dockerBuildMulti: ## Build a docker multistep image of the program
docker build -f docker/Dockerfile.multi -t sfeir/todolist:latest .
dockerClean: ## Remove the docker image of the program
docker rmi -f sfeir/todolist:latest
dockerUp: ## Start the program instances with their databases
docker-compose -f docker/docker-compose.yml up -d
dockerDown: ## Stop the program instances, their databases and remove the containers
docker-compose -f docker/docker-compose.yml down
dockerBuildUp: dockerDown dockerBuild dockerUp ## Stop, build and launch the docker images of the program
dockerBuildUpMulti: dockerDown dockerBuildMulti dockerUp ## Stop, build multi step and launch the docker images of the program
dockerWatch: ## Watch the status of the docker container
@watch -n1 'docker ps | grep todolist'
dockerLogs: ## Print the logs of the container
docker-compose logs -f
help: ## Print this message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
.PHONY: all test clean teardownTest setupTest