This repository has been archived by the owner on Aug 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
276 lines (224 loc) · 8.59 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
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
PYTHON = $(shell which python)
TOPDIR = $(shell pwd)
PYDIR = masu
OC_SOURCE = registry.access.redhat.com/openshift3/ose
OC_VERSION = v3.9
OC_DATA_DIR = ${HOME}/.oc/openshift.local.data
PGSQL_VERSION = 9.6
OS := $(shell uname)
ifeq ($(OS),Darwin)
PREFIX =
else
PREFIX = sudo
endif
define HELP_TEXT=
Please use \`make <target>' where <target> is one of:
--- General Commands ---
clean clean the project directory of scratch files, bytecode, logs, etc.
help show this message
lint run linting against the project
--- Commands using local services ---
serve run the Flask dev server locally
test-db create database schemas and tables
unittest run unittests
--- Commands using Docker Compose ---
docker-up run flask, worker, and rabbit services
docker-down shut down service containers
docker-shell run django and db containers with shell access to server (for pdb)
docker-logs connect to console logs for all services
docker-test-all run unittests
docker-rabbit make the rabbit service
--- Commands using an OpenShift Cluster ---
oc-clean stop openshift cluster & remove local config data
oc-create-all run all application services in openshift cluster
oc-create-configmap create configmaps in openshift cluster
oc-create-db create a Postgres DB in an openshift cluster
oc-create-flower create the celery monitoring app in an openshift cluster
oc-create-masu create the masu app in an openshift cluster
oc-create-rabbitmq create a RabbitMQ broker in an openshift cluster
oc-create-secrets create secrets in openshift cluster
oc-create-tags create image stream tags
oc-create-worker create the celery worker in an openshift cluster
oc-create-listener create the masu listener in an openshift cluster
oc-delete-masu delete Openshift masu objects without a cluster restart
oc-delete-worker delete Openshift worker objects without a cluster restart
oc-delete-rabbit delete Openshift rabbitmq objects without a cluster restart
oc-delete-all delete Openshift objects without a cluster restart
oc-dev-db run Postgres in an openshift cluster
oc-down stop openshift cluster and all running apps
oc-forward-ports port forward the DB to localhost
oc-login-dev to login to an openshift cluster as 'developer'
oc-reinit remove existing app and restart app in openshift cluster
oc-serve run Flask server locally against an Openshift DB
oc-stop-forwarding-ports stop port forwarding the DB to localhost
oc-test-db create database schemas and tables
oc-up initialize an openshift cluster
oc-up-all initialize openshift cluster and run all application services
oc-up-db initialize openshift cluster and run Postgres
endef
export HELP_TEXT
help:
@echo "$$HELP_TEXT"
clean:
git clean -fdx -e .idea/ -e *env/
lint:
tox -elint
test-db:
$(TOPDIR)/tests/create_db.sh
unittest:
tox -e py36
serve:
FLASK_APP=masu \
FLASK_ENV=development \
MASU_SECRET_KEY='t@@ m4nY 53Cr3tZ' \
flask run
oc-clean: oc-down
$(PREFIX) rm -rf $(OC_DATA_DIR)
oc-create-all: oc-create-tags oc-create-configmap oc-create-secrets oc-create-db oc-create-rabbitmq oc-create-masu oc-create-worker oc-create-listener oc-create-scheduler oc-create-flower
oc-create-configmap:
oc get configmap/masu || \
oc process -f $(TOPDIR)/openshift/configmap.yaml \
--param-file=$(TOPDIR)/openshift/configmap.env \
| oc create -f -
oc-create-db:
oc get dc/koku-pgsql || \
oc process openshift//postgresql-persistent \
-p NAMESPACE=myproject \
-p POSTGRESQL_USER=kokuadmin \
-p POSTGRESQL_PASSWORD=admin123 \
-p POSTGRESQL_DATABASE=koku \
-p POSTGRESQL_VERSION=$(PGSQL_VERSION) \
-p DATABASE_SERVICE_NAME=koku-pgsql \
| oc create -f -
oc-create-flower: oc-create-configmap oc-create-secrets
oc get bc/masu-flower dc/masu-flower || \
oc process -f $(TOPDIR)/openshift/flower.yaml \
--param-file=$(TOPDIR)/openshift/flower.env \
-p SOURCE_REPOSITORY_REF=$(shell git rev-parse --abbrev-ref HEAD) \
| oc create -f -
oc-create-masu: oc-create-configmap oc-create-secrets
oc get bc/masu dc/masu || \
oc process -f $(TOPDIR)/openshift/masu.yaml \
--param-file=$(TOPDIR)/openshift/masu.env \
-p SOURCE_REPOSITORY_REF=$(shell git rev-parse --abbrev-ref HEAD) \
| oc create -f -
oc-create-rabbitmq:
oc get statefulsets/rabbitmq || \
oc process -f $(TOPDIR)/openshift/rabbitmq.yaml \
--param-file=$(TOPDIR)/openshift/rabbitmq.env \
-p SOURCE_REPOSITORY_REF=$(shell git rev-parse --abbrev-ref HEAD) \
| oc create -f -
oc-create-secrets:
oc get secret/masu || \
oc process -f $(TOPDIR)/openshift/secrets.yaml \
--param-file=$(TOPDIR)/openshift/secrets.env \
| oc create -f -
oc-create-tags:
oc get is/postgresql || \
oc create istag postgresql:$(PGSQL_VERSION) \
--from-image=centos/postgresql-96-centos7
oc get is/python-36-centos7 || \
oc create istag python-36-centos7:latest \
--from-image=centos/python-36-centos7
oc-create-worker: oc-create-configmap oc-create-secrets
oc get bc/masu-worker dc/masu-worker || \
oc process -f $(TOPDIR)/openshift/worker.yaml \
--param-file=$(TOPDIR)/openshift/worker.env \
-p SOURCE_REPOSITORY_REF=$(shell git rev-parse --abbrev-ref HEAD) \
| oc create -f -
oc-create-listener: oc-create-configmap oc-create-secrets
oc get bc/masu-listener dc/masu-listener || \
oc process -f $(TOPDIR)/openshift/listener.yaml \
--param-file=$(TOPDIR)/openshift/listener.env \
-p SOURCE_REPOSITORY_REF=$(shell git rev-parse --abbrev-ref HEAD) \
| oc create -f -
oc-create-scheduler: oc-create-configmap oc-create-secrets
oc get bc/masu-scheduler dc/masu-scheduler || \
oc process -f $(TOPDIR)/openshift/scheduler.yaml \
--param-file=$(TOPDIR)/openshift/scheduler.env \
-p SOURCE_REPOSITORY_REF=$(shell git rev-parse --abbrev-ref HEAD) \
| oc create -f -
oc-create-monitor: oc-create-configmap oc-create-secrets
oc get bc/masu-monitor dc/masu-monitor || \
oc process -f $(TOPDIR)/openshift/monitor.yaml \
--param-file=$(TOPDIR)/openshift/monitor.env \
-p SOURCE_REPOSITORY_REF=$(shell git rev-parse --abbrev-ref HEAD) \
| oc create -f -
oc-delete-scheduler:
oc delete deploymentconfigs/masu-scheduler \
buildconfigs/masu-scheduler \
imagestreams/masu-scheduler \
oc-delete-masu:
oc delete svc/masu \
route/masu \
buildconfigs/masu \
deploymentconfigs/masu \
imagestreams/masu \
oc-delete-worker:
oc delete deploymentconfigs/masu-worker \
buildconfigs/masu-worker \
imagestreams/masu-worker \
pvc/masu-worker-data \
oc-delete-listener:
oc delete deploymentconfigs/masu-listener \
buildconfigs/masu-listener \
imagestreams/masu-listener \
pvc/masu-listener-data \
oc-delete-rabbit:
oc delete svc/rabbitmq \
imagestreams/rabbitmq \
rolebinding/view \
statefulsets/rabbitmq \
buildconfigs/rabbitmq \
pvc/mnesia-rabbitmq-0 \
pvc/mnesia-rabbitmq-1 \
pvc/mnesia-rabbitmq-2 \
oc-delete-all:
oc delete is --all && \
oc delete dc --all && \
oc delete bc --all && \
oc delete svc --all && \
oc delete pvc --all && \
oc delete routes --all && \
oc delete statefulsets --all && \
oc delete configmap/masu \
secret/masu \
secret/koku-pgsql \
oc-dev-db: oc-create-tags oc-create-db
oc-down:
oc cluster down
oc-forward-ports:
-make oc-stop-forwarding-ports 2>/dev/null
oc port-forward $$(oc get pods -o jsonpath='{.items[*].metadata.name}' -l name=koku-pgsql) 15432:5432 >/dev/null 2>&1 &
oc port-forward rabbitmq-0 5672:5672 >/dev/null 2>&1 &
oc-login-dev:
oc login -u developer --insecure-skip-tls-verify=true localhost:8443
oc-reinit: oc-delete-all oc-create-all
oc-stop-forwarding-ports:
kill -HUP $$(ps -eo pid,command | grep "oc port-forward" | grep -v grep | awk '{print $$1}')
oc-serve: oc-forward-ports serve
oc-test-db: oc-forward-ports
sleep 1
$(TOPDIR)/tests/create_db.sh
make oc-stop-forwarding-ports
oc-up:
oc cluster up \
--image=$(OC_SOURCE) \
--version=$(OC_VERSION) \
--host-data-dir=$(OC_DATA_DIR) \
--use-existing-config=true
sleep 60
oc-up-all: oc-up oc-create-all
oc-up-db: oc-up oc-create-db
docker-up:
docker-compose up --build -d
docker-logs:
docker-compose logs -f
docker-shell:
docker-compose run --service-ports server
docker-test-all:
docker-compose -f masu-test.yml up --build
docker-down:
docker-compose down
docker-rabbit:
docker-compose up -d rabbit