-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
247 lines (202 loc) · 9.93 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#----------------------
# Parse makefile arguments
#----------------------
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(RUN_ARGS):;@:)
#----------------------
# Silence GNU Make
#----------------------
ifndef VERBOSE
MAKEFLAGS += --no-print-directory
endif
#----------------------
# Load .env file
#----------------------
ifneq ("$(wildcard .env)","")
include .env
export
else
endif
DRUNPREFIX=
ifeq ($(OS),Windows_NT)
DRUNPREFIX = winpty
endif
COMPOSE_COMMAND=docker-compose
ifeq ($(APP_ENV),production)
COMPOSE_COMMAND=docker-compose -f docker-compose.yml -f docker-compose.prod.yml
endif
#----------------------
# Terminal
#----------------------
GREEN := $(shell tput -Txterm setaf 2)
WHITE := $(shell tput -Txterm setaf 7)
YELLOW := $(shell tput -Txterm setaf 3)
RESET := $(shell tput -Txterm sgr0)
#------------------------------------------------------------------
# - Add the following 'help' target to your Makefile
# - Add help text after each target name starting with '\#\#'
# - A category can be added with @category
#------------------------------------------------------------------
.PHONY: build test
HELP_FUN = \
%help; \
while(<>) { \
push @{$$help{$$2 // 'options'}}, [$$1, $$3] if /^([a-zA-Z\-]+)\s*:.*\#\#(?:@([a-zA-Z\-]+))?\s(.*)$$/ }; \
print "\n"; \
for (sort keys %help) { \
print "${WHITE}$$_${RESET \
}\n"; \
for (@{$$help{$$_}}) { \
$$sep = " " x (32 - length $$_->[0]); \
print " ${YELLOW}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n"; \
}; \
print ""; \
}
help: ##@other Show this help.
@perl -e '$(HELP_FUN)' $(MAKEFILE_LIST)
#----------------------
# dev
#----------------------
bash: ##@dev Bash into workspace container
$(COMPOSE_COMMAND) up -d workspace
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec workspace bash
mc: ##@dev Create MySQL shell
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec mysql sh -c "mysql -uroot -p${MYSQL_ROOT_PASSWORD} -h localhost"
rc: ##@dev Create Redis shell
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec redis sh -c "redis-cli"
up: ##@dev Brings up environment
$(COMPOSE_COMMAND) up -d mysql workspace
ifeq ($(APP_ENV),production)
$(COMPOSE_COMMAND) up -d mysql workspace
endif
down: ##@dev Shuts down environment
$(COMPOSE_COMMAND) down -t 1
logs: ##@dev Follow container logs
$(COMPOSE_COMMAND) logs --follow
test: ##@dev Runs local tests
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec workspace bash -c "go test -count=1 -cover ./... | grep -v 'no test files'"
#----------------------
# dev-watch
#----------------------
watch-fe: ##@dev-watch Runs frontend watcher
$(COMPOSE_COMMAND) exec workspace bash -c "cd frontend && npm run dev"
watch-be: ##@dev-watch Runs backend watcher
$(COMPOSE_COMMAND) exec workspace bash -c "air -c .air.toml"
#----------------------
# seed
#----------------------
seed-peq-database: ##@seed
$(COMPOSE_COMMAND) up -d workspace
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec workspace bash -c "curl http://db.projecteq.net/api/v1/dump/latest -o /tmp/db.zip"
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec workspace bash -c "unzip -o /tmp/db.zip -d /tmp/db/"
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec workspace bash -c "mysql -h mysql -u${MYSQL_USERNAME} -p${MYSQL_PASSWORD} ${MYSQL_EQEMU_DATABASE} -e 'DROP DATABASE ${MYSQL_EQEMU_DATABASE}; CREATE DATABASE ${MYSQL_EQEMU_DATABASE};'"
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec workspace bash -c "cd /tmp/db/peq-dump/ && mysql -h mysql -u${MYSQL_USERNAME} -p${MYSQL_PASSWORD} ${MYSQL_EQEMU_DATABASE} < ./create_all_tables.sql"
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec workspace bash -c "rm -rf /tmp/db/"
# This needs to get cleaned up later
seed-peq-database-prod: ##@seed
$(COMPOSE_COMMAND) exec prod bash -c "curl http://db.projecteq.net/api/v1/dump/latest -o /tmp/db.zip"
$(COMPOSE_COMMAND) exec prod bash -c "unzip -o /tmp/db.zip -d /tmp/db/"
$(COMPOSE_COMMAND) exec prod bash -c "mysql -h mysql -u${MYSQL_USERNAME} -p${MYSQL_PASSWORD} ${MYSQL_EQEMU_DATABASE} -e 'DROP DATABASE ${MYSQL_EQEMU_DATABASE}; CREATE DATABASE ${MYSQL_EQEMU_DATABASE};'"
$(COMPOSE_COMMAND) exec prod bash -c "cd /tmp/db/peq-dump/ && mysql -h mysql -u${MYSQL_USERNAME} -p${MYSQL_PASSWORD} ${MYSQL_EQEMU_DATABASE} < ./create_all_tables.sql"
$(COMPOSE_COMMAND) exec prod bash -c "rm -rf /tmp/db/"
seed-spire-tables: ##@seed
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec workspace bash -c "go run main.go spire:migrate"
#----------------------
# generate
#----------------------
generate-api-pipeline: ##@generate Runs entire API generation pipeline, backend models and controllers with frontend client (Run in workspace)
@./scripts/banner.sh "Generating generation config"
go run main.go generate:config
@./scripts/banner.sh "Generating backend models"
go run main.go generate:models
@./scripts/banner.sh "Generating backend controllers"
go run main.go generate:controllers
@./scripts/banner.sh "Generating Swagger spec"
make generate-swagger
@./scripts/banner.sh "Generating frontend Typescript axios client"
make generate-axios-client-local
@./scripts/banner.sh "Generation pipeline complete"
generate-axios-client-local: ##@generate Generate Axios client from Swagger spec
# sudo npm install @openapitools/openapi-generator-cli -g
sudo openapi-generator-cli version-manager set 5.0.0
sudo openapi-generator-cli generate --enable-post-process-file \
-i ./docs/swagger.yaml \
-g typescript-axios \
-o ./frontend/src/app/api/ \
-c ./openapi-generator-config.yaml
git checkout master ./frontend/src/app/api/api.ts
./scripts/strip-axios-client-comments.sh
generate-swagger: ##@generate Generate swagger docs (Run in workspace container)
./scripts/generate-swagger.sh
#----------------------
# install
#----------------------
build: ##@install Build
$(DRUNPREFIX) $(COMPOSE_COMMAND) build
publish: ##@images
docker push akkadius/spire:go-workspace
docker tag akkadius/spire:go-workspace akkadius/spire:go-workspace-v12
docker push akkadius/spire:go-workspace-v12
install: ##@install Runs installer
$(DRUNPREFIX) $(COMPOSE_COMMAND) build
make mysql-init
make seed-peq-database
make seed-spire-tables
make install-assets
@./scripts/banner.sh "Environment Initialized!"
@cat ./scripts/install-message.txt
install-assets: ##@install Installs assets
@./scripts/banner.sh "Initializing eq-asset-preview assets..."
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec workspace bash -c 'curl --compressed -o /tmp/assets.zip -L https://github.com/Akkadius/eq-asset-preview/archive/refs/heads/master.zip'
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec workspace bash -c 'unzip -o /tmp/assets.zip -d /tmp/assets'
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec workspace bash -c 'cp -R /tmp/assets/eq-asset-preview-master/ ./frontend/public/'
install-frontend: ##@install Install and initialize frontend packages
cp frontend/.env.example frontend/.env
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec workspace bash -c 'cd frontend && npm install'
#----------------------
# mysql
#----------------------
mysql-init: ##@mysql Initialize database
@./scripts/banner.sh "Initializing MySQL Database..."
$(COMPOSE_COMMAND) kill mysql
$(COMPOSE_COMMAND) build mysql
$(COMPOSE_COMMAND) up -d mysql
$(DRUNPREFIX) $(COMPOSE_COMMAND) run --user=root mysql bash -c "chown -R mysql:mysql /var/lib/mysql && exit"
$(COMPOSE_COMMAND) up -d mysql
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec -T mysql sh -c 'while ! mysqladmin ping -h "mysql" --silent; do sleep .5; done'
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec mysql sh -c "mysql -h localhost -uroot -p${MYSQL_ROOT_PASSWORD} -e 'CREATE DATABASE IF NOT EXISTS ${MYSQL_EQEMU_DATABASE}'"
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec mysql sh -c "mysql -h localhost -uroot -p${MYSQL_ROOT_PASSWORD} -e 'GRANT ALL PRIVILEGES ON ${MYSQL_EQEMU_DATABASE}.* TO \"${MYSQL_USERNAME}\"@\"%\"'"
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec mysql sh -c "mysql -h localhost -uroot -p${MYSQL_ROOT_PASSWORD} -e 'CREATE DATABASE IF NOT EXISTS ${MYSQL_SPIRE_DATABASE}';"
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec mysql sh -c "mysql -h localhost -uroot -p${MYSQL_ROOT_PASSWORD} -e 'GRANT ALL PRIVILEGES ON ${MYSQL_SPIRE_DATABASE}.* TO \"${MYSQL_USERNAME}\"@\"%\"'"
init-strip-mysql-remote-root: ##@mysql Strips MySQL remote root user
$(DRUNPREFIX) $(COMPOSE_COMMAND) exec mysql bash -c "mysql -uroot -p${MYSQL_ROOT_PASSWORD} -h localhost -e \"delete from mysql.user where User = 'root' and Host = '%'; FLUSH PRIVILEGES\""
#----------------------
# build
#----------------------
build-assets: ##@build Builds static assets before packing into binary
curl --compressed -o /tmp/assets.zip -L https://github.com/Akkadius/eq-asset-preview/archive/refs/heads/master.zip
unzip -qq -o /tmp/assets.zip -d /tmp/assets
cp -R /tmp/assets/eq-asset-preview-master/ ./frontend/public/
strip-extra-assets: ##@build Strips extra assets not needed to packet into binary
rm -rf frontend/public/eq-asset-preview-master/assets/npc_models
rm -rf frontend/public/eq-asset-preview-master/assets/objects
rm -rf frontend/public/eq-asset-preview-master/assets/item_icons
build-frontend: ##@build Builds frontend to be packed into binary
cd frontend && npm install && npm run build
build-binary: ##@build Build and packs release binary
packr clean
packr --compress
GOOS=linux GOARCH=amd64 go build -o spire-linux-amd64
go install github.com/tc-hib/go-winres@latest
go-winres make
GOOS=windows GOARCH=amd64 go build -o spire-windows-amd64.exe
zip spire-linux-amd64.zip spire-linux-amd64
zip spire-windows-amd64.exe.zip spire-windows-amd64.exe
release-binary: ##@build Releases binary
gh-release --assets=spire-linux-amd64.zip,spire-windows-amd64.exe.zip,eqemu-server-installer-linux-amd64,eqemu-server-installer-windows-amd64.exe -y
build-installer-binary: ##@build Builds installer binary
GOOS=linux GOARCH=amd64 go build -o eqemu-server-installer-linux-amd64 ./cmd/installer/
go install github.com/tc-hib/go-winres@latest
go-winres make --arch amd64 --in ./cmd/installer/winres.json --out ./cmd/installer/
mv cmd/installer/_windows_amd64.syso cmd/installer/rsrc_windows_amd64.syso
GOOS=windows GOARCH=amd64 go build -o eqemu-server-installer-windows-amd64.exe ./cmd/installer/