-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
135 lines (104 loc) · 4.4 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
125
126
127
128
129
130
131
132
133
134
135
.PHONY: \
clean \
config \
config-dev \
dev \
doc \
exec \
help \
install \
logs \
ps \
query-db \
query-testdb \
start \
stop \
tail-logs \
test \
test-integration \
test-unit \
up \
.DEFAULT_GOAL:=help
#
# Variables
#
# The name of the binary.
BINARY:=prepaidcard
# The Go version.
GOVERSION:=1.11
# The name of the package.
PACKAGE:=github.com/sepetrov/prepaidcard
# The application version.
#
# The value is automatically generated using Git. You should never override it manually.
#
# Falls back gracefully to one of the values:
# - [tag] if HEAD is tagged
# - [tag]-[number of commits after the last tag]-g[short git commit hash] if HEAD has an offset from a tag
# - [git commit hash]
# - "unknown"
VERSION:=$(shell \
git -C . describe --tags 2> /dev/null || \
git -C . rev-parse --short HEAD 2> /dev/null || \
echo "unknown" \
)
# Override the variables with the environment variables from .env if it exists.
-include .env
##
## * Host targets
##
clean: ## Remove Docker containers and images
docker-compose -p prepaidcard -f docker-compose.yml -f docker-compose.override.yml rm -fsv
-docker rmi -f $(shell docker-compose -p prepaidcard -f docker-compose.yml -f docker-compose.override.yml images -q 2>/dev/null)
config: ## Show Docker configuration for development mode
@BINARY=$(BINARY) GOVERSION=$(GOVERSION) PACKAGE=$(PACKAGE) VERSION=$(VERSION) docker-compose -p prepaidcard -f docker-compose.yml -f docker-compose.override.yml config
config-dev: ## Show Docker configuration for production mode
@BINARY=$(BINARY) GOVERSION=$(GOVERSION) PACKAGE=$(PACKAGE) VERSION=$(VERSION) docker-compose -p prepaidcard -f docker-compose.yml config
dev: ## Build and start Docker conainer in development mode
BINARY=$(BINARY) GOVERSION=$(GOVERSION) PACKAGE=$(PACKAGE) VERSION=$(VERSION) docker-compose -p prepaidcard -f docker-compose.yml -f docker-compose.override.yml up --build -d --remove-orphans api
docker-compose -p prepaidcard -f docker-compose.yml -f docker-compose.override.yml exec api sh -c "make install && $(BINARY)"
doc: ## Build and start Swagger API container
VERSION=$(VERSION) docker-compose -p prepaidcard -f docker-compose.yml up -d doc
-[ -z "$(DOC_PORT)" ] || open http://localhost:$(DOC_PORT) 2> /dev/null
exec: ## SSH into API container running in development mode
docker-compose -p prepaidcard -f docker-compose.yml -f docker-compose.override.yml exec api sh
logs: ## Show Docker container logs
docker-compose -p prepaidcard -f docker-compose.yml -f docker-compose.override.yml logs
ps: ## Show Docker container status
docker-compose -p prepaidcard -f docker-compose.yml -f docker-compose.override.yml ps
query-db: ## Open MySQL client
docker-compose -p prepaidcard -f docker-compose.yml -f docker-compose.override.yml exec db mysql -uroot -p'$(DB_ROOT_PASSWORD)' $(BINARY)
query-testdb: ## Open MySQL client to test databse
docker-compose -p prepaidcard -f docker-compose.yml -f docker-compose.override.yml exec testdb mysql -uroot -p'$(DB_ROOT_PASSWORD)' $(BINARY)_test
start: ## Start Docker containers in development mode
docker-compose -p prepaidcard -f docker-compose.yml -f docker-compose.override.yml start
stop: ## Stop Docker container
docker-compose -p prepaidcard -f docker-compose.yml -f docker-compose.override.yml stop
tail-logs: ## Show Docker container logs continuously
docker-compose -p prepaidcard -f docker-compose.yml -f docker-compose.override.yml logs -f
up: ## Build and start Docker containers in prodution mode
BINARY=$(BINARY) GOVERSION=$(GOVERSION) PACKAGE=$(PACKAGE) VERSION=$(VERSION) docker-compose -p prepaidcard -f docker-compose.yml up --build --remove-orphans -d api
##
## * Container targets
##
install: ## Install application binary
CGO_ENABLED=0 go install -a -ldflags "-s -w -X '$(PACKAGE)/pkg/api/api.Version=$(VERSION)'" -v $(PACKAGE)
test: ## Run tests
CGO_ENABLED=0 go test -a -ldflags '-s -w' -v $(PACKAGE)/...
test-integration: ## Run integration tests
go test -tags=integration -v $(PACKAGE)/...
test-unit: ## Run unit tests
go test -tags=unit -v $(PACKAGE)/...
##
## * Help
##
help: ## Show this help message
@echo
@echo ' Usage:'
@echo ' make <target>'
@echo
@echo ' Targets:'
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
@echo
version: ## Print the version.
@echo $(VERSION)