1+ # StreamSource Makefile
2+ # Development shortcuts for Docker Compose commands
3+ # All commands run inside Docker containers - no local Ruby/Rails required
4+
5+ .PHONY : help dev up down restart logs shell console test spec lint rubocop migrate seed reset rebuild clean yarn assets routes
6+
7+ # Default target - show help
8+ help :
9+ @echo " StreamSource Development Commands:"
10+ @echo " "
11+ @echo " Core Commands:"
12+ @echo " make dev - Start all services with asset watchers"
13+ @echo " make up - Start core services only (no asset watchers)"
14+ @echo " make down - Stop all services"
15+ @echo " make restart - Restart all services"
16+ @echo " make logs - Show logs (follow mode)"
17+ @echo " make status - Show container status"
18+ @echo " "
19+ @echo " Development:"
20+ @echo " make shell - Open bash shell in web container"
21+ @echo " make console - Open Rails console"
22+ @echo " make routes - Show Rails routes"
23+ @echo " make attach - Attach to web container (for pry debugging)"
24+ @echo " "
25+ @echo " Testing:"
26+ @echo " make test - Run full test suite (RSpec)"
27+ @echo " make spec - Run specific test (use file=path/to/spec.rb)"
28+ @echo " make coverage - Open test coverage report"
29+ @echo " "
30+ @echo " Database:"
31+ @echo " make migrate - Run database migrations"
32+ @echo " make rollback - Rollback last migration"
33+ @echo " make seed - Seed the database"
34+ @echo " make reset - Reset database (drop, create, migrate, seed)"
35+ @echo " make db-console - Open PostgreSQL console"
36+ @echo " "
37+ @echo " Code Quality:"
38+ @echo " make lint - Run RuboCop linter"
39+ @echo " make lint-fix - Auto-fix RuboCop issues"
40+ @echo " make security - Run Brakeman security analysis"
41+ @echo " "
42+ @echo " Assets:"
43+ @echo " make assets - Build all assets (JS and CSS)"
44+ @echo " make watch-js - Watch and rebuild JavaScript"
45+ @echo " make watch-css - Watch and rebuild CSS"
46+ @echo " "
47+ @echo " Maintenance:"
48+ @echo " make rebuild - Complete rebuild (clean + build + migrate + seed)"
49+ @echo " make clean - Remove containers, volumes, and orphans"
50+ @echo " make install - Install/update dependencies"
51+
52+ # Core Commands
53+ # Start development environment with asset watchers
54+ dev :
55+ docker compose --profile assets up -d
56+ @echo " StreamSource is running!"
57+ @echo " - API: http://localhost:3000"
58+ @echo " - Admin: http://localhost:3000/admin"
59+ @echo " - API Docs: http://localhost:3000/api-docs"
60+
61+ # Start core services only (no asset watchers)
62+ up :
63+ docker compose up -d
64+ @echo " StreamSource core services are running (no asset watchers)"
65+
66+ # Stop all services
67+ down :
68+ docker compose down
69+
70+ # Restart all services
71+ restart : down dev
72+
73+ # Show logs in follow mode
74+ logs :
75+ docker compose logs -f web
76+
77+ # Show container status
78+ status :
79+ docker compose ps
80+
81+ # Development Tools
82+ # Open bash shell in web container
83+ shell :
84+ docker compose exec web bash
85+
86+ # Open Rails console
87+ console :
88+ docker compose exec web bin/rails console
89+
90+ # Show Rails routes
91+ routes :
92+ docker compose exec web bin/rails routes
93+
94+ # Attach to web container (for pry debugging)
95+ attach :
96+ docker attach $$(docker compose ps -q web )
97+
98+ # Testing
99+ # Run full test suite using RSpec
100+ test :
101+ docker compose exec web bin/test
102+
103+ # Run specific test file
104+ spec :
105+ @if [ -z " $( file) " ]; then \
106+ echo " Usage: make spec file=spec/models/stream_spec.rb" ; \
107+ echo " or: make spec file=spec/models/stream_spec.rb:42" ; \
108+ else \
109+ docker compose exec web bin/test $(file ) ; \
110+ fi
111+
112+ # Open test coverage report
113+ coverage :
114+ @echo " Opening coverage report..."
115+ @open coverage/index.html 2> /dev/null || xdg-open coverage/index.html 2> /dev/null || echo " Coverage report at: coverage/index.html"
116+
117+ # Database Management
118+ # Run database migrations
119+ migrate :
120+ docker compose exec web bin/rails db:migrate
121+
122+ # Rollback last migration
123+ rollback :
124+ docker compose exec web bin/rails db:rollback
125+
126+ # Seed the database
127+ seed :
128+ docker compose exec web bin/rails db:seed
129+
130+ # Reset database (drop, create, migrate, seed)
131+ reset :
132+ docker compose exec web bin/rails db:reset
133+
134+ # Open PostgreSQL console
135+ db-console :
136+ docker compose exec db psql -U streamsource
137+
138+ # Code Quality
139+ # Run RuboCop linter
140+ lint :
141+ docker compose exec web bin/rubocop
142+
143+ # Auto-fix RuboCop issues
144+ lint-fix :
145+ docker compose exec web bundle exec rubocop -A
146+
147+ # Run Brakeman security analysis
148+ security :
149+ docker compose exec web bin/brakeman
150+
151+ # Asset Management
152+ # Build all assets (JavaScript and CSS)
153+ assets :
154+ docker compose exec web yarn build
155+ docker compose exec web yarn build:css
156+
157+ # Watch and rebuild JavaScript
158+ watch-js :
159+ docker compose exec web yarn build --watch
160+
161+ # Watch and rebuild CSS
162+ watch-css :
163+ docker compose exec web yarn build:css --watch
164+
165+ # Maintenance
166+ # Complete rebuild - equivalent to dcnuke alias
167+ rebuild :
168+ docker compose stop
169+ docker compose down -v --remove-orphans
170+ docker compose up -d
171+ docker compose run --rm web yarn build
172+ docker compose run --rm web yarn build:css
173+ docker compose exec web bin/rails db:prepare
174+ docker compose logs -f web
175+
176+ # Clean up everything (containers, volumes, orphans)
177+ clean :
178+ docker compose down -v --remove-orphans
179+
180+ # Install/update dependencies
181+ install :
182+ docker compose exec web bundle install
183+ docker compose exec web yarn install
184+
185+ # Additional Commands
186+ .PHONY : redis-cli cache-clear db-prepare generate setup
187+
188+ # Access Redis CLI
189+ redis-cli :
190+ docker compose exec redis redis-cli
191+
192+ # Clear Rails cache
193+ cache-clear :
194+ docker compose exec web bin/rails cache:clear
195+
196+ # Prepare database (create if needed, migrate, seed)
197+ db-prepare :
198+ docker compose exec web bin/rails db:prepare
199+
200+ # Rails generators
201+ generate :
202+ @if [ -z " $( what) " ]; then \
203+ echo " Usage: make generate what='model Stream title:string'" ; \
204+ echo " or: make generate what='controller Api::V1::Streams'" ; \
205+ echo " or: make generate what='migration AddIndexToStreams'" ; \
206+ else \
207+ docker compose exec web bin/rails generate $(what ) ; \
208+ fi
209+
210+ # Initial setup for new developers
211+ setup :
212+ @echo " Setting up StreamSource development environment..."
213+ docker compose build
214+ docker compose up -d
215+ docker compose exec web bin/rails db:prepare
216+ @echo " "
217+ @echo " Setup complete! StreamSource is running at:"
218+ @echo " - API: http://localhost:3000"
219+ @echo
" - Admin: http://localhost:3000/admin ([email protected] / Password123!)" 220+ @echo " - API Docs: http://localhost:3000/api-docs"
221+
222+ # Utility Commands
223+ .PHONY : exec run yarn bundle
224+
225+ # Execute command in web container
226+ exec :
227+ @if [ -z " $( cmd) " ]; then \
228+ echo " Usage: make exec cmd='ls -la'" ; \
229+ else \
230+ docker compose exec web $(cmd ) ; \
231+ fi
232+
233+ # Run command in new web container
234+ run :
235+ @if [ -z " $( cmd) " ]; then \
236+ echo " Usage: make run cmd='rake db:version'" ; \
237+ else \
238+ docker compose run --rm web $(cmd ) ; \
239+ fi
240+
241+ # Run yarn commands
242+ yarn :
243+ @if [ -z " $( cmd) " ]; then \
244+ echo " Usage: make yarn cmd='add lodash'" ; \
245+ else \
246+ docker compose exec web yarn $(cmd ) ; \
247+ fi
248+
249+ # Run bundle commands
250+ bundle :
251+ @if [ -z " $( cmd) " ]; then \
252+ echo " Usage: make bundle cmd='add rspec-rails'" ; \
253+ else \
254+ docker compose exec web bundle $(cmd ) ; \
255+ fi
256+
257+ # Troubleshooting
258+ .PHONY : logs-all logs-web logs-db ps-all health
259+
260+ # Show logs for all services
261+ logs-all :
262+ docker compose logs -f
263+
264+ # Show only web logs
265+ logs-web :
266+ docker compose logs -f web
267+
268+ # Show only database logs
269+ logs-db :
270+ docker compose logs -f db
271+
272+ # Show all containers (including stopped)
273+ ps-all :
274+ docker compose ps -a
275+
276+ # Health check
277+ health :
278+ @echo " Checking StreamSource health..."
279+ @docker compose ps
280+ @echo " "
281+ @echo " Rails status:"
282+ @docker compose exec web bin/rails runner " puts 'Rails: OK'"
283+ @echo " "
284+ @echo " Database status:"
285+ @docker compose exec web bin/rails runner " puts 'Database: ' + (ActiveRecord::Base.connection.active? ? 'OK' : 'ERROR')"
286+ @echo " "
287+ @echo " Redis status:"
288+ @docker compose exec web bin/rails runner " puts 'Redis: ' + (Redis.new.ping == 'PONG' ? 'OK' : 'ERROR')"
0 commit comments