-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
148 lines (121 loc) · 3.88 KB
/
Makefile
File metadata and controls
148 lines (121 loc) · 3.88 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
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
.PHONY: all \
# Utilities
ensure-tool-pnpm ensure-tool-node \
# Tests
setup \
bench bench-clean bench-all \
# Local development/Debug
debug-api-server \
# Local development DB
db-custom-image \
db-local db-local-setup db-local-stop db-local \
db-migration db-local-migrate db-local-revert \
db-local-psql
KUBECTL ?= kubectl
NODE ?= node
PNPM ?= pnpm
DOCKER ?= docker
ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
DB_DATA_DIR ?= $(ROOT_DIR)output/postgres/data
DB_INIT_SCRIPTS_DIR ?= $(ROOT_DIR)output/postgres/init-scripts
DB_MIGRATIONS_DIR ?= $(ROOT_DIR)output/postgres/init-scripts
DB_CONTAINER_NAME ?= "supaseenby-pg"
DB_IMAGE ?= "postgres" # custom image -> "postgres-14.4-alpine-hll"
DB_IMAGE_TAG ?= "14.4-alpine" # custom image -> "latest"
DB_USER_NAME ?= "supaseenby"
DB_USER_PASSWORD ?= "supaseenby"
DB_NAME ?= "supaseenby"
DB_PORT ?= 5432
DB_HOST ?= localhost
DB_URL ?= "postgres://$(DB_USER_NAME):$(DB_USER_PASSWORD)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)"
all: setup bench-all
###########
# Tooling #
###########
ensure-tool-pnpm:
ifeq ("","$(shell which $(PNPM))")
$(error "PNPM is not installed (see: https://pnpm.io)")
endif
ensure-tool-node:
ifeq ("","$(shell which $(NODE))")
$(error "NodeJS is not installed (see: https://github.com/nvm-sh/nvm, https://nodejs.org)")
endif
ensure-tool-docker:
ifeq ("","$(shell which $(DOCKER))")
$(error "Docker is not installed (see: https://docs.docker.com)")
endif
#########
# Tests #
#########
setup: ensure-tool-pnpm
$(PNPM) install
bench:
echo -e "=> running benchmarks (local DB should be setup & running)..."
@DB_URL=$(DB_URL) \
$(PNPM) bench
bench-clean:
@echo -e "=> Run the following to clean out test bench. BE CAREFUL"
@echo -e "==> rm $(TEST_USERS_JSON_PATH)"
@echo -e "==> rm $(TEST_POSTS_JSON_PATH)"
bench-all:
$(MAKE) -S --no-print-directory bench SEEN_BY_STRATEGY=simple-counter > ./simple-counter.bench.log
$(MAKE) -S --no-print-directory bench SEEN_BY_STRATEGY=simple-hstore > ./simple-hstore.bench.log
$(MAKE) -S --no-print-directory bench SEEN_BY_STRATEGY=assoc-table > ./assoc-table.bench.log
$(MAKE) -S --no-print-directory bench SEEN_BY_STRATEGY=hll > ./hll.bench.log
#####################
# Local development #
#####################
##########################
# Local development - DB #
##########################
db-custom-image:
$(DOCKER) build -t $(DB_IMAGE) -f ./postgres14.4-hll.Dockerfile .
db-local-setup:
mkdir -p $(DB_DATA_DIR)
db-local-stop:
@if docker ps | grep $(DB_CONTAINER_NAME) ; then \
echo "[info] removing existing container if present..."; \
$(DOCKER) kill $(DB_CONTAINER_NAME) || true; \
$(DOCKER) rm $(DB_CONTAINER_NAME) || true; \
fi
### Start a local DB for the API only
db-local: db-local-stop
@echo -e "Running local DB...\n\n"
$(DOCKER) run --rm \
$(DOCKER_OPTS) \
-it \
--env POSTGRES_PASSWORD=$(DB_USER_PASSWORD) \
--env POSTGRES_USER=$(DB_USER_NAME) \
-p 127.0.0.1:${DB_PORT}:${DB_PORT} \
-v ${DB_DATA_DIR}:/var/lib/postgresql/data:z \
-v ${DB_INIT_SCRIPTS_DIR}:/docker-entrypoint-initdb.d:z \
--name ${DB_CONTAINER_NAME} \
${DB_IMAGE}:${DB_IMAGE_TAG}
db-local-clean:
@echo -e "Cleaning local DB..."
sudo rm -r ${DB_DATA_DIR}
db-migration:
ifeq (,$(NAME))
$(error "NAME not set")
else
@DB_URL=$(DB_URL) \
DB_MIGRATIONS_DIR=$(DB_MIGRATIONS_DIR) \
$(PNPM) run "db:migration:create" --name $(NAME).sql
endif
db-local-migrate: ensure-tool-pnpm
@DB_URL=$(DB_URL) \
DB_MIGRATIONS_DIR=$(DB_MIGRATIONS_DIR) \
$(PNPM) run "db:migrate:up"
db-local-revert: ensure-tool-pnpm
DB_URL=$(DB_URL) \
DB_MIGRATIONS_DIR=$(DB_MIGRATIONS_DIR) \
$(PNPM) run "db:migrate:down"
db-local-psql: ensure-tool-docker
$(DOCKER) exec -it $(DB_CONTAINER_NAME) psql -U $(DB_USER_NAME)
###########################
# Local development - API #
###########################
api-local:
echo -e "=> running server for local debug..."
DB_URL=$(DB_URL) \
$(PNPM) run "api:server"