-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakefile
111 lines (85 loc) · 3.94 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
# set user to "root" to run commands as root in docker
USER=$$(whoami)
# The docker command to execute commands directly in docker
DOCKER=docker-compose exec -T -w /app --user="$(USER)" backend-php
# The PHP binary to use, you may add arguments to PHP here
PHP=php
# directories writeable by webserver
WRITEABLE_DIRS=/app/runtime /app/logs /app/backend/web/assets
TESTCASE=
COMMAND=
# default target lists general usage information
default:
@echo "The following commands are available:"
@echo ""
@echo " make start start PHP built-in webserver"
@echo " make stop stop PHP built-in webserver"
@echo " make start-docker start docker environment"
@echo " make stop-docker stop docker environment"
@echo " make cli run bash in docker environment"
@echo " make bash alias for 'make cli'"
@echo " make lint Run OpenAPI linter"
.PHONY: start stop start-docker stop-docker clean test bash cli lint lint-php lint-js
## PHP runtime ##
# start PHP built-in webserver
start: config/components-dev.local.php backend/config/cookie-validation.key env.php
@echo "Starting server for api"
cd api && $(MAKE) start
@echo "Starting server for backend"
cd backend && $(MAKE) start
# stop PHP built-in webserver
stop:
cd api && $(MAKE) stop
cd backend && $(MAKE) stop
## Docker Runtime ##
# run bash inside docker container
bash: cli
cli:
docker-compose exec --user="$(USER)" backend-php bash
run:
$(DOCKER) sh -c '$(COMMAND)'
start-docker: docker-compose.override.yml runtime/build-docker config/components-dev.local.php backend/config/cookie-validation.key env.php stop
docker-compose up -d
docker-compose exec -T backend-php bash -c "grep '^$(shell whoami):' /etc/passwd || useradd -m '$(shell whoami)' --uid=$(shell id -u) -G www-data -s /bin/bash -d /app/runtime/home"
docker-compose exec -T backend-php bash -c "sed -i 's/#force_color_prompt=yes/force_color_prompt=yes/' /app/runtime/home/.bashrc && sed -i 's~etc/bash_completion~etc/bash_completion.d/yii~' /app/runtime/home/.bashrc"
docker-compose exec -T backend-php bash -c "chgrp -R www-data $(WRITEABLE_DIRS) && chmod -R g+w $(WRITEABLE_DIRS)"
$(DOCKER) sh -c 'cd /app && composer install --no-progress --no-interaction --ansi'
@echo ""
@echo "API: http://localhost:8337/"
# @echo "API docs: http://localhost:8337/docs/index.html" # not yet :)
@echo "Backend: http://localhost:8338/"
@echo "Mailcatcher: http://localhost:8055/"
@echo ""
stop-docker:
docker-compose down
runtime/build-docker: */Dockerfile
docker-compose build
touch $@
# copy config files if they do not exist
config/components-%.local.php: config/components-ENV.local.php
test -f $@ || cp $< $@
env.php: env.php.dist
test -f $@ || cp $< $@
docker-compose.override.yml: docker-compose.override.dist.yml
test -f $@ || cp $< $@
backend/config/cookie-validation.key:
test -s $@ || php -r 'echo bin2hex(random_bytes(20));' > $@
# Lint API spec
lint: lint-php lint-js
lint-php:
$(DOCKER) ./vendor/bin/php-openapi validate openapi/schema.yaml
lint-js: node_modules/.bin/spectral
docker-compose run -T --no-deps --rm --user="$$(id -u)" -e FORCE_COLOR=1 -w /app nodejs ./node_modules/.bin/spectral lint openapi/schema.yaml -f stylish --ruleset .spectral.yml
node_modules/.bin/spectral: package.json
docker-compose run -T --no-deps --rm --user="$$(id -u)" -e FORCE_COLOR=1 -w /app nodejs npm install
## Docker Runtime Tests ##
test: tests/_data/dump.sql
$(DOCKER) vendor/bin/codecept run $(TESTCASE)
clean:
rm -rf tests/_data/dump.sql
# generate database dump for test env
tests/_data/dump.sql: $(shell find common/migrations -type f)
$(DOCKER) sh -c 'YII_ENV=test ./yii migrate/fresh --interactive=0'
$(DOCKER) sh -c 'mysqldump -h db-test -uapi_test -papisecret api_db_test > tests/_data/dump.sql'
# for postgres you may use this command instead:
#$(DOCKER) sh -c 'PGPASSWORD=apisecret pg_dump --schema-only --clean --if-exists -w -h db-test -U api_test -d api_db_test -f tests/_data/dump.sql'