-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
124 lines (91 loc) · 3.45 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
120
121
122
123
124
CC=go
RM=rm
MV=mv
SOURCEDIR=./cli/
SOURCES := $(shell find . -name '*.go')
GOOS=darwin
GOARCH=amd64
#VERSION:=$(shell grep -m1 "M4ClientVersion string" *.go | sed 's/[", ]//g' | cut -d= -f2)
APP=m4client
BUILD_TIME=`date +%FT%T%z`
PACKAGES :=
M4_CLIENT=$(shell git rev-parse --short HEAD)
LIBS=
LDFLAGS=-ldflags #"-X main.M4ClientGitHash=$(M4_CLIENT)"
.DEFAULT_GOAL:=test
help:
@echo ""
@echo "***********************************************************"
@echo "******** makefile's help, possible actions: ***************"
@echo "*** test : execute test on the project"
@echo "*** package : package the application"
@echo "*** coverage-display : execute tests and display code coverage in your navigator"
@echo "*** coverage : execute test and gets the code coverage on the project"
@echo "*** fmt : execute go fmt on the project"
@echo "*** audit : execute static audit on source code."
@echo "*** deps : get the dependencies of the project"
@echo "*** init : initialise the project"
@echo "*** clean : clean binaries and project structure"
@echo "*** package-zip : create the zip archive to delivery"
@echo "***********************************************************"
@echo ""
package: ${APP}
@tar -cvzf ${APP}-${GOOS}-${GOARCH}.tar.gz ${APP}
@echo " Archive ${APP}-${GOOS}-${GOARCH}.tar.gz created"
test: $(APP)
@GOOS=${GOOS} GOARCH=${GOARCH} go test -cover ./...
@echo " Tests OK."
coverage-display:
$(shell ls -d */ | while read d; do d_=`echo $$d | tr -d '/'`;go test -coverprofile=$$d_.out github.com/jeromelesaux/m4client/$$d_; go tool cover -html=$$d_.out; done 1>/dev/null)
@echo " Tests executed and results will be displayed in your navigator."
coverage:
@go get github.com/axw/gocov/gocov
@gocov test ./... | gocov report
$(APP): fmt $(SOURCES)
@echo " Compilation des sources ${BUILD_TIME}"
@echo ""
@GOOS=${GOOS} GOARCH=${GOARCH} go build -o ${APP} $(SOURCEDIR)/main.go
@echo " ${APP} generated."
fmt: audit
@echo " Go FMT"
@$(foreach element,$(SOURCES),go fmt $(element);)
audit: deps
@go tool vet -all . 2> audit.log &
@echo " Audit effectue"
deps: init
@echo " Download packages"
dep ensure -update -v
init: clean
@echo " Init of the project"
@echo " Version :: ${VERSION}"
clean:
@if [ -f "${APP}" ] ; then rm ${APP} ; fi
@if [ -f "${APP}-linux-amd64.tar.gz" ] ; then rm ${APP}-linux-amd64.tar.gz ; fi
@rm -f *.out
@echo " Nettoyage effectuee"
execute:
@./${APP} -port 8080 -dbconfig dbconfig.json -appconfig appconfig.json -logerrorfile test.log -loglevel DEBUG
package-zip: ${APP}
@zip -r ${APP}-${GOOS}-${GOARCH}.zip ./${APP}
@echo " Archive ${APP}-${GOOS}-${GOARCH}.zip created"
#----------------------------------------------------------------------#
#----------------------------- docker actions -------------------------#
#----------------------------------------------------------------------#
DOCKER_IP=$(shell if [ -z "$(DOCKER_MACHINE_NAME)" ]; then echo 'localhost'; else docker-machine ip $(DOCKER_MACHINE_NAME); fi)
dockerBuild:
docker build -t ${M4_CLIENT} .
dockerClean:
docker rmi -force ${M4_CLIENT} .
dockerUp:
docker-compose up -d
dockerStop:
docker-compose stop
docker-compose kill
docker-compose rm -f
dockerBuildUp: dockerStop dockerBuild
dockerWatch:
@watch -n1 'docker ps | grep ${M4_CLIENT}'
dockerLogs:
docker-compose logs -f
dockerBash:
docker exec -it $(shell docker ps -aqf "name=${M4_CLIENT}" 2> /dev/null) bash