-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmakefile
More file actions
181 lines (149 loc) · 5.98 KB
/
Copy pathmakefile
File metadata and controls
181 lines (149 loc) · 5.98 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
DEV_COMPOSE = docker compose -f infra/development/docker-compose.yml
PROD_COMPOSE = docker compose -f infra/production/docker-compose.yml
SELF_MAKEFILE = $(firstword $(MAKEFILE_LIST))
define run_compose
$(1) $(2)
endef
# Development Commands
dev-build:
@echo "🏗️ Building development..."
$(call run_compose,$(DEV_COMPOSE),up -d db redis || true)
$(call run_compose,$(DEV_COMPOSE),build)
dev-up:
@echo "🚀 Starting development..."
$(call run_compose,$(DEV_COMPOSE),up -d db redis || true)
@sleep 3
@echo "⏳ Running migrations..."
$(call run_compose,$(DEV_COMPOSE),run --rm web python manage.py migrate)
$(call run_compose,$(DEV_COMPOSE),run --rm web python manage.py migrate django_celery_beat)
@echo "🚀 Starting all services..."
$(call run_compose,$(DEV_COMPOSE),up -d web bot celery_worker celery_beat)
@echo "✅ All services started!"
dev-down:
@echo "🛑 Stopping all services..."
$(call run_compose,$(DEV_COMPOSE),down)
dev-restart:
@echo "🔄 Restarting services..."
$(call run_compose,$(DEV_COMPOSE),restart web bot celery_worker celery_beat)
dev-makemigrations:
@echo "⚙️ Make migrations"
$(call run_compose,$(DEV_COMPOSE),exec web python manage.py makemigrations)
dev-migrate:
@echo "⚙️ Migrate"
$(call run_compose,$(DEV_COMPOSE),exec web python manage.py migrate)
dev-superuser:
@echo "👨💻 Create superuser"
$(call run_compose,$(DEV_COMPOSE),exec web python manage.py createsuperuser)
dev-logs:
@echo "📋 Showing logs..."
$(call run_compose,$(DEV_COMPOSE),logs -f web bot celery_worker celery_beat)
dev-logs-celery:
@echo "📋 Showing Celery logs only..."
$(call run_compose,$(DEV_COMPOSE),logs -f celery_worker celery_beat)
dev-status:
@echo "📊 Service status:"
$(call run_compose,$(DEV_COMPOSE),ps)
dev-shell:
@echo "🪄 Shell app:"
$(call run_compose,$(DEV_COMPOSE),exec web bash)
dev-celery-inspect:
@echo "🔍 Checking registered Celery tasks..."
$(call run_compose,$(DEV_COMPOSE),exec celery_worker celery -A src.settings.config.celery inspect registered)
dev-celery-purge:
@echo "🗑️ Purging all Celery tasks..."
$(call run_compose,$(DEV_COMPOSE),exec celery_worker celery -A src.settings.config.celery purge -f)
dev-redis-cli:
@echo "🪄 Shell redis:"
$(call run_compose,$(DEV_COMPOSE),exec redis redis-cli)
dev-db-shell:
@echo "🪄 Shell database:"
$(call run_compose,$(DEV_COMPOSE),exec db psql -U djangogram_user -d djangogram_db)
dev-clean:
@echo "🧹 Cleaning up..."
$(call run_compose,$(DEV_COMPOSE),down -v)
@echo "✅ Cleaned!"
# Production Commands
prod-build:
@echo "🏗️ Building production images..."
$(call run_compose,$(PROD_COMPOSE),build)
prod-up:
@echo "🚀 Starting production..."
$(call run_compose,$(PROD_COMPOSE),up -d db redis || true)
@sleep 3
@echo "⏳ Running migrations..."
$(call run_compose,$(PROD_COMPOSE),run --rm web python manage.py migrate)
$(call run_compose,$(PROD_COMPOSE),run --rm web python manage.py migrate django_celery_beat)
@echo "🚀 Starting all services..."
$(call run_compose,$(PROD_COMPOSE),up -d web bot celery_worker celery_beat)
@echo "✅ All services started!"
prod-down:
@echo "🛑 Stopping production..."
$(call run_compose,$(PROD_COMPOSE),down)
prod-restart:
@echo "🔄 Restarting production..."
$(call run_compose,$(PROD_COMPOSE),restart)
prod-logs:
@echo "📋 Showing production logs..."
$(call run_compose,$(PROD_COMPOSE),logs -f web bot celery_worker celery_beat)
prod-status:
@echo "📊 Production service status:"
$(call run_compose,$(PROD_COMPOSE),ps)
prod-shell:
@echo "🪄 Shell app:"
$(call run_compose,$(PROD_COMPOSE),exec web bash)
prod-update:
@echo "🔄 Zero-downtime update..."
$(call run_compose,$(PROD_COMPOSE),build)
$(call run_compose,$(PROD_COMPOSE),up -d --no-deps --force-recreate web)
@sleep 3
$(call run_compose,$(PROD_COMPOSE),exec web python manage.py migrate)
$(call run_compose,$(PROD_COMPOSE),up -d --no-deps --force-recreate bot celery_worker celery_beat)
$(call run_compose,$(PROD_COMPOSE),up -d --no-deps --force-recreate nginx)
docker image prune -f --filter "dangling=true"
@echo "✅ Production updated!"
prod-force-rebuild:
@echo "⚠️ FORCE REBUILD - This will cause downtime!"
@read -p "Are you sure? (yes/no): " confirm && [ "$$confirm" = "yes" ] || exit 1
$(call run_compose,$(PROD_COMPOSE),down)
docker image prune -af
$(call run_compose,$(PROD_COMPOSE),build --no-cache)
$(call run_compose,$(PROD_COMPOSE),up -d)
@sleep 5
$(call run_compose,$(PROD_COMPOSE),exec web python manage.py migrate)
@echo "✅ Force rebuild completed!"
prod-clean-images:
@echo "🧹 Cleaning unused Docker images..."
docker image prune -f
@echo "✅ Done!"
prod-clean-all:
@echo "⚠️ WARNING: This will delete all data (DB, Redis, etc.)"
@read -p "Are you sure? Type 'DELETE' to confirm: " confirm && [ "$$confirm" = "DELETE" ] || exit 1
$(call run_compose,$(PROD_COMPOSE),down -v)
docker image prune -af
@echo "✅ Everything cleaned!"
prod-memory:
@echo "💾 Docker memory usage:"
docker stats --no-stream
@echo "\n📦 Image sizes:"
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"
.PHONY: help
help:
@echo "Available commands:"
@echo ""
@echo "Development commands:"
@grep -E '^[a-zA-Z0-9_-]+:' $(SELF_MAKEFILE) | grep '^dev-' | while read cmd _; do \
desc=$$(grep -A1 "$$cmd" $(SELF_MAKEFILE) | tail -n1 | sed 's/^[ \t]*# //'); \
printf " %-25s %s\n" "$$cmd" "$$desc"; \
done
@echo ""
@echo "Production commands:"
@grep -E '^[a-zA-Z0-9_-]+:' $(SELF_MAKEFILE) | grep '^prod-' | while read cmd _; do \
desc=$$(grep -A1 "$$cmd" $(SELF_MAKEFILE) | tail -n1 | sed 's/^[ \t]*# //'); \
printf " %-25s %s\n" "$$cmd" "$$desc"; \
done
.PHONY: \
dev-build dev-up dev-down dev-restart dev-makemigrations dev-migrate \
dev-superuser dev-logs dev-logs-celery dev-status dev-shell dev-celery-inspect \
dev-celery-purge dev-redis-cli dev-db-shell dev-clean \
prod-build prod-up prod-down prod-restart prod-logs prod-status prod-shell \
prod-update prod-force-rebuild prod-clean-images prod-clean-all prod-memory