forked from ruflin/Elastica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
183 lines (147 loc) · 5 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
#/bin/bash
SOURCE = "./lib"
TARGET?=70
# By default docker environment is used to run commands. To run without the predefined environment, set RUN_ENV=" " either as parameter or as environment variable
ifndef RUN_ENV
RUN_ENV = docker run --workdir="/elastica" -v $(shell pwd):/elastica ruflin/elastica-dev-base
endif
.PHONY: clean
clean:
rm -r -f ./build
rm -r -f ./vendor
rm -r -f ./composer.lock
# Runs commands inside virtual environemnt. Example usage inside docker: make run RUN="make phpunit"
.PHONY: run
run:
docker run -v $(shell pwd):/elastica ruflin/elastica $(RUN)
### Quality checks / development tools ###
.PHONY: code-browser
code-browser:
${RUN_ENV} phpcb --log ./build/logs --source ${SOURCE} --output ./build/code-browser
# Copy paste detector
.PHONY: cpd
cpd:
${RUN_ENV} phpcpd --log-pmd ./build/logs/pmd-cpd.xml ${SOURCE}
.PHONY: messdetector
messdetector:
${RUN_ENV} phpmd ${SOURCE} text codesize,unusedcode,naming,design ./build/phpmd.xml
.PHONY: messdetector-ci
messdetector-ci:
${RUN_ENV} phpmd ${SOURCE} xml codesize,unusedcode,naming,design --reportfile ./build/logs/pmd.xml
.PHONY: dependencies
dependencies:
${RUN_ENV} pdepend --jdepend-xml=./build/logs/jdepend.xml \
--jdepend-chart=./build/pdepend/dependencies.svg \
--overview-pyramid=./build/pdepend/overview-pyramid.svg \
${SOURCE}
.PHONY: phpunit
phpunit:
EXIT_STATUS=0 ; \
phpunit -c test/ --coverage-clover build/coverage/unit-coverage.xml --group unit || EXIT_STATUS=$$? ; \
phpunit -c test/ --coverage-clover build/coverage/functional-coverage.xml --group functional || EXIT_STATUS=$$? ; \
phpunit -c test/ --coverage-clover build/coverage/shutdown-coverage.xml --group shutdown || EXIT_STATUS=$$? ; \
exit $$EXIT_STATUS
.PHONY: tests
tests:
# Rebuild image to copy changes files to the image
make elastica-image
make setup
mkdir -p build
docker-compose run elastica make phpunit
docker cp elastica_elastica_run_1:/elastica/build/coverage/ $(shell pwd)/build/coverage
# Makes it easy to run a single test file. Example to run IndexTest.php: make test TEST="IndexTest.php"
.PHONY: test
test:
make elastica-image
make setup
mkdir -p build
docker-compose run elastica phpunit -c test/ ${TEST}
.PHONY: doc
doc:
${RUN_ENV} phpdoc run -d lib/ -t build/docs
# Uses the preconfigured standards in .php_cs
.PHONY: lint
lint:
${RUN_ENV} php-cs-fixer fix
.PHONY: loc
loc:
${RUN_ENV} cloc --by-file --xml --exclude-dir=build -out=build/cloc.xml .
.PHONY: phploc
phploc:
${RUN_ENV} phploc --log-csv ./build/logs/phploc.csv ${SOURCE}
# VIRTUAL ENVIRONMENT
.PHONY: build
build:
docker-compose build
.PHONY: setup
setup: build
docker-compose scale elasticsearch=3
# TODO: Makes the snapshot directory writable for all instances. Nicer solution needed.
docker-compose run elasticsearch chmod -R 777 /tmp/backups/
.PHONY: start
start:
docker-compose up
.PHONY: stop
stop:
docker-compose stop
.PHONY: destroy
destroy: clean
docker-compose kill
docker-compose rm
# Stops and removes all containers and removes all images
.PHONY: destroy-environment
destroy-environment:
make remove-containers
-docker rmi $(shell docker images -q)
.PHONY: remove-containers
remove-containers:
-docker stop $(shell docker ps -a -q)
-docker rm -v $(shell docker ps -a -q)
# Starts a shell inside the elastica image
.PHONY: shell
shell:
docker run -v $(shell pwd):/elastica -ti ruflin/elastica /bin/bash
# Starts a shell inside the elastica image with the full environment running
.PHONY: env-shell
env-shell:
docker-compose run elastica /bin/bash
# Visualise repo
.PHONY: gource
gource:
gource --log-format git \
--seconds-per-day 0.1 \
--title 'Elastica (https://github.com/ruflin/Elastica)' \
--user-scale 1 \
--max-user-speed 50
## DOCKER IMAGES
.PHONY: elastica-image
elastica-image:
docker build -t ruflin/elastica-dev-base -f env/elastica/Docker${TARGET} env/elastica/
docker build -t ruflin/elastica .
# Builds all image locally. This can be used to use local images if changes are made locally to the Dockerfiles
.PHONY: build-images
build-images:
docker build -t ruflin/elastica-dev-base -f env/elastica/Docker${TARGET} env/elastica/
docker build -t ruflin/elasticsearch-elastica env/elasticsearch/
docker build -t ruflin/nginx-elastica env/nginx/
docker build -t ruflin/elastica-data env/data/
make elastica-image
# Removes all local images
.PHONY: clean-images
clean-images:
-docker rmi ruflin/elastica-dev-base
-docker rmi ruflin/elasticsearch-elastica
-docker rmi ruflin/nginx-elastica
-docker rmi ruflin/elastica
-docker rmi ruflin/elastica-data
# Pushs images as latest to the docker registry. This is normally not needed as they are directly fetched and built from Github
.PHONY: push-images
push-images: build-images
docker push ruflin/elastica-dev-base
docker push ruflin/elasticsearch-elastica
docker push ruflin/nginx-elastica
docker push ruflin/elastica
## OTHER
# google-setup:
# docker-machine create --driver google --google-project elastica-1024 --google-machine-type n1-standard-8 elastica
# eval "$(docker-machine env elastica)"