-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Makefile
147 lines (109 loc) · 4.6 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
141
142
143
144
145
146
147
# Database
MYSQL_USER ?= user
MYSQL_PASSWORD ?= password
MYSQL_ADDRESS ?= 127.0.0.1:3306
MYSQL_DATABASE ?= article
# Exporting bin folder to the path for makefile
export PATH := $(PWD)/bin:$(PATH)
# Default Shell
export SHELL := bash
# Type of OS: Linux or Darwin.
export OSTYPE := $(shell uname -s | tr A-Z a-z)
export ARCH := $(shell uname -m)
# --- Tooling & Variables ----------------------------------------------------------------
include ./misc/make/tools.Makefile
include ./misc/make/help.Makefile
# ~~~ Development Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
up: dev-env dev-air ## Startup / Spinup Docker Compose and air
down: docker-stop ## Stop Docker
destroy: docker-teardown clean ## Teardown (removes volumes, tmp files, etc...)
install-deps: migrate air gotestsum tparse mockery ## Install Development Dependencies (localy).
deps: $(MIGRATE) $(AIR) $(GOTESTSUM) $(TPARSE) $(MOCKERY) $(GOLANGCI) ## Checks for Global Development Dependencies.
deps:
@echo "Required Tools Are Available"
dev-env: ## Bootstrap Environment (with a Docker-Compose help).
@ docker-compose up -d --build mysql
dev-env-test: dev-env ## Run application (within a Docker-Compose help)
@ $(MAKE) image-build
docker-compose up web
dev-air: $(AIR) ## Starts AIR ( Continuous Development app).
air
docker-stop:
@ docker-compose down
docker-teardown:
@ docker-compose down --remove-orphans -v
# ~~~ Code Actions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lint: $(GOLANGCI) ## Runs golangci-lint with predefined configuration
@echo "Applying linter"
golangci-lint version
golangci-lint run -c .golangci.yaml ./...
# -trimpath - will remove the filepathes from the reports, good to same money on network trafic,
# focus on bug reports, and find issues fast.
# - race - adds a racedetector, in case of racecondition, you can catch report with sentry.
# https://golang.org/doc/articles/race_detector.html
#
# todo(butuzov): add additional flags to compiler to have an `version` flag.
build: ## Builds binary
@ printf "Building aplication... "
@ go build \
-trimpath \
-o engine \
./app/
@ echo "done"
build-race: ## Builds binary (with -race flag)
@ printf "Building aplication with race flag... "
@ go build \
-trimpath \
-race \
-o engine \
./app/
@ echo "done"
go-generate: $(MOCKERY) ## Runs go generte ./...
go generate ./...
TESTS_ARGS := --format testname --jsonfile gotestsum.json.out
TESTS_ARGS += --max-fails 2
TESTS_ARGS += -- ./...
TESTS_ARGS += -test.parallel 2
TESTS_ARGS += -test.count 1
TESTS_ARGS += -test.failfast
TESTS_ARGS += -test.coverprofile coverage.out
TESTS_ARGS += -test.timeout 5s
TESTS_ARGS += -race
tests: $(GOTESTSUM)
@ gotestsum $(TESTS_ARGS) -short
tests-complete: tests $(TPARSE) ## Run Tests & parse details
@cat gotestsum.json.out | $(TPARSE) -all -notests
# ~~~ Docker Build ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ONESHELL:
image-build:
@ echo "Docker Build"
@ DOCKER_BUILDKIT=0 docker build \
--file Dockerfile \
--tag go-clean-arch \
.
# Commenting this as this not relevant for the project, we load the DB data from the SQL file.
# please refer this when introducing the database schema migrations.
# # ~~~ Database Migrations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# MYSQL_DSN := "mysql://$(MYSQL_USER):$(MYSQL_PASSWORD)@tcp($(MYSQL_ADDRESS))/$(MYSQL_DATABASE)"
# migrate-up: $(MIGRATE) ## Apply all (or N up) migrations.
# @ read -p "How many migration you wants to perform (default value: [all]): " N; \
# migrate -database $(MYSQL_DSN) -path=misc/migrations up ${NN}
# .PHONY: migrate-down
# migrate-down: $(MIGRATE) ## Apply all (or N down) migrations.
# @ read -p "How many migration you wants to perform (default value: [all]): " N; \
# migrate -database $(MYSQL_DSN) -path=misc/migrations down ${NN}
# .PHONY: migrate-drop
# migrate-drop: $(MIGRATE) ## Drop everything inside the database.
# migrate -database $(MYSQL_DSN) -path=misc/migrations drop
# .PHONY: migrate-create
# migrate-create: $(MIGRATE) ## Create a set of up/down migrations with a specified name.
# @ read -p "Please provide name for the migration: " Name; \
# migrate create -ext sql -dir misc/migrations $${Name}
# ~~~ Cleans ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clean: clean-artifacts clean-docker
clean-artifacts: ## Removes Artifacts (*.out)
@printf "Cleanning artifacts... "
@rm -f *.out
@echo "done."
clean-docker: ## Removes dangling docker images
@ docker image prune -f