-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
145 lines (117 loc) · 5.84 KB
/
Makefile
File metadata and controls
145 lines (117 loc) · 5.84 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
.PHONY: composer-install composer-require composer-dump up down build shell shell-root nginx-reload migrate-status migrate-create migrate-run migrate-rollback seed-run collect recents reset stats logs db-shell db-backup cache-flush fix-regions help
.DEFAULT_GOAL := help
# Set compose file based on ENV
ifeq ($(ENV),production)
DOCKER_COMPOSE = docker compose -f docker/docker-compose.production.yml --env-file=.env
else
DOCKER_COMPOSE = docker compose -f docker/docker-compose.yml --env-file=.env
endif
composer-install:
$(DOCKER_COMPOSE) run --rm --user $(shell id -u):$(shell id -g) phpfpm composer install
composer-require:
$(DOCKER_COMPOSE) run --rm --user $(shell id -u):$(shell id -g) phpfpm composer require $(PACKAGE)
composer-dump:
$(DOCKER_COMPOSE) run --rm --user $(shell id -u):$(shell id -g) phpfpm composer dump-autoload
up:
$(DOCKER_COMPOSE) up
down:
$(DOCKER_COMPOSE) down
build:
$(DOCKER_COMPOSE) build --no-cache
shell:
$(DOCKER_COMPOSE) exec --user $(shell id -u):$(shell id -g) phpfpm bash
shell-root:
$(DOCKER_COMPOSE) exec phpfpm bash
db-shell:
$(DOCKER_COMPOSE) exec postgres sh -c 'psql -U $$POSTGRES_USER -d $$POSTGRES_DB'
db-backup:
@echo "Creating database backup..."
@$(DOCKER_COMPOSE) exec phpfpm mkdir -p /u/apps/data/backups
@$(DOCKER_COMPOSE) exec postgres sh -c 'pg_dump -U $$POSTGRES_USER -d $$POSTGRES_DB' | $(DOCKER_COMPOSE) exec -T phpfpm sh -c 'cat > /u/apps/data/backups/backup_$$(date +%Y%m%d_%H%M%S).sql'
@echo "Backup saved to storage/backups/"
# Nginx commands
nginx-reload:
@echo "Reloading nginx configuration..."
@$(DOCKER_COMPOSE) exec nginx nginx -s reload
@echo "Nginx configuration reloaded successfully"
# Database Migration Commands
migrate-status:
$(DOCKER_COMPOSE) run --rm --user $(shell id -u):$(shell id -g) phpfpm vendor/bin/phinx status
migrate-create:
$(DOCKER_COMPOSE) run --rm --user $(shell id -u):$(shell id -g) phpfpm vendor/bin/phinx create $(NAME)
migrate-run:
$(DOCKER_COMPOSE) run --rm --user $(shell id -u):$(shell id -g) phpfpm vendor/bin/phinx migrate
migrate-rollback:
$(DOCKER_COMPOSE) run --rm --user $(shell id -u):$(shell id -g) phpfpm vendor/bin/phinx rollback
seed-run:
$(DOCKER_COMPOSE) run --rm --user $(shell id -u):$(shell id -g) phpfpm vendor/bin/phinx seed:run
collect:
$(DOCKER_COMPOSE) run --rm --user $(shell id -u):$(shell id -g) phpfpm php bin/collect.php $(filter-out $@,$(MAKECMDGOALS))
recents:
$(DOCKER_COMPOSE) run --rm --user $(shell id -u):$(shell id -g) phpfpm php bin/recents.php $(filter-out $@,$(MAKECMDGOALS))
stats:
$(DOCKER_COMPOSE) run --rm --user $(shell id -u):$(shell id -g) phpfpm php bin/stats.php
fix-regions:
$(DOCKER_COMPOSE) run --rm --user $(shell id -u):$(shell id -g) phpfpm php bin/fix-regions.php $(filter-out $@,$(MAKECMDGOALS))
logs:
$(DOCKER_COMPOSE) exec phpfpm sh -c 'tail -f /u/apps/data/logs/*.log'
cache-flush:
@echo "Flushing Redis cache..."
@$(DOCKER_COMPOSE) exec redis redis-cli FLUSHALL
@echo "Redis cache flushed!"
reset:
@echo "Resetting database (rollback all + migrate + seed)..."
$(DOCKER_COMPOSE) run --rm --user $(shell id -u):$(shell id -g) phpfpm vendor/bin/phinx rollback -t 0
$(DOCKER_COMPOSE) run --rm --user $(shell id -u):$(shell id -g) phpfpm vendor/bin/phinx migrate
$(DOCKER_COMPOSE) run --rm --user $(shell id -u):$(shell id -g) phpfpm vendor/bin/phinx seed:run
@echo "Database reset complete!"
# Handle extra arguments for collect command
%:
@:
help:
@echo "Available commands:"
@echo ""
@echo "Usage:"
@echo " Development: make up"
@echo " Production: ENV=production make up"
@echo ""
@echo "Docker Management:"
@echo " up - Start the Docker containers"
@echo " down - Stop the Docker containers"
@echo " build - Build the Docker images"
@echo " shell - Open a bash shell in the PHP container"
@echo " shell-root - Open a bash shell in the PHP container as root"
@echo " nginx-reload - Reload nginx configuration"
@echo " logs - Follow application logs (tail -f)"
@echo ""
@echo "Composer Management:"
@echo " composer-install - Install PHP dependencies via Composer"
@echo " composer-require - Add a new package (use: make composer-require PACKAGE=package-name)"
@echo " composer-dump - Regenerate Composer autoloader"
@echo ""
@echo "Database Management:"
@echo " db-shell - Connect to PostgreSQL database"
@echo " db-backup - Create a database backup (saves to storage/backups/)"
@echo " migrate-status - Check migration status"
@echo " migrate-create - Create a new migration (use: make migrate-create NAME=MigrationName)"
@echo " migrate-run - Run pending migrations"
@echo " migrate-rollback - Rollback the last migration"
@echo " seed-run - Run database seeders"
@echo " reset - Reset database (rollback all + migrate + seed)"
@echo ""
@echo "Event Collection:"
@echo " collect - Collect events from all sources"
@echo " Examples: make collect (today)"
@echo " make collect 2024-01-01 (single day)"
@echo " make collect 2024-01-01 2024-01-31 (date range)"
@echo " make collect 2024-01-01 2024-01-31 5 (5-day chunks)"
@echo ""
@echo "Data Analysis & Maintenance:"
@echo " recents - Show recent events (use: make recents 10)"
@echo " stats - Show database statistics"
@echo " fix-regions - Fix NOAA region IDs (add +10000 to IDs < 9000)"
@echo " Dry run: make fix-regions"
@echo " Apply: make fix-regions apply"
@echo ""
@echo "Cache Management:"
@echo " cache-flush - Flush Redis cache"