-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
190 lines (156 loc) · 5.33 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
help: # コマンド確認
@echo "\033[32mAvailable targets:\033[0m"
@grep "^[a-zA-Z\-]*:" Makefile | grep -v "grep" | sed -e 's/^/make /' | sed -e 's/://'
##############
### テスト ####
##############
# テスト処理の共通化
# パラメータ:
# - path=<テスト対象のパス> (デフォルト: ./...)
# - opts=<追加オプション> (デフォルト: なし)
# - tags=<ビルドタグ> (デフォルト: なし)
define tests
$(if $(TEST_TAGS),\
go test -v -timeout 10m -tags=$(TEST_TAGS) $(TEST_PATH) $(TEST_OPTIONS),\
go test -v -timeout 10m $(TEST_PATH) $(TEST_OPTIONS)\
)
endef
# appディレクトリの全体テスト
# コマンド例: $ make test-app opts="-run TestXxx"
test-app:
$(eval TEST_PATH=./...)
$(eval TEST_TAGS=$(tags))
$(eval TEST_OPTIONS=${opts})
@echo "Running all tests in app..."
cd ./app && $(call tests)
# ドメイン層のテスト
# コマンド例: $ make test-domain path=./... opts="-run TestXxx"
test-domain:
$(eval TEST_PATH=$(or $(path),./...))
$(eval TEST_TAGS=$(tags))
$(eval TEST_OPTIONS=${opts})
@echo "Running tests in domain..."
cd ./app/domain && $(call tests)
# ユースケースのテスト
# コマンド例: $ make test-usecase path=./... opts="-run TestXxx"
test-usecase:
$(eval TEST_PATH=$(or $(path),./...))
$(eval TEST_TAGS=$(tags))
$(eval TEST_OPTIONS=${opts})
@echo "Running tests in usecase..."
cd ./app/application/usecase && $(call tests)
# リポジトリのテスト
# コマンド例: $ make test-repo path=./... opts="-run TestXxx"
test-repo:
$(eval TEST_PATH=$(or $(path),./...))
$(eval TEST_TAGS=$(tags))
$(eval TEST_OPTIONS=${opts})
@echo "Running tests in repository..."
cd ./app/infrastructure/repository_test && $(call tests)
# クエリサービスのテスト
# コマンド例: $ make test-query path=./... opts="-run TestXxx"
test-query:
$(eval TEST_PATH=$(or $(path),./...))
$(eval TEST_TAGS=$(tags))
$(eval TEST_OPTIONS=${opts})
@echo "Running tests in queryservice..."
cd ./app/infrastructure/queryservice_test && $(call tests)
# pkgディレクトリのテスト
# コマンド例: $ make test-pkg path=./... opts="-run TestXxx"
test-pkg:
$(eval TEST_PATH=$(or $(path),./...))
$(eval TEST_TAGS=$(tags))
$(eval TEST_OPTIONS=${opts})
@echo "Running tests in pkg..."
cd ./pkg && $(call tests)
test-integration:
$(eval TEST_PATH=$(or $(path),./...))
$(eval TEST_TAGS=$(tags))
$(eval TEST_OPTIONS=${opts})
@echo "Running tests in integration"
cd ./app/infrastructure/api_test/integration && $(call tests) -tags=integration
#####################
##### コンテナ操作 ####
#####################
# docker-composeにおけるDockerfileのビルド
build:
@echo "Building Docker images..."
docker compose build
# docker compose up
up:
@echo "Starting containers with docker-compose up..."
docker compose up
# docker compose down
down:
@echo "Stopping containers with docker-compose down..."
docker compose down
# docker compose logs -f
logs:
@echo "Fetching logs with docker-compose logs..."
docker compose logs -f
# docker compose ps
ps:
@echo "Viewing running containers with docker-compose ps..."
docker compose ps
ls:
@echo "Viewing running containers with docker-compose ls..."
docker container ls
exec-db:
docker compose exec db /bin/bash
exec-kvs:
docker compose exec kvs /bin/bash
########################
### DBマイグレーション ####
########################
MIGRATE_PATH = infrastructure/db/migrations
DB_URL = mysql://user:pswd@tcp(db:3306)/todo-db?parseTime=true
# マイグレーションファイルを作成
# コマンド例: $ make migrate-create name=<migration-name>
migrate-create:
$(eval NAME=$(or $(name),$(error "Error: Please specify a migration name using name=<name>")))
@echo "Creating migration file..."
cd app/ && migrate create -ext sql -dir $(MIGRATE_PATH) -seq $(NAME)
# マイグレーションを適用
# コマンド例: $ make migrate-up
migrate-up:
@echo "Applying migrations..."
docker compose run --rm app migrate --path $(MIGRATE_PATH) --database "$(DB_URL)" -verbose up
# マイグレーションをロールバック
# コマンド例: $ make migrate-down
migrate-down:
@echo "Rolling back migrations..."
docker compose run --rm app migrate --path $(MIGRATE_PATH) --database "$(DB_URL)" -verbose down
# マイグレーションのバージョンをセット
# migration-upが失敗した時は、最後のバージョンにforceしなおしてから再度upするようにする
# コマンド例: $ make migrate-force version=<version_number>
migrate-force:
@echo "Forcing database migration version to $(version)..."
docker compose run --rm app migrate --path $(MIGRATE_PATH) --database "$(DB_URL)" force $(version)
#############
### sqlc ####
#############
# sqlcでコードを生成
sqlc-gen:
@echo "Generating query in sql by sqlc..."
cd ./app/infrastructure/db/sqlc && sqlc generate
#############
## swagger ##
#############
# コメントをパースしてドキュメント生成
swag:
@echo "Generating document by swagger..."
cd ./app && swag fmt && swag init
###################
### パッケージ管理 ###
###################
# github.com/kakkky/appにおいてgo getする
# コマンド例: $ make get-app name=github.com/xxxx/xxx
get-app:
cd ./app && go get $(name)
get-pkg:
cd ./pkg && go get $(name)
###################
### go generate ###
###################
go-gen:
cd ./app && go generate ./...