-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
298 lines (255 loc) · 8.83 KB
/
Copy pathMakefile
File metadata and controls
298 lines (255 loc) · 8.83 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
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
# PolicyGraph Makefile
# Common development commands and shortcuts
.PHONY: help install test lint format clean docker-up docker-down docker-logs docker-shell docs-build docs-serve backup
# Default target
help:
@echo "PolicyGraph Development Commands"
@echo "================================"
@echo ""
@echo "Development:"
@echo " install Install Python dependencies with Poetry"
@echo " install-dev Install Python dependencies (including dev)"
@echo " install-docs Install documentation dependencies"
@echo " test Run tests"
@echo " lint Run linting and code quality checks"
@echo " format Format code with black and isort"
@echo " clean Clean up temporary files and caches"
@echo ""
@echo "Poetry:"
@echo " poetry-add Add new dependency"
@echo " poetry-add-dev Add new development dependency"
@echo " poetry-update Update dependencies"
@echo " poetry-lock Lock dependencies"
@echo " poetry-show Show dependency tree"
@echo ""
@echo "Docker:"
@echo " docker-up Start all services with docker-compose"
@echo " docker-down Stop all services"
@echo " docker-logs View logs from all services"
@echo " docker-shell Open shell in app container"
@echo " docker-build Build all Docker images"
@echo " docker-pull Pull latest Docker images"
@echo ""
@echo "Documentation:"
@echo " docs-install Install documentation dependencies"
@echo " docs-build Build documentation"
@echo " docs-serve Serve documentation locally"
@echo " docs-clean Clean documentation build artifacts"
@echo ""
@echo "Backup:"
@echo " backup-app Create application backup"
@echo " backup-neo4j Create Neo4j backup"
@echo " backup-all Create all backups"
@echo ""
@echo "Utilities:"
@echo " health-check Check system health"
@echo " logs View recent logs"
@echo " status Show service status"
# Development commands
install:
@echo "Installing Python dependencies with Poetry..."
poetry install
@echo "Dependencies installed successfully!"
install-dev:
@echo "Installing Python dependencies with Poetry (including dev dependencies)..."
poetry install --with dev
@echo "Development dependencies installed successfully!"
install-docs:
@echo "Installing documentation dependencies with Poetry..."
cd docs && poetry install
@echo "Documentation dependencies installed successfully!"
poetry-add:
@echo "Adding new dependency with Poetry..."
@read -p "Enter package name: " package; \
poetry add $$package
poetry-add-dev:
@echo "Adding new development dependency with Poetry..."
@read -p "Enter package name: " package; \
poetry add --group dev $$package
poetry-update:
@echo "Updating dependencies with Poetry..."
poetry update
poetry-lock:
@echo "Locking dependencies with Poetry..."
poetry lock
poetry-show:
@echo "Showing dependency tree..."
poetry show --tree
test:
@echo "Running tests..."
poetry run pytest app/ -v --cov=app --cov-report=term-missing
lint:
@echo "Running linting checks..."
poetry run flake8 app/ --max-line-length=88 --extend-ignore=E203,W503
poetry run black --check --diff app/
poetry run isort --check-only --diff app/
poetry run mypy app/ --ignore-missing-imports --no-strict-optional
format:
@echo "Formatting code..."
poetry run black app/
poetry run isort app/
@echo "Code formatted successfully!"
clean:
@echo "Cleaning up temporary files..."
find . -type d -name "__pycache__" -exec rm -rf {} +
find . -type f -name "*.pyc" -delete
find . -type f -name "*.pyo" -delete
find . -type f -name "*.pyd" -delete
find . -type f -name ".coverage" -delete
find . -type d -name "*.egg-info" -exec rm -rf {} +
find . -type d -name ".pytest_cache" -exec rm -rf {} +
find . -type d -name ".tox" -exec rm -rf {} +
find . -type d -name "htmlcov" -exec rm -rf {} +
@echo "Cleanup completed!"
# Docker commands
docker-up:
@echo "Starting PolicyGraph services..."
docker-compose up -d
@echo "Services started! Use 'make docker-logs' to view logs."
docker-down:
@echo "Stopping PolicyGraph services..."
docker-compose down
@echo "Services stopped!"
docker-logs:
@echo "Viewing logs from all services..."
docker-compose logs -f
docker-shell:
@echo "Opening shell in app container..."
docker-compose exec app /bin/bash
docker-build:
@echo "Building Docker images..."
docker-compose build
@echo "Images built successfully!"
docker-pull:
@echo "Pulling latest Docker images..."
docker-compose pull
@echo "Images pulled successfully!"
# Documentation commands
docs-install:
@echo "Installing documentation dependencies..."
cd docs && poetry install
@echo "Documentation dependencies installed!"
docs-build:
@echo "Building documentation..."
cd docs && make html
@echo "Documentation built successfully!"
docs-serve:
@echo "Serving documentation locally..."
cd docs && make serve
@echo "Documentation available at http://localhost:8080"
docs-clean:
@echo "Cleaning documentation build artifacts..."
cd docs && make clean
@echo "Documentation cleaned!"
# Backup commands
backup-app:
@echo "Creating application backup..."
./infra/backup/backup_app.sh
@echo "Application backup completed!"
backup-neo4j:
@echo "Creating Neo4j backup..."
./infra/backup/backup_neo4j.sh
@echo "Neo4j backup completed!"
backup-all: backup-app backup-neo4j
@echo "All backups completed!"
# Utility commands
health-check:
@echo "Checking system health..."
@curl -f http://localhost:8000/health || echo "Health check failed!"
@docker-compose ps
logs:
@echo "Recent logs from all services..."
docker-compose logs --tail=100
status:
@echo "Service status:"
docker-compose ps
@echo ""
@echo "Resource usage:"
docker stats --no-stream
# Environment setup
setup-dev:
@echo "Setting up development environment..."
@if [ ! -f .env.local ]; then \
echo "Creating .env.local from .env.example..."; \
cp .env.example .env.local; \
echo "Please edit .env.local with your development settings"; \
else \
echo ".env.local already exists"; \
fi
@echo "Development environment setup completed!"
setup-staging:
@echo "Setting up staging environment..."
@if [ ! -f .env.staging ]; then \
echo "Creating .env.staging from .env.production..."; \
cp .env.production .env.staging; \
echo "Please edit .env.staging with your staging settings"; \
else \
echo ".env.staging already exists"; \
fi
@echo "Staging environment setup completed!"
# CI/CD commands
ci-lint:
@echo "Running CI linting checks..."
poetry run black --check --diff app/
poetry run isort --check-only --diff app/
poetry run flake8 app/ --max-line-length=88 --extend-ignore=E203,W503
ci-test:
@echo "Running CI tests..."
poetry run pytest app/ --cov=app --cov-report=xml --cov-report=term-missing
ci-security:
@echo "Running security checks..."
poetry run bandit -r app/ -f json -o bandit-report.json || true
poetry run safety check --json --output safety-report.json || true
ci-all: ci-lint ci-test ci-security
@echo "All CI checks completed!"
# Production commands
deploy-staging:
@echo "Deploying to staging environment..."
docker-compose --env-file .env.staging up -d
@echo "Staging deployment completed!"
deploy-production:
@echo "Deploying to production environment..."
@echo "WARNING: This will deploy to production!"
@read -p "Are you sure? [y/N] " -n 1 -r; \
if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
docker-compose --env-file .env.production up -d; \
echo "Production deployment completed!"; \
else \
echo "Production deployment cancelled."; \
fi
# Monitoring commands
monitor:
@echo "Starting system monitoring..."
@echo "Press Ctrl+C to stop monitoring"
@watch -n 5 'docker-compose ps && echo "" && docker stats --no-stream'
# Database commands
db-shell:
@echo "Opening Neo4j Cypher shell..."
docker-compose exec neo4j cypher-shell -u neo4j -p $$NEO4J_PASSWORD
db-backup:
@echo "Creating Neo4j backup..."
docker-compose exec neo4j neo4j-admin backup --database=neo4j --backup-dir=/backups --name=manual_backup_$$(date +%Y%m%d_%H%M%S)
db-restore:
@echo "Restoring Neo4j from backup..."
@echo "WARNING: This will overwrite current data!"
@read -p "Are you sure? [y/N] " -n 1 -r; \
if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
echo "Please specify backup file:"; \
read backup_file; \
docker-compose exec neo4j neo4j-admin restore --from=/backups/$$backup_file --database=neo4j; \
echo "Database restored successfully!"; \
else \
echo "Database restore cancelled."; \
fi
# Quick start for new developers
quickstart: setup-dev install docker-up
@echo ""
@echo "🎉 PolicyGraph development environment is ready!"
@echo ""
@echo "Next steps:"
@echo "1. Edit .env.local with your settings"
@echo "2. Visit http://localhost:8000/docs for API documentation"
@echo "3. Visit http://localhost:7474 for Neo4j browser"
@echo "4. Use 'make help' to see available commands"
@echo ""
@echo "Happy coding! 🚀"