-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
153 lines (112 loc) · 4.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
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
148
149
150
151
152
153
# 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 ./scripts/make/tools.Makefile
include ./scripts/make/help.Makefile
# Load environment variables from .env file
ifneq (,$(wildcard ./.env))
include .env
export
endif
# ~~~ 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 db loki promtail grafana redis
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.yml ./...
# -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 api_server \
./cmd/app/
@ echo "done"
build-race: ## Builds binary (with -race flag)
@ printf "Building aplication with race flag... "
@ go build \
-trimpath \
-race \
-o api_server \
./cmd/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 curium-go-fiber \
--build-arg SERVER_PORT=$(SERVER_PORT) \
.
# # ~~~ Database Migrations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
POSTGRE_DSN := "postgres://$(DATABASE_USER):$(DATABASE_PASS)@$(DATABASE_HOST):$(DATABASE_PORT)/$(DATABASE_NAME)?sslmode=disable"
migrate-up: $(MIGRATE) ## Apply all (or N up) migrations.
@ read -p "How many migration you wants to perform (default value: [all]): " N; \
migrate -database $(POSTGRE_DSN) -path=scripts/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 $(POSTGRE_DSN) -path=scripts/migrations down ${NN}
# .PHONY: migrate-drop
# migrate-drop: $(MIGRATE) ## Drop everything inside the database.
# migrate -database $(POSTGRE_DSN) -path=scripts/migrations drop
.PHONY: migrate-dirty
migrate-dirty: $(MIGRATE) ## Clean a dirty migration by force
@ read -p "Fixed migration error and continue the migration process on version: " N; \
migrate -database $(POSTGRE_DSN) -path=scripts/migrations force $${N}
.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 scripts/migrations -seq $${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