-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMakefile
More file actions
217 lines (203 loc) · 12 KB
/
Makefile
File metadata and controls
217 lines (203 loc) · 12 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
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
#!/usr/bin/make -f
-include ./docker/.env
PWD = $(shell pwd)
DOCKER_USER = $(id -u)
DOCKER_COMPOSE = docker compose --project-directory=docker
PORT_admin = 8881
PORT_web = 8882
PORT_cli = 8883
RUN_ADMIN = php ${PWD}/elasticms-admin/bin/console --no-debug
RUN_CLI = php ${PWD}/elasticms-cli/bin/console --no-debug
RUN_WEB = php ${PWD}/elasticms-web/bin/console --no-debug
RUN_POSTGRES = docker compose --project-directory=docker exec -i -u ${DOCKER_USER}:0 -e PGUSER=postgres -e PGPASSWORD=adminpg postgres
NPM_CMD = "${NPM_EXTRA_CMD} npm $*"
RUN_DEMO_NPM = docker run -u ${DOCKER_USER}:0 --rm -it -v ${PWD}/demo:/opt/src --workdir /opt/src elasticms/base-php:8.4-cli-dev sh -c ${NPM_CMD}
RUN_ADMIN_UI_NPM = docker run -u ${DOCKER_USER}:0 --rm -p 5173:5173 -it -v ${PWD}/EMS/admin-ui-bundle:/opt/src --workdir /opt/src/assets elasticms/base-php:8.4-cli-dev sh -c ${NPM_CMD}
OTEL_ENABLED ?= false
.DEFAULT_GOAL := help
.PHONY: help demo docs
help: # Show help for each of the Makefile recipes.
@echo "EMS Monorepo"
@echo "---------------------------"
@echo "DOCKER_USER: ${DOCKER_USER}"
@echo "OTEL enabled: ${OTEL_ENABLED}"
@echo "NPM_EXTRA_CMD: ${NPM_EXTRA_CMD}"
@echo "ADMIN: http://localhost:8881"
@echo "WEB: http://localhost:8882"
@echo "KIBANA: http://kibana.localhost"
@echo "MINIO: http://minio.localhost"
@echo "MAIL: http://mailserver.localhost"
@echo "---------------------------"
@echo ""
@echo "Usage: make [target]"
@echo "Targets:"
@grep -E '(^\S*:.*?##.*$$)|(^##)' Makefile | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
## —— Mono —————————————————————————————————————————————————————————————————————————————————————————————————————————————
init: ## init mono repo (copy .env)
@cp -fp ./docker/.env.dist ./docker/.env
@cp -fp ./docker/sandbox.env.dist ./docker/sandbox.env
@cp -fp ./elasticms-admin/.env.dist ./elasticms-admin/.env
@cp -fp ./elasticms-admin/.env.local.dist ./elasticms-admin/.env.local
@cp -fp ./elasticms-web/.env.dist ./elasticms-web/.env
@cp -fp ./elasticms-web/.env.local.dist ./elasticms-web/.env.local
start: ## start docker, admin server, web server
@$(DOCKER_COMPOSE) --profile=ems up -d
@$(MAKE) -s server-start/admin
@$(MAKE) -s server-start/web
cd elasticms-admin && symfony local:run -d php bin/console messenger:consume async -vvv
start/%: ## start/(mariadb|keycloak|grafana|redis-commander)
@$(DOCKER_COMPOSE) --profile=${*} up -d --force-recreate
stop: ## stop docker, admin server, web server
@$(MAKE) -s server-stop/admin
@$(MAKE) -s server-stop/web
@$(DOCKER_COMPOSE) --profile=all down
stop/%: ## stop/(mariadb|keycloak|grafana|redis-commander)
@$(DOCKER_COMPOSE) --profile=${*} down
check: ## run all checks
@composer monorepo-validate
@composer rector
@composer phpall
@composer lint
@$(MAKE) build-translations
cache-clear: ## cache clear
@$(RUN_ADMIN) c:cl
@$(RUN_CLI) c:cl
@$(RUN_WEB) c:cl
status: ## status
@docker ps --filter="label=elasticMS" --format "table {{.Label \"com.docker.compose.service\"}}\t{{.Status}}\t{{.Ports}}"
pull: ## Pull service images
@$(DOCKER_COMPOSE) pull
sandbox: ## open a terminal in a development sandbox container
@$(DOCKER_COMPOSE) exec sandbox bash
## —— Symfony server ———————————————————————————————————————————————————————————————————————————————————————————————————
server-start/%: ## server-start/(admin|web|cli)
@if [ "$(OTEL_ENABLED)" = "true" ]; then \
env \
OTEL_PHP_AUTOLOAD_ENABLED=true \
OTEL_SERVICE_NAME=demo-ems-$(*) \
OTEL_TRACES_EXPORTER=otlp \
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \
OTEL_EXPORTER_OTLP_ENDPOINT=http://apm-server.localhost \
OTEL_RESOURCE_ATTRIBUTES=deployment.environment=dev \
OTEL_TRACES_SAMPLER=always_on \
OTEL_LOG_LEVEL=debug \
OTEL_PHP_LOG_DESTINATION=stderr \
OTEL_PHP_AUTOLOAD_PATH=$(MAKEFILE_DIR)/vendor/autoload.php \
symfony server:start --dir=elasticms-$* -d --port=$(PORT_$(*)) --no-tls --allow-all-ip; \
else \
symfony server:start --dir=elasticms-$* -d --port=$(PORT_$(*)) --no-tls --allow-all-ip; \
fi
server-stop/%: ## server-stop/(admin|web|cli)
symfony server:stop --dir=elasticms-${*}
server-log/%: ## server-log/(admin|web|cli)
symfony server:log --dir=elasticms-${*}
server-status/%: ## server-log/(admin|web|cli)
symfony server:status --dir=elasticms-${*}
server-restart: ## server-restart
@$(MAKE) -s server-stop/admin
@$(MAKE) -s server-stop/web
@$(MAKE) -s server-start/admin
@$(MAKE) -s server-start/web
cd elasticms-admin && symfony local:run -d php bin/console messenger:consume async -vvv
## —— Docker --------———————————————————————————————————————————————————————————————————————————————————————————————————
docker-images: ## List images
@docker ps --filter="label=elasticMS" --format "table {{.Label \"com.docker.compose.service\"}}\t{{.Image}}"
docker-logs: ## logs
@$(DOCKER_COMPOSE) logs -f
## —— assets ————————————————————————————————————————————————————————————————————————————————————————————————————————————
assets-npm/%: ## npm run in AdminUIBundle
@$(RUN_ADMIN_UI_NPM) $*
assets-install: ## Install NPM dependencies in AdminUIBundle assets
@$(MAKE) -s assets-npm/"install"
assets-build: ## build AdminUIBundle assets
@$(MAKE) -s assets-npm/"run build"
assets-clean: ## remove AdminUIBundle assets
rm -Rf EMS/admin-ui-bundle/public
assets-dev: ## Start an AdminUIBundle Vite server
@$(MAKE) -s assets-clean
@$(MAKE) -s assets-npm/"run dev-host"
## —— Doc ——————————————————————————————————————————————————————————————————————————————————————————————————————————————
docs: ## serve docs
npm run --prefix ./docs docs:dev
docs-build: ## build docs
npm run --prefix ./docs docs:build
docs-format: ## format docs
npm run --prefix ./docs docs:format
docs-lint: ## lint docs
npm run --prefix ./docs docs:lint
docs-init: ## init docs
npm install --prefix ./docs
## —— Build ————————————————————————————————————————————————————————————————————————————————————————————————————————————
build-translations: ## build translations
@php build/translations en EMSCoreBundle --write --format=yml -d emsco-core
@php build/translations en EMSAdminUIBundle --write --format=yml
## —— Database —————————————————————————————————————————————————————————————————————————————————————————————————————————
db-migrate: ## run doctrine migrations
@$(RUN_ADMIN) doctrine:migrations:migrate --no-interaction
db-load/%: ## make db-load/"db_example" DUMP=../../dumps.sql
@$(RUN_POSTGRES) psql -U ${*} < ${DUMP}
db-dump/%: ## db-dump/"db_example" SCHEMA="schema_example_adm"
@$(RUN_POSTGRES) pg_dump ${*} -w --clean -Fp -O --schema=${SCHEMA} | sed "/^\(DROP\|ALTER\|CREATE\) SCHEMA.*\$$/d" > dump_demo_$$(date +%Y%m%d%H%M%S).sql
db-drop/%: ## db-drop/"db_example"
@$(RUN_POSTGRES) psql -c "DROP DATABASE IF EXISTS ${*};"
@$(RUN_POSTGRES) psql -c "DROP USER IF EXISTS ${*};"
db-schema-rename/%: ## db-schema-rename/"db_example" FROM="schema_from" TO="schema_to"
@$(RUN_POSTGRES) psql -d ${*} -c "ALTER SCHEMA ${FROM} RENAME TO ${TO};"
@$(RUN_POSTGRES) psql -d ${*} -c "ALTER USER ${*} SET search_path TO ${TO};"
db-create/%: ## db-create/"db_example" SCHEMA="schema_example_adm"
@$(RUN_POSTGRES) psql -c "CREATE USER ${*} WITH ENCRYPTED PASSWORD '${*}';"
@$(RUN_POSTGRES) psql -c "CREATE DATABASE ${*} WITH OWNER ${*};"
@$(RUN_POSTGRES) psql -c "GRANT ALL PRIVILEGES ON DATABASE ${*} TO ${*};"
@$(RUN_POSTGRES) psql -d ${*} -c "ALTER SCHEMA public OWNER TO ${*};"
@$(RUN_POSTGRES) psql -d ${*} -c "ALTER SCHEMA public RENAME TO ${SCHEMA};"
@$(RUN_POSTGRES) psql -d ${*} -c "ALTER USER ${*} SET search_path TO ${SCHEMA};"
@$(RUN_POSTGRES) psql -d ${*} -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA ${SCHEMA} TO ${*};"
@echo 'DB_URL="pgsql://${*}:${*}@127.0.0.1:5432/${*}"'
db-create-mysql: ## create mysql database
@$(RUN_ADMIN) doctrine:database:drop --if-exists --force
@$(RUN_ADMIN) doctrine:database:create
@$(RUN_ADMIN) doctrine:migrations:migrate --no-interaction
## —— Demo —————————————————————————————————————————————————————————————————————————————————————————————————————————————
demo: ## make new demo
@$(MAKE) -s cache-clear
@$(MAKE) -s db-drop/"demo"
@$(MAKE) -s db-create/"demo" SCHEMA="schema_demo_adm"
@$(MAKE) -s db-migrate
@$(MAKE) -s assets-install
@$(MAKE) -s assets-build
@$(RUN_ADMIN) emsco:user:create demo demo@example.com demo --super-admin
@$(RUN_ADMIN) emsco:user:promote demo ROLE_API
@$(RUN_ADMIN) emsco:user:promote demo ROLE_FORM_CRM
@$(MAKE) -s demo-npm/"install"
@$(MAKE) -s demo-npm/"run build"
@$(RUN_ADMIN) assets:install --symlink
@$(RUN_WEB) assets:install --symlink
@ln -sf ${PWD}/demo/dist ${PWD}/elasticms-web/public/bundles/demo
@ln -sf ${PWD}/demo/dist ${PWD}/elasticms-admin/public/bundles/demo
@$(RUN_ADMIN) ems:admin:login --username=demo --password=demo
@$(RUN_ADMIN) ems:admin:restore --configs-folder=./demo/configs/admin --configs --force
@$(RUN_ADMIN) ems:contenttype:activate --all --force --no-debug
@$(RUN_ADMIN) ems:environment:rebuild --all --no-debug
@$(RUN_ADMIN) ems:managed-alias:add-environment ma_preview preview
@$(RUN_ADMIN) ems:managed-alias:add-environment ma_preview default
@$(RUN_ADMIN) ems:managed-alias:add-environment ma_live live
@$(RUN_ADMIN) ems:managed-alias:add-environment ma_live default
@$(RUN_ADMIN) emsco:user:add-group demo admins
@$(RUN_ADMIN) emsch:local:login demo demo
@$(RUN_ADMIN) emsch:local:push --force
@$(RUN_ADMIN) emsch:local:upload --filename=./demo/skeleton/template/asset_hash.twig
@$(RUN_ADMIN) emsch:local:folder-upload ./demo/configs/admin/assets
@$(RUN_ADMIN) ems:admin:restore --documents-folder=./demo/configs/document --documents --force
@$(RUN_ADMIN) ems:environment:align preview live --force --no-debug
@$(RUN_WEB) ems:admin:login --username=demo --password=demo
@$(RUN_WEB) ems:admin:webhooks:register http://localhost:8882/_admin_webhook content.finalize content.delete environment.new_index.preview
demo-backup-configs: ## backup demo configs
@$(RUN_WEB) c:c
@$(RUN_WEB) ems:admin:login --username=demo --password=demo
@$(RUN_WEB) ems:admin:backup --configs-folder=./demo/configs/admin --configs --export
demo-backup-documents: ## backup demo documents
@$(RUN_ADMIN) ems:admin:backup --documents-folder=./demo/configs/document --documents --export
demo-npm/%: ## demo npm
@$(RUN_DEMO_NPM) $*
demo-npm-watch: ## demo npm run watch
@$(MAKE) -s demo-npm/"run watch"