-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
115 lines (84 loc) · 3.37 KB
/
Copy pathMakefile
File metadata and controls
115 lines (84 loc) · 3.37 KB
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
.DEFAULT_GOAL := help
# HOST is only used for API specs generation
HOST ?= localhost:8080
# Generates a help message. Borrowed from https://github.com/pydanny/cookiecutter-djangopackage.
help: ## Display this help message
@echo "Please use \`make <target>' where <target> is one of"
@perl -nle'print $& if m{^[\.a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-25s\033[0m %s\n", $$1, $$2}'
depends: ## Install & build dependencies
go get ./...
go build ./...
go mod tidy
provision: depends ## Provision dev environment
docker-compose up -d
scripts/waitdb.sh
@$(MAKE) migrate
dev: ## Bring up the server on dev environment with hot reload
air
remove: ## Bring down the server on dev environment, remove all docker related stuffs as well
docker-compose down -v --remove-orphans
migrate: ## Run database migrations
go run cmd/migration/main.go up
migrate.undo: ## Undo the last database migration
go run cmd/migration/main.go down
migrate.status: ## Check migration status
go run cmd/migration/main.go status
migrate.version: ## Show current migration version
go run cmd/migration/main.go version
migrate.create: ## Create new migration file (usage: make migrate.create name=add_users_table)
@if [ -z "$(name)" ]; then \
echo "Error: name is required. Usage: make migrate.create name=add_users_table"; \
exit 1; \
fi
go run cmd/migration/main.go create $(name) sql
migrate.reset: ## Rollback all migrations
go run cmd/migration/main.go reset
migrate.redo: ## Redo the last migration
go run cmd/migration/main.go redo
wire: ## Generate wire dependency injection code
cd internal/di && GOFLAGS=-mod=mod wire
wire.check: ## Check if wire code is up to date
cd internal/di && GOFLAGS=-mod=mod wire check
seed: ## Run database seeder
echo "To be done!"
test: ## Run tests
sh scripts/test.sh
test.cover: test ## Run tests and open coverage statistics page
go tool cover -html=coverage-all.out
build: clean ## Build the server binary file on host machine
sh scripts/build.sh
build.linux: ## Build the server binary file for Linux host
@$(MAKE) GOOS=linux GOARCH=amd64 build
build.windows: ## Build the server binary file for Windows host
@$(MAKE) GOOS=windows GOARCH=amd64 build
build.arm: clean ## Build the server binary file for ARM host
GOOS=linux GOARCH=arm64 sh scripts/build-arm.sh
build.air: ## Build the server binary file for air hot reload
sh scripts/build-air.sh
clean: ## Clean up the built & test files
rm -rf ./server ./*.out
specs: ## Generate swagger specs
swag fmt -g /cmd/api/main.go
swag fmt -d ./internal/api
swag init --parseInternal --parseDependency --parseDepth 1 -g /cmd/api/main.go -o ./internal/api/docs
docker.build: ## Build Docker image
docker build -t gocore:latest .
docker.run: ## Run Docker container (requires running database)
docker run -d \
--name gocore \
-p 8080:8080 \
-e DB_DSN="goone:goone123@tcp(host.docker.internal:3306)/goone?charset=utf8mb4&parseTime=True&loc=Local" \
gocore:latest
docker.stop: ## Stop Docker container
docker stop gocore || true
docker rm gocore || true
docker.logs: ## View Docker container logs
docker logs -f gocore
docker.export: ## Export Docker image to tar file
docker save gocore:latest -o gocore-latest.tar
%: # prevent error for `up` target when passing arguments
ifeq ($(filter up,$(MAKECMDGOALS)),up)
@:
else
$(error No rule to make target `$@`.)
endif