forked from ethyca/fidesops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
220 lines (177 loc) · 6.29 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
.DEFAULT_GOAL := help
####################
# CONSTANTS
####################
REGISTRY := ethyca
IMAGE_TAG := $(shell git fetch --force --tags && git describe --tags --dirty --always)
IMAGE_NAME := fidesops
IMAGE := $(REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)
IMAGE_LATEST := $(REGISTRY)/$(IMAGE_NAME):latest
DOCKERFILE_ENVIRONMENTS := postgres mysql mongodb mssql
####################
# Defaults
####################
.PHONY: help
help:
@echo "Under Construction, please read the Makefile directly!"
####################
# Dev
####################
init-db: compose-build
@echo "Check for new migrations to run..."
@docker-compose run --rm -e ANALYTICS_OPT_OUT $(IMAGE_NAME) \
python -c "\
from fidesops.db.database import init_db; \
from fidesops.core.config import config; \
init_db(config.database.SQLALCHEMY_DATABASE_URI);"
reset-db:
@echo "Resetting and re-initializing the application db..."
@make teardown
@docker volume rm fidesops_app-db-data || echo "No app DB found, continuing!"
@make init-db
server: compose-build
@docker-compose up
server-no-db: compose-build
@docker-compose -f docker-compose.no-db.yml up
server-shell: compose-build
@docker-compose run $(IMAGE_NAME) /bin/bash
integration-shell:
@virtualenv -p python3 fidesops_test_dispatch; \
source fidesops_test_dispatch/bin/activate; \
python run_infrastructure.py --open_shell --datastores $(datastores)
integration-env:
@virtualenv -p python3 fidesops_test_dispatch; \
source fidesops_test_dispatch/bin/activate; \
python run_infrastructure.py --run_application --datastores $(datastores)
quickstart:
@virtualenv -p python3 fidesops_test_dispatch; \
source fidesops_test_dispatch/bin/activate; \
python run_infrastructure.py --datastores mongodb postgres --run_quickstart
####################
# Docker
####################
docker-build:
docker build --tag $(IMAGE) .
docker-push:
docker tag $(IMAGE) $(IMAGE_LATEST)
docker push $(IMAGE)
docker push $(IMAGE_LATEST)
####################
# CI
####################
check-all: isort-ci black-ci pylint mypy check-migrations pytest pytest-integration
black-ci: compose-build
@echo "Running black checks..."
@docker-compose run \
-e ANALYTICS_OPT_OUT \
$(IMAGE_NAME) \
black --check src/ tests/ \
|| (echo "Error running 'black --check src/ tests/', please run 'make black' to format your code!"; exit 1)
@make teardown
check-migrations: compose-build
@echo "Check if there are unrun migrations..."
@docker-compose run --rm -e ANALYTICS_OPT_OUT $(IMAGE_NAME) \
python -c "\
from fidesops.db.database import check_missing_migrations; \
from fidesops.core.config import config; \
check_missing_migrations(config.database.SQLALCHEMY_DATABASE_URI);"
@make teardown
isort-ci:
@echo "Running isort checks..."
@docker-compose run $(IMAGE_NAME) \
isort src tests --check-only
pylint: compose-build
@echo "Running pylint checks..."
@docker-compose run \
-e ANALYTICS_OPT_OUT \
$(IMAGE_NAME) \
pylint src/
@make teardown
mypy: compose-build
@echo "Running mypy checks..."
@docker-compose run \
-e ANALYTICS_OPT_OUT \
$(IMAGE_NAME) \
mypy src/
@make teardown
pytest: compose-build
@echo "Running pytest unit tests..."
@docker-compose run \
-e ANALYTICS_OPT_OUT \
$(IMAGE_NAME) \
pytest $(pytestpath) -m "not integration and not integration_external and not integration_saas"
@make teardown
pytest-integration:
@virtualenv -p python3 fidesops_test_dispatch; \
source fidesops_test_dispatch/bin/activate; \
python run_infrastructure.py --run_tests --analytics_opt_out --datastores $(datastores)
@make teardown
# These tests connect to external third-party test databases
pytest-integration-external: compose-build
@echo "Running tests that connect to external third party test databases"
@docker-compose run \
-e ANALYTICS_OPT_OUT \
-e REDSHIFT_TEST_URI \
-e SNOWFLAKE_TEST_URI -e REDSHIFT_TEST_DB_SCHEMA \
-e BIGQUERY_KEYFILE_CREDS -e BIGQUERY_DATASET \
$(IMAGE_NAME) pytest $(pytestpath) -m "integration_external"
@make teardown
pytest-saas: compose-build
@echo "Running integration tests for SaaS connectors"
@docker-compose run \
-e ANALYTICS_OPT_OUT \
-e MAILCHIMP_DOMAIN -e MAILCHIMP_USERNAME -e MAILCHIMP_API_KEY -e MAILCHIMP_IDENTITY_EMAIL \
-e SENTRY_HOST -e SENTRY_ACCESS_TOKEN -e SENTRY_IDENTITY_EMAIL -e SENTRY_ERASURE_TOKEN -e SENTRY_ERASURE_IDENTITY -e SENTRY_USER_ID -e SENTRY_ISSUE_URL \
-e HUBSPOT_DOMAIN -e HUBSPOT_HAPIKEY -e HUBSPOT_IDENTITY_EMAIL \
-e SEGMENT_DOMAIN -e SEGMENT_PERSONAS_DOMAIN -e SEGMENT_WORKSPACE -e SEGMENT_ACCESS_TOKEN -e SEGMENT_API_DOMAIN -e SEGMENT_NAMESPACE_ID -e SEGMENT_ACCESS_SECRET -e SEGMENT_USER_TOKEN -e SEGMENT_IDENTITY_EMAIL \
-e STRIPE_HOST -e STRIPE_API_KEY -e STRIPE_PAYMENT_TYPES -e STRIPE_ITEMS_PER_PAGE -e STRIPE_IDENTITY_EMAIL \
$(IMAGE_NAME) pytest $(pytestpath) -m "integration_saas"
@make teardown
####################
# Utils
####################
.PHONY: black
black: compose-build
@echo "Running black formatting against the src/ and tests/ directories..."
@docker-compose run $(IMAGE_NAME) black src/ tests/
@make teardown
@echo "Fin"
.PHONY: clean
clean:
@echo "Cleaning project temporary files and installed dependencies..."
@docker system prune -a --volumes
@echo "Clean complete!"
.PHONY: compose-build
compose-build:
@echo "Tearing down the docker compose images, network, etc..."
@docker-compose down --remove-orphans
@docker-compose build --build-arg REQUIRE_MSSQL="true"
.PHONY: isort
isort:
@echo "Running isort checks..."
@docker-compose run $(IMAGE_NAME) \
isort src tests
.PHONY: teardown
teardown:
@echo "Tearing down the dev environment..."
@docker-compose down --remove-orphans
@echo "Teardown complete"
.PHONY: docs-build
docs-build: compose-build
@docker-compose run --rm $(IMAGE_NAME) \
python generate_openapi.py ./docs/fidesops/docs/api/openapi.json
.PHONY: docs-serve
docs-serve: docs-build
@docker-compose build docs
@docker-compose up docs
####################
# Test Data Creation
####################
user:
@virtualenv -p python3 fidesops_test_dispatch; \
source fidesops_test_dispatch/bin/activate; \
python run_infrastructure.py --datastores postgres --run_create_superuser
test-data:
@virtualenv -p python3 fidesops_test_dispatch; \
source fidesops_test_dispatch/bin/activate; \
python run_infrastructure.py --datastores postgres --run_create_test_data