-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
119 lines (99 loc) · 3.57 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
TARGET := caweb
.PHONY: all build integration-tests
all: build
build:
go build -tags="go_json nomsgpack" ./cmd/caweb
integration-tests:
if [ ! -s $$XDG_RUNTIME_DIR/podman/podman.sock ]; then \
systemctl --user start podman.service; \
fi && \
DOCKER_HOST=unix://$$XDG_RUNTIME_DIR/podman/podman.sock \
go test ./pkg/adapter/restful/gin -run TestIntegration
.PHONY: config-test
config-test:
go test ./pkg/adapter/config/...
.PHONY: mig-tests
mig-tests:
if [ ! -s $$XDG_RUNTIME_DIR/podman/podman.sock ]; then \
systemctl --user start podman.service; \
fi && \
DOCKER_HOST=unix://$$XDG_RUNTIME_DIR/podman/podman.sock \
go test ./pkg/core/usecase/migrationuc
.PHONY: scram-test
scram-test:
go test ./pkg/adapter/hash/scram
.PHONY: test
test: config-test integration-tests mig-tests scram-test
.PHONY: install-staticcheck install-revive revive lint
install-staticcheck:
go install honnef.co/go/tools/cmd/staticcheck@2023.1.6
install-revive:
go get -u github.com/mgechev/revive
revive:
revive -formatter friendly ./...
lint:
@staticcheck ./...
@revive ./...
SRC_DB_DIR := dist/.db/caweb1_0_0
.PHONY: src-db src-db-psql
src-db: $(SRC_DB_DIR)/.pgpass
podman start caweb1_0_0-pg16-dbms
$(SRC_DB_DIR)/.pgpass:
adminpass="$$(head -c16 /dev/random | sha1sum | cut -d' ' -f1)" && \
cawebpass="$$(head -c16 /dev/random | sha1sum | cut -d' ' -f1)" && \
mkdir -p $(SRC_DB_DIR)/data && \
echo "127.0.0.1:5455:caweb1_0_0:admin:$$adminpass" > $@ && \
echo "127.0.0.1:5455:caweb1_0_0:caweb:$$cawebpass" >> $@ && \
chmod 0600 $@ && \
podman run -t --detach --replace --name caweb1_0_0-pg16-dbms \
-e POSTGRES_USER="admin" \
-e POSTGRES_PASSWORD="$$adminpass" \
-e POSTGRES_DB="caweb1_0_0" \
-e POSTGRES_HOST_AUTH_METHOD="scram-sha-256" \
-e POSTGRES_INITDB_ARGS="--auth-host=scram-sha-256" \
-v $(CURDIR)/$(SRC_DB_DIR)/data:/var/lib/postgresql/data:Z \
-p 5455:5432 \
docker.io/postgres:16-bookworm
src-db-psql: src-db
PGPASSFILE=$(SRC_DB_DIR)/.pgpass \
psql -h 127.0.0.1 -p 5455 -U admin -d caweb1_0_0
DST_DB_DIR := dist/.db/caweb1_2_0
.PHONY: dst-db dst-db-psql
dst-db: $(DST_DB_DIR)/.pgpass
podman start caweb1_2_0-pg16-dbms
$(DST_DB_DIR)/.pgpass:
adminpass="$$(head -c16 /dev/random | sha1sum | cut -d' ' -f1)" && \
cawebpass="$$(head -c16 /dev/random | sha1sum | cut -d' ' -f1)" && \
mkdir -p $(DST_DB_DIR)/data && \
echo "127.0.0.1:5456:caweb1_2_0:admin:$$adminpass" > $@ && \
echo "127.0.0.1:5456:caweb1_2_0:caweb:$$cawebpass" >> $@ && \
chmod 0600 $@ && \
podman run -t --detach --replace --name caweb1_2_0-pg16-dbms \
-e POSTGRES_USER="admin" \
-e POSTGRES_PASSWORD="$$adminpass" \
-e POSTGRES_DB="caweb1_2_0" \
-e POSTGRES_HOST_AUTH_METHOD="scram-sha-256" \
-e POSTGRES_INITDB_ARGS="--auth-host=scram-sha-256" \
-v $(CURDIR)/$(DST_DB_DIR)/data:/var/lib/postgresql/data:Z \
-p 5456:5432 \
docker.io/postgres:16-bookworm
dst-db-psql: dst-db
PGPASSFILE=$(DST_DB_DIR)/.pgpass \
psql -h 127.0.0.1 -p 5456 -U admin -d caweb1_2_0
.PHONY: grep
grep:
grep -R --exclude-dir=.git --exclude-dir=dist ${ARGS} .
.PHONY: manual-migration-test
manual-migration-test: build
podman stop --ignore caweb1_0_0-pg16-dbms
podman stop --ignore caweb1_2_0-pg16-dbms
for dir in "$(SRC_DB_DIR)" "$(DST_DB_DIR)"; do \
podman unshare rm -rf "$$dir" && mkdir -p "$$dir"; \
done
$(MAKE) src-db dst-db
sleep 10
./$(TARGET) db init-dev --config configs/sample-src-config.yaml
./$(TARGET) db migrate configs/sample-src-config.yaml \
configs/sample-dst-config.yaml \
--config configs/sample-config.yaml
echo "Check configs/sample-config.yaml as the target config file."