-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
140 lines (106 loc) · 3.06 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
136
137
138
139
140
# Project variables
MAINPATH := ./cmd/server
BINDIR := $(CURDIR)/bin
BINNAME ?= users-microservice
# Go binary location (usefull when using multiple go versions)
GOBIN ?= $(shell which go)
# Go commands flags
PKG := ./...
LDFLAGS := -w -s
CGO_ENABLED ?= 0
TEST_FLAGS := -race -failfast -cover -coverprofile=./test/coverage/c.out
EXTRA_TEST_FLAGS ?= -v
# Docker compose configs
DC_DEV_FILE ?= docker-compose.dev.yaml
DC_LOCAL_FILE ?= docker-compose.local.yaml
DC_ARGS ?= ""
# Project config files
CONFIG_FILE_LOCAL := $(CURDIR)/config/local.yaml
CONFIG_FILE_DEV := $(CURDIR)/config/dev.yaml
# =====================================================
# Main commands
.PHONY: all
all: build
.PHONY: build
build:
GO111MODULE=on CGO_ENABLED=$(CGO_ENABLED) $(GOBIN) build -trimpath -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(BINNAME) $(MAINPATH)
.PHONY: run
run:
ifeq ($(CONFIG_FILE),)
run: CONFIG_FILE=$(CONFIG_FILE_LOCAL)
endif
run:
CONFIG_FILE=$(CONFIG_FILE) $(GOBIN) run $(MAINPATH)
.PHONY: test
test:
$(GOBIN) test $(TEST_FLAGS) $(EXTRA_TEST_FLAGS) ./...
# =====================================================
# Dependencies
.PHONY: tidy
tidy:
$(GOBIN) mod tidy
.PHONY: vendor
vendor:
$(GOBIN) mod vendor
# =====================================================
# Test coverage
.PHONY: cover
cover: test cover-only
.PHONY: coverage
coverage: cover
.PHONY: coverage-only
coverage-only:
$(GOBIN) tool cover -html=./test/coverage/c.out
.PHONY: cover-only
cover-only: coverage-only
# =====================================================
# Tools
$(MOCKGEN):
(cd /; GO111MODULE=on $(GOBIN) install github.com/golang/mock/mockgen@v1.6.0)
.PHONY: generate
generate: $(MOCKGEN)
$(GOBIN) generate ./...
$(SWAGGOSWAG):
(cd /; GO111MODULE=on $(GOBIN) install github.com/swaggo/swag/cmd/swag@latest)
.PHONY: swag
swag: $(SWAGGOSWAG) vendor
@echo "Running swaggo-swag"
swag init --parseDependency --parseVendor --parseInternal -g **/**/*.go --exclude ./vendor
swag fmt
# =====================================================
# Docker compose commands
.PHONY: dev-up
dev-up:
docker compose -f $(DC_DEV_FILE) up --remove-orphans --build -d
.PHONY: dev-stop
dev-stop:
docker compose -f $(DC_DEV_FILE) stop
.PHONY: dev-down
dev-down:
docker compose -f $(DC_DEV_FILE) down --remove-orphans
.PHONY: dev-exec
dev-exec:
docker compose -f $(DC_DEV_FILE) $(DC_ARGS)
.PHONY: local-up
local-up:
docker compose -f $(DC_LOCAL_FILE) up --remove-orphans --build -d
.PHONY: local-stop
local-stop:
docker compose -f $(DC_LOCAL_FILE) stop
.PHONY: local-down
local-down:
docker compose -f $(DC_LOCAL_FILE) down --remove-orphans
.PHONY: local-exec
local-exec:
docker compose -f $(DC_LOCAL_FILE) $(DC_ARGS)
# =====================================================
# Subscriber sidecar
.PHONY: subscriber
ifeq ($(CONFIG_FILE),)
subscriber: CONFIG_FILE=$(CONFIG_FILE_LOCAL)
endif
subscriber:
CONFIG_FILE=$(CONFIG_FILE) $(GOBIN) run ./cmd/subscriber
.PHONY: build-subscriber
build-subscriber:
GO111MODULE=on CGO_ENABLED=$(CGO_ENABLED) $(GOBIN) build -trimpath -ldflags '$(LDFLAGS)' -o $(BINDIR)/subscriber ./cmd/subscriber