-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathMakefile
122 lines (96 loc) · 3.69 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
# Use bash or file wildcards won't work
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.ONESHELL:
.DELETE_ON_ERROR:
.DEFAULT_GOAL := prepare
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
DB_CONTAINER=rmap-mysql
HOST_UID=$(shell id -u)
HOST_GID=$(shell id -g)
DOCKER_IMAGE_NAME = quay.io/reconmap/rest-api
DOCKER_DEFAULT_TAG = $(DOCKER_IMAGE_NAME)
ifdef TRAVIS_BRANCH
GIT_BRANCH_NAME = $(TRAVIS_BRANCH)
else
GIT_BRANCH_NAME = $(shell git rev-parse --abbrev-ref HEAD)
endif
define composer_install
echo
echo Running composer install on $(1)
docker-compose run --rm --user reconmapper -w $(1) --entrypoint composer api install
endef
.PHONY: prepare-config
prepare-config:
[ -f config.json ] || cp config-template.json config.json
.PHONY: prepare-dirs
prepare-dirs:
mkdir -p vendor logs data-mysql data-redis
.SILENT: install-deps
.PHONY: install-deps
install-deps:
$(call composer_install, /var/www/webapp)
$(call composer_install, /var/www/webapp/packages/command-parsers-lib)
.PHONY: prepare
prepare: prepare-config prepare-dirs build install-deps
.PHONY: build
build:
docker-compose build --no-cache --build-arg HOST_UID=$(HOST_UID) --build-arg HOST_GID=$(HOST_GID)
.PHONY: tests
tests: start validate
docker-compose run --rm -e WAIT_HOSTS=$(DB_CONTAINER):3306 -e WAIT_TIMEOUT=60 --entrypoint /usr/local/bin/wait waiter
echo Importing SQL files: $(wildcard database/0*.sql)
cat tests/database.sql | docker container exec -i $(DB_CONTAINER) mysql -uroot -preconmuppet
cat database/0*.sql | sed "s/USE reconmap;/USE reconmap_test;/" | docker container exec -i $(DB_CONTAINER) mysql -uroot -preconmuppet reconmap_test
docker-compose run --rm -w /var/www/webapp --entrypoint php api src/Cli/app.php test:generate-data --use-test-database
docker-compose run --rm -w /var/www/webapp -e CURRENT_PLANET=Moon --entrypoint ./run-tests.sh api
docker container exec -i $(DB_CONTAINER) mysql -uroot -preconmuppet -e "DROP DATABASE reconmap_test"
.PHONY: security-tests
security-tests:
docker-compose run --rm -w /var/www/webapp --entrypoint bash api -c "wget https://github.com/fabpot/local-php-security-checker/releases/download/v2.0.5/local-php-security-checker_2.0.5_linux_amd64 -O security-checker && chmod +x security-checker && ./security-checker"
.PHONY: start
start: prepare-config prepare-dirs
docker-compose up -d
.PHONY: validate
validate:
docker-compose run --rm -w /var/www/webapp --entrypoint composer api validate --strict
.PHONY: stop
stop:
docker-compose stop
.PHONY: clean
clean: stop
docker-compose down -v --remove-orphans
docker-compose rm
rm -rf {data-mysql,data-redis}
.PHONY: api-shell
api-shell:
@docker-compose exec -u reconmapper -w /var/www/webapp api bash
.PHONY: api-rootshell
api-rootshell:
@docker-compose exec -u root -w /var/www/webapp api bash
.PHONY: cache-clear
cache-clear:
git clean -fdx data/cache
.PHONY: push
push:
docker tag $(DOCKER_IMAGE_NAME):latest $(DOCKER_IMAGE_NAME):$(GIT_BRANCH_NAME)
docker push $(DOCKER_IMAGE_NAME):$(GIT_BRANCH_NAME)
docker push $(DOCKER_IMAGE_NAME):latest
docker-compose push mysql
# Database targets
.PHONY: db-shell
db-shell:
@docker-compose exec mysql mysql --silent -uroot -preconmuppet reconmap
.PHONY: db-reset
db-reset:
cat database/{01,02}*.sql | docker container exec -i $(DB_CONTAINER) mysql -uroot -preconmuppet reconmap
.PHONY: db-import
db-import:
cat database/{01,02,03}*.sql | docker container exec -i $(DB_CONTAINER) mysql -uroot -preconmuppet reconmap
.PHONY: db-migrate
db-migrate:
cat database/migrations/changes$(MIGRATE_FROM_VERSION)-$(MIGRATE_TO_VERSION).sql | docker container exec -i $(DB_CONTAINER) mysql -uroot -preconmuppet reconmap
.PHONY: redis-shell
redis-shell:
@docker-compose exec redis redis-cli