-
Notifications
You must be signed in to change notification settings - Fork 60
/
Makefile
332 lines (258 loc) · 10.4 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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
PYTHON = $(shell which python)
TOPDIR = $(shell pwd)
PYDIR = rbac
OC_SOURCE = registry.access.redhat.com/openshift3/ose
OC_VERSION = v3.9
OC_DATA_DIR = ${HOME}/.oc/openshift.local.data
PGSQL_VERSION = 14.5
PORT=8000
APP_HOME=$(shell pwd)/$(PYDIR)
APP_MODULE=rbac.wsgi
APP_CONFIG=$(TOPDIR)/$(PYDIR)/gunicorn.py
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 any scratch files, bytecode, logs, etc.
help show this message
html create html documentation for the project
lint run linting against the project
format format linting errors found by lint task
typecheck run type check
--- Commands using local services ---
create-test-db-file create a Postgres DB dump file for RBAC
collect-static collect static files to host
make-migrations make migrations for the database
reinitdb drop and recreate the database
requirements generate Pipfile.lock and requirements
run-migrations run migrations against database
serve run the Django server locally
serve-with-oc run Django server locally against an Openshift DB
start-db start the psql db in detached state
stop-compose stop all containers
unittest run unittests
user create a Django super user
--- Commands using Docker Compose ---
docker-up run django and database
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-grype Run security checks on the project image(s)
--- Commands using an Ephemeral Cluster ---
ephemeral-build build and deploy a docker image based on local repo
ephemeral-deploy deploy RBAC app to ephemeral cluster
ephemeral-pods list all RBAC specific pods
ephemeral-pf-rbac port forward RBAC server to localhost (local default port: 9080)
ephemeral-reserve reserve a namespace from the ephemeral cluster (Example to override HOURS, HOURS="12h")
ephemeral-release release the currently reserved namespace
--- 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-db create a Postgres DB in an initialized openshift cluster
oc-create-rbac create the RBAC app in an initialized openshift cluster
oc-create-tags create image stream tags
oc-create-test-db-file create a Postgres DB dump file for RBAC
oc-delete-all delete Openshift objects without a cluster restart
oc-down stop app & openshift cluster
oc-forward-ports port forward the DB to localhost
oc-login-dev login to an openshift cluster as 'developer'
oc-reinit remove existing app and restart app in initialized openshift cluster
oc-run-migrations run Django migrations in the Openshift DB
oc-stop-forwarding-ports stop port forwarding the DB to localhost
oc-up initialize an openshift cluster
oc-up-all run app in openshift cluster
oc-up-db run Postgres in an openshift cluster
endef
export HELP_TEXT
help:
@echo "$$HELP_TEXT"
clean:
git clean -fdx -e .idea/ -e *env/
html:
@cd docs; $(MAKE) html
lint:
tox -elint
format:
black -t py39 -l 119 rbac tests
typecheck:
mypy --install-types --non-interactive rbac
reinitdb:
make start-db
make reset-db
make run-migrations
reset-db:
docker-compose exec -u postgres db dropdb postgres
docker-compose exec -u postgres db createdb -Eutf8 -Ttemplate0 -Opostgres postgres
make-migrations:
DJANGO_READ_DOT_ENV_FILE=True $(PYTHON) $(PYDIR)/manage.py makemigrations api management
run-migrations:
DJANGO_READ_DOT_ENV_FILE=True $(PYTHON) $(PYDIR)/manage.py migrate
shell:
DJANGO_READ_DOT_ENV_FILE=True $(PYTHON) $(PYDIR)/manage.py shell
seeds:
DJANGO_READ_DOT_ENV_FILE=True $(PYTHON) $(PYDIR)/manage.py seeds
show-migrations:
DJANGO_READ_DOT_ENV_FILE=True $(PYTHON) $(PYDIR)/manage.py showmigrations api management
urls:
DJANGO_READ_DOT_ENV_FILE=True $(PYTHON) $(PYDIR)/manage.py show_urls
create-test-db-file: run-migrations
sleep 1
DJANGO_READ_DOT_ENV_FILE=True $(PYTHON) $(PYDIR)/manage.py runserver > /dev/null 2>&1 &
sleep 5
$(PYTHON) $(TOPDIR)/scripts/create_test_customer.py --bypass-api
pg_dump -d $(DATABASE_NAME) -h $(POSTGRES_SQL_SERVICE_HOST) -p $(POSTGRES_SQL_SERVICE_PORT) -U $(DATABASE_USER) > test.sql
kill -HUP $$(ps -eo pid,command | grep "manage.py runserver" | grep -v grep | awk '{print $$1}')
collect-static:
$(PYTHON) $(PYDIR)/manage.py collectstatic --no-input
requirements:
pipenv lock
pipenv requirements > requirements.txt
serve:
DJANGO_READ_DOT_ENV_FILE=True $(PYTHON) $(PYDIR)/manage.py runserver $(PORT)
gunicorn-serve:
DJANGO_READ_DOT_ENV_FILE=True gunicorn "$(APP_MODULE)" --chdir=$(APP_HOME) --bind=0.0.0.0:8080 --access-logfile=- --config "$(APP_CONFIG)" --preload
serve-with-oc: oc-forward-ports
sleep 3
DJANGO_READ_DOT_ENV_FILE=True $(PYTHON) $(PYDIR)/manage.py runserver
make oc-stop-forwarding-ports
start-db:
docker-compose up -d db
stop-compose:
docker-compose down
unittest:
$(PYTHON) $(PYDIR)/manage.py test $(PYDIR) -v 2
user:
$(PYTHON) $(PYDIR)/manage.py createsuperuser
oc-clean: oc-down
$(PREFIX) rm -rf $(OC_DATA_DIR)
oc-create-tags:
oc get istag postgresql:$(PGSQL_VERSION) || oc create istag postgresql:$(PGSQL_VERSION) --from-image=centos/postgresql-96-centos7
oc-create-db:
oc process openshift//postgresql-persistent \
-p NAMESPACE=myproject \
-p POSTGRESQL_USER=rbacadmin \
-p POSTGRESQL_PASSWORD=admin123 \
-p POSTGRESQL_DATABASE=rbac \
-p POSTGRESQL_VERSION=$(PGSQL_VERSION) \
-p DATABASE_SERVICE_NAME=rbac-pgsql \
| oc create -f -
oc-create-all: oc-create-tags oc-create-rbac oc-create-redis oc-create-worker oc-create-scheduler
oc-create-rbac:
openshift/init-app.sh -n myproject -b `git rev-parse --abbrev-ref HEAD`
oc-create-worker:
oc get bc/rbac-worker dc/rbac-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-scheduler:
oc get bc/rbac-scheduler dc/rbac-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-redis:
oc get bc/rbac-redis dc/rbac-redis || \
oc process -f $(TOPDIR)/openshift/redis.yaml \
--param-file=$(TOPDIR)/openshift/redis.env \
-p SOURCE_REPOSITORY_REF=$(shell git rev-parse --abbrev-ref HEAD) \
| oc create -f -
oc-create-test-db-file: oc-run-migrations
sleep 1
make oc-forward-ports
sleep 1
DJANGO_READ_DOT_ENV_FILE=True $(PYTHON) $(PYDIR)/manage.py runserver > /dev/null 2>&1 &
sleep 5
$(PYTHON) $(TOPDIR)/scripts/create_test_customer.py --bypass-api
pg_dump -d $(DATABASE_NAME) -h $(POSTGRES_SQL_SERVICE_HOST) -p $(POSTGRES_SQL_SERVICE_PORT) -U $(DATABASE_USER) > test.sql
kill -HUP $$(ps -eo pid,command | grep "manage.py runserver" | grep -v grep | awk '{print $$1}')
make oc-stop-forwarding-ports
oc-delete-scheduler:
oc delete deploymentconfigs/rbac-scheduler \
buildconfigs/rbac-scheduler \
imagestreams/rbac-scheduler \
oc-delete-worker:
oc delete deploymentconfigs/rbac-worker \
buildconfigs/rbac-worker \
imagestreams/rbac-worker \
oc-delete-redis:
oc delete deploymentconfigs/rbac-redis \
buildconfigs/rbac-redis \
imagestreams/rbac-redis \
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/rbac-env \
secret/rbac-secret \
secret/rbac-pgsql \
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=rbac-pgsql) 15432:5432 >/dev/null 2>&1 &
oc-login-dev:
oc login -u developer --insecure-skip-tls-verify=true localhost:8443
oc-make-migrations: oc-forward-ports
sleep 3
DJANGO_READ_DOT_ENV_FILE=True $(PYTHON) $(PYDIR)/manage.py makemigrations api management
make oc-stop-forwarding-ports
oc-reinit: oc-delete-all oc-create-rbac
oc-run-migrations: oc-forward-ports
sleep 3
DJANGO_READ_DOT_ENV_FILE=True $(PYTHON) $(PYDIR)/manage.py migrate
make oc-stop-forwarding-ports
oc-stop-forwarding-ports:
kill -HUP $$(ps -eo pid,command | grep "oc port-forward" | grep -v grep | awk '{print $$1}')
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-rbac
oc-up-db: oc-up oc-create-db
docker-grype:
@docker-compose build >/dev/null 2>&1
@echo ""
@docker run --rm \
--volume /var/run/docker.sock:/var/run/docker.sock \
--name Grype anchore/grype:latest \
$$(docker images --format '{{.Repository}}' |grep rbac-server) --only-fixed
docker-up:
@docker network ls --format '{{.Name}}' |grep -q rbac-network > /dev/null 2>&1 && echo "" || docker network create rbac-network
docker-compose up --build -d
docker-logs:
docker-compose logs -f
docker-shell:
docker-compose run --service-ports server
docker-down:
@docker ps --format '{{.Names}}' |grep -q rbac >/dev/null 2>&1 && docker-compose down || echo ""
@docker network ls --format '{{.Name}}' |grep -q rbac-network > /dev/null 2>&1 && \docker network rm rbac-network > /dev/null 2>&1 || echo ""
ephemeral-build:
./scripts/ephemeral/ephemeral.sh build
ephemeral-deploy:
./scripts/ephemeral/ephemeral.sh deploy
ephemeral-pods:
./scripts/ephemeral/ephemeral.sh pods
RBAC_LOCAL_PORT = "9080"
ephemeral-pf-rbac:
./scripts/ephemeral/ephemeral.sh pf-rbac ${RBAC_LOCAL_PORT}
HOURS = "24h"
ephemeral-reserve:
./scripts/ephemeral/ephemeral.sh reserve ${HOURS}
ephemeral-release:
./scripts/ephemeral/ephemeral.sh release
generate_v2_spec:
cd docs/source/specs/typespec/ && ./compile_tsp_spec
.PHONY: docs