forked from code-kakitai/code-kakitai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
95 lines (72 loc) · 2.26 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
.PHONY: test
help: # コマンド確認
@echo "\033[32mAvailable targets:\033[0m"
@grep "^[a-zA-Z\-]*:" Makefile | grep -v "grep" | sed -e 's/^/make /' | sed -e 's/://'
# app-containerが起動しているかどうかのチェック、起動していればtrueを返す
check_app_container = $(shell docker ps --format '{{.Names}}' | grep -q code-kakitai-app && echo "true" || echo "false")
##################
# goサーバーの操作 #
##################
run:
docker compose exec app sh -c "go run ./cmd/main.go"
test: lint
cd app && go test ./...
lint:
cd app && go vet ./...
gen:
docker compose exec app sh -c "go generate ./..."
tidy:
docker compose exec app sh -c "go mod tidy"
##################
#### 環境関連 #####
##################
init:up
go work init ./app ./pkg
make migrate-apply
make create-test-data
up:
docker compose up -d
down:
docker compose down
destroy:
docker compose down --rmi all --volumes --remove-orphans
restart:
docker compose restart
logs:
docker compose logs -f
app-container:
docker compose exec app bash
##################
#### Swagger #####
##################
gen-swagger:
swag init -g app/cmd/main.go --output app/docs/swagger
swagger-up:
docker-compose -f app/docs/swagger/docker-compose.yml up -d
##################
##### DB関連 #####
##################
# マイグレーション
build-cli: # cliのビルド
cd app && go build -o ./cli/main ./cli/main.go
migrate-dry-run: up build-cli # migration dry-run
shema_path=$$(find . -name "schema.sql"); \
./app/cli/main migration $$shema_path
cd app && rm ./cli/main
migrate-apply: up build-cli # migration apply
shema_path=$$(find . -name "schema.sql"); \
DB_HOST=$(DB_HOST) ./app/cli/main migration $$shema_path apply
cd app && rm ./cli/main
migrate-local-dry-run:
@make migrate-dry-run DB_HOST=127.0.0.1
migrate-local-apply:
@make migrate-apply DB_HOST=127.0.0.1
# sqlc
sqlc-gen:
docker compose exec app sh -c "sqlc generate"
# test dataの作成
create-test-data:
docker compose cp ./ops/test_data/ db:/tmp/test_data
docker compose exec db sh -c "mysql -u root code_kakitai < /tmp/test_data/create_test_users.sql"
docker compose exec db sh -c "mysql -u root code_kakitai < /tmp/test_data/create_test_owners.sql"
docker compose exec db sh -c "rm -rf /tmp/test_data"