-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
264 lines (224 loc) · 8.47 KB
/
Copy pathMakefile
File metadata and controls
264 lines (224 loc) · 8.47 KB
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
# Krill Makefile
# Provides convenient commands for both local development and Docker containers
.PHONY: help build-dev build-test build-prod build-all test run-dev run-prod clean
.PHONY: server migrate makemigrations shell collectstatic createsuperuser
.PHONY: test-local test-docker security-check deploy-check push-prod
.PHONY: clean-whitespace lint
# Default target
help:
@echo "Krill Development Commands"
@echo "=========================="
@echo ""
@echo "Local Development Commands:"
@echo " server - Run Django development server"
@echo " migrate - Run database migrations"
@echo " makemigrations - Create new migrations"
@echo " shell - Open Django shell"
@echo " collectstatic - Collect static files"
@echo " createsuperuser - Create admin user"
@echo " dbshell - Open database shell"
@echo " showmigrations - Show migration status"
@echo " check - Run Django system checks"
@echo ""
@echo "Testing Commands:"
@echo " test-local - Run tests locally"
@echo " test-docker - Run tests in Docker container"
@echo " security-check - Run security validation"
@echo " test-data - Run anonymized data tests"
@echo " test-data-gen - Generate anonymized test data"
@echo " test-data-fixtures - Generate Django fixtures from test data"
@echo " test-data-all - Generate all test data and fixtures"
@echo " create-test-superuser - Create test superuser (admin/admin)"
@echo ""
@echo "Docker Commands:"
@echo " build-dev - Build development image"
@echo " build-test - Build testing image"
@echo " build-prod - Build production image"
@echo " build-all - Build all images"
@echo " push-prod - Push production image to DigitalOcean registry"
@echo " run-dev - Run development container"
@echo " run-prod - Run production container"
@echo " docker-shell - Access container shell"
@echo ""
@echo "Data Management:"
@echo " flush - Flush database"
@echo " loaddata - Load sample data"
@echo " load-testdata - Load anonymized test data"
@echo " setup - Setup development environment"
@echo " setup-test - Setup test environment with anonymized data"
@echo " reset - Reset development environment"
@echo " reset-test - Reset test environment with anonymized data"
@echo ""
@echo "Utility Commands:"
@echo " clean - Remove all krill images"
@echo " logs - Show container logs"
@echo " deploy-check - Run deployment checks"
@echo " clean-whitespace - Clean trailing whitespace and excessive blank lines"
@echo " lint - Run code linting and whitespace cleanup"
# Build commands
build-dev:
@echo "Building development image..."
./build.sh development
build-test:
@echo "Building testing image..."
./build.sh testing
build-prod:
@echo "Building production image..."
./build.sh production
build-all:
@echo "Building all images..."
./build.sh all
push-prod:
@echo "Pushing production image to DigitalOcean registry..."
./build.sh push
# Run commands
run-dev:
@echo "Running development container..."
docker run -p 8000:8000 krill:development
run-prod:
@echo "Running production container..."
@echo "Note: Set environment variables for database connection"
docker run -p 8000:8000 \
-e DJANGO_SECRET_KEY=your-secret-key \
-e DB_NAME=your_db_name \
-e DB_USER=your_db_user \
-e DB_PASSWORD=your_db_password \
-e DB_HOST=your_db_host \
-e REDIS_URL=redis://your_redis_host:6379/1 \
krill:production
# Local Development Commands
server:
@echo "Starting Django development server..."
cd krill && python manage.py runserver
migrate:
@echo "Running database migrations..."
cd krill && python manage.py migrate
makemigrations:
@echo "Creating new migrations..."
cd krill && python manage.py makemigrations
shell:
@echo "Opening Django shell..."
cd krill && python manage.py shell
collectstatic:
@echo "Collecting static files..."
cd krill && python manage.py collectstatic --noinput
createsuperuser:
@echo "Creating superuser..."
cd krill && python manage.py createsuperuser
# Testing Commands
test-local:
@echo "Running tests locally..."
cd krill && python manage.py test --verbosity=2
test-docker:
@echo "Building and running tests in Docker..."
./build.sh test
security-check:
@echo "Running security validation..."
cd krill && python run_security_check.py
# Anonymized Data Commands
test-data:
@echo "Running anonymized data tests..."
python tests/run_tests.py
test-data-gen:
@echo "Generating anonymized test data..."
@if [ ! -f "ln2_cane4_export.csv" ]; then \
echo "Error: Original data file 'ln2_cane4_export.csv' not found in project root."; \
echo "Please ensure the original data file is present before generating anonymized data."; \
echo "The anonymized data will not be regenerated."; \
exit 1; \
fi
cd tests/scripts && python anonymize_csv.py
test-data-fixtures:
@echo "Generating Django fixtures from anonymized data..."
cd tests/scripts && python convert_csv.py
create-test-superuser:
@echo "Creating test superuser..."
cd tests/scripts && python create_test_superuser.py
test-data-all:
@echo "Generating all test data and fixtures..."
@if [ ! -f "ln2_cane4_export.csv" ]; then \
echo "Error: Original data file 'ln2_cane4_export.csv' not found in project root."; \
echo "Please ensure the original data file is present before generating anonymized data."; \
exit 1; \
fi
@echo "Step 1: Generating anonymized data..."
cd tests/scripts && python anonymize_csv.py
@echo "Step 2: Generating Django fixtures..."
cd tests/scripts && python convert_csv.py
@echo "Step 3: Running verification tests..."
python tests/run_tests.py
@echo "All test data generation complete!"
# Docker Commands
test:
@echo "Building and running tests..."
./build.sh test
# Utility Commands
clean:
@echo "Removing all krill images..."
docker rmi krill:development krill:testing krill:production 2>/dev/null || true
logs:
@echo "Container logs (if running):"
docker logs $$(docker ps -q --filter ancestor=krill:development) 2>/dev/null || \
docker logs $$(docker ps -q --filter ancestor=krill:production) 2>/dev/null || \
echo "No krill containers running"
docker-shell:
@echo "Accessing container shell..."
@if [ "$$(docker ps -q --filter ancestor=krill:development)" ]; then \
docker exec -it $$(docker ps -q --filter ancestor=krill:development) /bin/bash; \
elif [ "$$(docker ps -q --filter ancestor=krill:production)" ]; then \
docker exec -it $$(docker ps -q --filter ancestor=krill:production) /bin/bash; \
else \
echo "No krill containers running. Start one first with 'make run-dev' or 'make run-prod'"; \
fi
deploy-check:
@echo "Running deployment checks..."
cd krill && python manage.py check --deploy
# Additional Development Commands
flush:
@echo "Flushing database..."
cd krill && python manage.py flush
loaddata:
@echo "Loading sample data..."
cd krill && python manage.py loaddata ../tests/fixtures/sample_fixtures.json
load-testdata:
@echo "Loading anonymized test data..."
cd krill && python manage.py loaddata ../tests/fixtures/sample_fixtures.json
dbshell:
@echo "Opening database shell..."
cd krill && python manage.py dbshell
showmigrations:
@echo "Showing migration status..."
cd krill && python manage.py showmigrations
check:
@echo "Running Django system checks..."
cd krill && python manage.py check
# Development Setup Commands
setup:
@echo "Setting up development environment..."
cd krill && python manage.py migrate
@echo "Development setup complete!"
setup-test:
@echo "Setting up test environment with anonymized data..."
cd krill && python manage.py migrate
cd krill && python manage.py loaddata ../tests/fixtures/sample_fixtures.json
cd tests/scripts && python create_test_superuser.py
@echo "Test environment setup complete!"
reset:
@echo "Resetting development environment..."
cd krill && python manage.py flush --noinput
cd krill && python manage.py loaddata ../tests/fixtures/sample_fixtures.json
@echo "Development environment reset complete!"
reset-test:
@echo "Resetting test environment with anonymized data..."
cd krill && python manage.py flush --noinput
cd krill && python manage.py loaddata ../tests/fixtures/sample_fixtures.json
cd tests/scripts && python create_test_superuser.py
@echo "Test environment reset complete!"
# Code Quality Commands
clean-whitespace:
@echo "Cleaning whitespace in all files..."
python3 scripts/clean_whitespace.py
lint:
@echo "Running code linting and whitespace cleanup..."
python3 scripts/clean_whitespace.py
@echo "Linting complete!"