-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
125 lines (98 loc) · 3.25 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
APP_NAME=fortress-api
DEFAULT_PORT=8200
POSTGRES_TEST_SERVICE?=postgres_test
POSTGRES_TEST_CONTAINER?=fortress_local_test
POSTGRES_CONTAINER?=fortress_local
TOOLS_IMAGE=dwarvesv/fortress-tools:latest
APP_ENVIRONMENT=docker run --rm -v ${PWD}:/${APP_NAME} -w /${APP_NAME} --net=host ${TOOLS_IMAGE}
SWAGGER_VERSION = v1.16.1
.PHONY: setup shel colima-start colima-stop init build dev test migrate-up migrate-down ci
shell:
@if ! command -v devbox >/dev/null 2>&1; then curl -fsSL https://get.jetpack.io/devbox | bash; fi
@devbox install
@devbox shell
colima-start:
colima start --cpu 1 --memory 2 --disk 30
colima-stop:
@colima stop
setup:
docker pull ${TOOLS_IMAGE}
init:
@if [[ "$(docker images -q dwarvesv/fortress-tools:latest 2> /dev/null)" == "" ]]; then \
docker pull ${TOOLS_IMAGE}; \
fi
make remove-infras
docker compose up -d
@echo "Waiting for database connection..."
@while ! docker exec ${POSTGRES_CONTAINER} pg_isready > /dev/null; do \
sleep 1; \
done
@while ! docker exec $(POSTGRES_TEST_CONTAINER) pg_isready > /dev/null; do \
sleep 1; \
done
make migrate-up
make migrate-test
make seed
make seed-test
seed:
@docker exec -t $(POSTGRES_CONTAINER) sh -c "mkdir -p /seed"
@docker exec -t $(POSTGRES_CONTAINER) sh -c "rm -rf /seed/*"
@docker cp migrations/seed $(POSTGRES_CONTAINER):/
@docker exec -t $(POSTGRES_CONTAINER) sh -c "PGPASSWORD=postgres psql -U postgres -d fortress_local -f /seed/seed.sql"
seed-test:
@docker exec -t $(POSTGRES_TEST_CONTAINER) sh -c "mkdir -p /seed"
@docker exec -t $(POSTGRES_TEST_CONTAINER) sh -c "rm -rf /seed/*"
@docker cp migrations/test_seed $(POSTGRES_TEST_CONTAINER):/
@docker exec -t $(POSTGRES_TEST_CONTAINER) sh -c "PGPASSWORD=postgres psql -U postgres -d $(POSTGRES_TEST_CONTAINER) -f /test_seed/seed.sql"
remove-infras:
docker compose down --remove-orphans --volumes
build:
env GOOS=darwin GOARCH=amd64 go build -o bin ./...
dev:
go run ./cmd/server/main.go
air:
air -c .air.toml
cronjob:
go run ./cmd/cronjob/main.go
test: setup-test
@PROJECT_PATH=$(shell pwd) go test -cover ./... -count=1 -p=1
setup-test:
docker rm --volumes -f ${POSTGRES_TEST_CONTAINER}
docker compose up -d ${POSTGRES_TEST_SERVICE}
@while ! docker exec $(POSTGRES_TEST_CONTAINER) pg_isready > /dev/null; do \
sleep 1; \
done
make migrate-test
make seed-test
migrate-test:
${APP_ENVIRONMENT} sql-migrate up -env=test
migrate-new:
${APP_ENVIRONMENT} sql-migrate new -env=local ${name}
migrate-up:
${APP_ENVIRONMENT} sql-migrate up -env=local
migrate-down:
${APP_ENVIRONMENT} sql-migrate down -env=local
docker-build:
docker build \
--build-arg DEFAULT_PORT="${DEFAULT_PORT}" \
-t ${APP_NAME}:latest .
reset-db:
${APP_ENVIRONMENT} sql-migrate down -env=local -limit=0
${APP_ENVIRONMENT} sql-migrate up -env=local
make seed
reset-test-db:
${APP_ENVIRONMENT} sql-migrate down -env=test -limit=0
${APP_ENVIRONMENT} sql-migrate up -env=test
make seed-test
gen-mock:
echo "add later"
gen-swagger:
swag init --parseDependency -g ./cmd/server/main.go
ci: init
@PROJECT_PATH=$(shell pwd) go test -cover ./... -count=1 -p=1
WD := $(shell pwd)
lint:
docker run -t --rm -v $(WD):/app -w /app golangci/golangci-lint:v1.52.2 golangci-lint run -v
.PHONY: digest
digest:
npx ai-digest --show-output-files --whitespace-removal