forked from cloudfoundry/app-autoscaler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
139 lines (124 loc) · 4.62 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
SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c ${SHELLFLAGS}
MVN_OPTS="-Dmaven.test.skip=true"
OS:=$(shell . /etc/lsb-release &>/dev/null && echo $${DISTRIB_ID} || uname )
db_type:=postgres
DBURL := $(shell case "${db_type}" in\
(postgres) printf "postgres://postgres:postgres@localhost/autoscaler?sslmode=disable"; ;; \
(mysql) printf "root@tcp(localhost)/autoscaler?tls=false"; ;; esac)
CI?=false
$(shell mkdir -p target)
.PHONY: check-type
check-db_type:
@case "${db_type}" in\
(mysql|postgres) echo "Using bd:${db_type}"; ;;\
(*) echo "ERROR: db_type needs to be one of mysql|postgres"; exit 1;;\
esac
.PHONY: init-db
init-db: check-db_type start-db build-db target/init-db-${db_type}
target/init-db-${db_type}:
@./scripts/initialise_db.sh ${db_type}
@touch $@
.PHONY: init
init: target/init
target/init:
@make -C src/autoscaler buildtools
@touch $@
.PHONY: clean
clean:
@make stop-db db_type=mysql
@make stop-db db_type=postgres
@mvn clean > /dev/null
@make -C src/autoscaler clean
@rm target/* &> /dev/null || echo "# Already clean"
.PHONY: build-db
build-db: target/build-db
target/build-db:
@mvn --no-transfer-progress package -pl db ${MVN_OPTS}
@touch $@
.PHONY: scheduler
scheduler: init
@mvn --no-transfer-progress package -pl scheduler ${MVN_OPTS}
.PHONY: autoscaler
autoscaler: init
@make -C src/autoscaler build
.PHONY: test-certs
test-certs: target/autoscaler_test_certs target/scheduler_test_certs
target/autoscaler_test_certs:
@./scripts/generate_test_certs.sh
@touch $@
target/scheduler_test_certs:
@./scheduler/scripts/generate_unit_test_certs.sh
@touch $@
.PHONY: test test-autoscaler test-scheduler
test: test-autoscaler test-scheduler
test-autoscaler: check-db_type init init-db test-certs
@echo " - using DBURL=${DBURL}"
@make -C src/autoscaler test DBURL="${DBURL}"
test-scheduler: check-db_type init init-db test-certs
@mvn test --no-transfer-progress -Dspring.profiles.include=${db_type}
.PHONY: start-db
start-db: check-db_type target/start-db-${db_type}_CI_${CI} waitfor_${db_type}_CI_${CI}
@echo " SUCCESS"
.PHONY: waitfor_postgres_CI_false waitfor_postgres_CI_true
target/start-db-postgres_CI_false:
@if [ ! "$(shell docker ps -q -f name="^${db_type}")" ]; then \
if [ "$(shell docker ps -aq -f status=exited -f name="^${db_type}")" ]; then \
docker rm ${db_type}; \
fi;\
echo " - starting docker for ${db_type}";\
docker run -p 5432:5432 --name postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_USER=postgres \
-e POSTGRES_DB=autoscaler \
--health-cmd pg_isready \
--health-interval 1s \
--health-timeout 2s \
--health-retries 10 \
-d \
postgres:9.6 >/dev/null;\
else echo " - $@ already up'"; fi;
@touch $@
target/start-db-postgres_CI_true:
@echo " - $@ already up'"
waitfor_postgres_CI_false:
@echo -n " - waiting for ${db_type} ."
@until docker exec postgres pg_isready &>/dev/null ; do echo -n "."; sleep 1; done
waitfor_postgres_CI_true:
@echo " - no ci postgres checks"
.PHONY: waitfor_mysql_CI_false waitfor_mysql_CI_true
target/start-db-mysql_CI_false:
@if [ ! "$(shell docker ps -q -f name="^${db_type}")" ]; then \
if [ "$(shell docker ps -aq -f status=exited -f name="^${db_type}")" ]; then \
docker rm ${db_type}; \
fi;\
echo " - starting docker for ${db_type}";\
docker run -p 3306:3306 --name mysql \
-e MYSQL_ALLOW_EMPTY_PASSWORD=true \
-e MYSQL_DATABASE=autoscaler \
-d \
mysql:latest \
>/dev/null;\
else echo " - $@ already up"; fi;
@touch $@
target/start-db-mysql_CI_true:
@echo " - $@ already up'"
waitfor_mysql_CI_false:
@echo -n " - waiting for ${db_type} ."
@until docker exec mysql mysqladmin ping &>/dev/null ; do echo -n "."; sleep 1; done
@echo " SUCCESS"
@echo -n " - Waiting for table creation ."
@until [[ ! -z `docker exec mysql mysql -qfsBe "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='autoscaler'" 2> /dev/null` ]]; do echo -n "."; sleep 1; done
waitfor_mysql_CI_true:
@echo -n " - Waiting for table creation ."
@which mysql >/dev/null && until [[ ! -z $(shell mysql -u "root" -h `hostname` --port=3306 -qfsBe "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='autoscaler'" 2> /dev/null) ]]; do echo -n "."; sleep 1; done
.PHONY: stop-db
stop-db: check-db_type
@echo " - Stopping ${db_type}"
@rm target/start-db-${db_type} &> /dev/null || echo " - Seems the make target was deleted stopping anyway!"
@docker rm -f ${db_type} &> /dev/null || echo " - we could not stop and remove docker named '${db_type}'"
.PHONY: build
build: init init-db test-certs scheduler autoscaler
.PHONY: integration
integration: build
make -C src/autoscaler integration DBURL="${DBURL}"