@bostonuniversity/buwp-local 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,513 @@
1
+ # Multi-Project Support
2
+
3
+ Learn how to run multiple buwp-local projects simultaneously, either isolated or integrated.
4
+
5
+ ## Overview
6
+
7
+ buwp-local supports two multi-project strategies:
8
+
9
+ 1. **Isolated Environments** - Each project runs independently with its own database and WordPress
10
+ 2. **Shared Environments** - Multiple repositories share one WordPress instance for integration testing
11
+
12
+ ## Isolated Environments
13
+
14
+ ### How It Works
15
+
16
+ Each project gets a unique name (based on directory name) and isolated Docker volumes:
17
+
18
+ - **Database volume:** `{projectName}_db_data`
19
+ - **WordPress volume:** `{projectName}_wp_build`
20
+ - **Container names:** `{projectName}-wordpress-1`, `{projectName}-db-1`, etc.
21
+
22
+ This means:
23
+ ✅ Each project has its own database
24
+ ✅ Each project has its own WordPress installation
25
+ ✅ Projects don't interfere with each other
26
+ ✅ You can run multiple projects simultaneously
27
+
28
+ ### Setting Up Multiple Projects
29
+
30
+ **Step 1: Initialize each project**
31
+
32
+ ```bash
33
+ # Plugin A
34
+ cd ~/projects/bu-custom-analytics
35
+ npx buwp-local init --plugin
36
+
37
+ # Plugin B
38
+ cd ~/projects/bu-slideshow
39
+ npx buwp-local init --plugin
40
+
41
+ # Theme
42
+ cd ~/projects/responsive-framework
43
+ npx buwp-local init --theme
44
+ ```
45
+
46
+ **Step 2: Configure different ports (optional)**
47
+
48
+ Edit `.buwp-local.json` in each project to avoid port conflicts:
49
+
50
+ ```json
51
+ // bu-custom-analytics
52
+ {
53
+ "ports": {
54
+ "http": 8080,
55
+ "https": 8443
56
+ }
57
+ }
58
+
59
+ // bu-slideshow
60
+ {
61
+ "ports": {
62
+ "http": 8081,
63
+ "https": 8444
64
+ }
65
+ }
66
+
67
+ // responsive-framework
68
+ {
69
+ "ports": {
70
+ "http": 8082,
71
+ "https": 8445
72
+ }
73
+ }
74
+ ```
75
+
76
+ **Step 3: Add hostnames to /etc/hosts**
77
+
78
+ ```bash
79
+ sudo bash -c 'cat >> /etc/hosts << EOF
80
+ 127.0.0.1 bu-custom-analytics.local
81
+ 127.0.0.1 bu-slideshow.local
82
+ 127.0.0.1 responsive-framework.local
83
+ EOF'
84
+ ```
85
+
86
+ **Step 4: Start all projects**
87
+
88
+ ```bash
89
+ cd ~/projects/bu-custom-analytics && npx buwp-local start
90
+ cd ~/projects/bu-slideshow && npx buwp-local start
91
+ cd ~/projects/responsive-framework && npx buwp-local start
92
+ ```
93
+
94
+ **Step 5: Access your sites**
95
+
96
+ - http://bu-custom-analytics.local:8080
97
+ - http://bu-slideshow.local:8081
98
+ - http://responsive-framework.local:8082
99
+
100
+ ### Managing Multiple Projects
101
+
102
+ **View running projects in Docker Desktop:**
103
+
104
+ ```
105
+ Containers:
106
+ ├─ bu-custom-analytics
107
+ │ ├─ bu-custom-analytics-wordpress-1
108
+ │ ├─ bu-custom-analytics-db-1
109
+ │ └─ bu-custom-analytics-redis-1
110
+
111
+ ├─ bu-slideshow
112
+ │ ├─ bu-slideshow-wordpress-1
113
+ │ ├─ bu-slideshow-db-1
114
+ │ └─ bu-slideshow-redis-1
115
+
116
+ └─ responsive-framework
117
+ ├─ responsive-framework-wordpress-1
118
+ ├─ responsive-framework-db-1
119
+ └─ responsive-framework-redis-1
120
+ ```
121
+
122
+ **Stop a specific project:**
123
+
124
+ ```bash
125
+ cd ~/projects/bu-custom-analytics
126
+ npx buwp-local stop
127
+ ```
128
+
129
+ **View logs for a specific project:**
130
+
131
+ ```bash
132
+ cd ~/projects/bu-slideshow
133
+ npx buwp-local logs -f
134
+ ```
135
+
136
+ ---
137
+
138
+ ## Shared Environments
139
+
140
+ ### When to Use Shared Environments
141
+
142
+ Use a shared environment when you need to:
143
+ - ✅ Test how multiple plugins work together
144
+ - ✅ Develop theme + plugins simultaneously
145
+ - ✅ Mirror production configuration locally
146
+ - ✅ Test plugin interactions with real data
147
+ - ✅ Collaborate on integrated features
148
+
149
+ ### How It Works
150
+
151
+ By giving multiple repositories the **same `projectName`**, they join the same Docker Compose project and share:
152
+ - Database (one shared MySQL instance)
153
+ - WordPress installation (one shared wp_build volume)
154
+ - Services (Redis, S3 proxy, etc.)
155
+
156
+ ### Setup: Primary + Secondary Pattern
157
+
158
+ This is the recommended approach for shared environments.
159
+
160
+ #### Primary Repository
161
+
162
+ Create a "primary" repository that owns the base configuration:
163
+
164
+ ```bash
165
+ mkdir ~/projects/bu-sandbox-primary
166
+ cd ~/projects/bu-sandbox-primary
167
+ npx buwp-local init
168
+ ```
169
+
170
+ Edit `.buwp-local.json`:
171
+
172
+ ```json
173
+ {
174
+ "projectName": "bu-sandbox",
175
+ "hostname": "bu-sandbox.local",
176
+ "multisite": true,
177
+ "services": {
178
+ "redis": true,
179
+ "s3proxy": true,
180
+ "shibboleth": true
181
+ },
182
+ "ports": {
183
+ "http": 80,
184
+ "https": 443,
185
+ "db": 3306
186
+ },
187
+ "mappings": [],
188
+ "env": {
189
+ "WP_DEBUG": true
190
+ }
191
+ }
192
+ ```
193
+
194
+ Create shared credentials:
195
+
196
+ ```bash
197
+ # Either use Keychain (recommended)
198
+ npx buwp-local keychain setup --file ~/Downloads/credentials.json
199
+
200
+ # Or create .env.local
201
+ cp .env.local.example .env.local
202
+ # Edit with credentials
203
+ ```
204
+
205
+ Start the base environment:
206
+
207
+ ```bash
208
+ npx buwp-local start
209
+ ```
210
+
211
+ #### Secondary Repositories
212
+
213
+ Add your plugin/theme repositories to the shared environment:
214
+
215
+ ```bash
216
+ cd ~/projects/bu-custom-analytics
217
+ npx buwp-local init --plugin
218
+ ```
219
+
220
+ Edit `.buwp-local.json` to use the **same projectName**:
221
+
222
+ ```json
223
+ {
224
+ "projectName": "bu-sandbox", // Same as primary!
225
+ "hostname": "bu-sandbox.local",
226
+ "multisite": true,
227
+ "services": {
228
+ "redis": true,
229
+ "s3proxy": true,
230
+ "shibboleth": true
231
+ },
232
+ "ports": {
233
+ "http": 80,
234
+ "https": 443,
235
+ "db": 3306
236
+ },
237
+ "mappings": [
238
+ {
239
+ "local": "./",
240
+ "container": "/var/www/html/wp-content/plugins/bu-custom-analytics"
241
+ }
242
+ ],
243
+ "env": {
244
+ "WP_DEBUG": true
245
+ }
246
+ }
247
+ ```
248
+
249
+ Link or copy credentials:
250
+
251
+ ```bash
252
+ # Option 1: Use Keychain (already global, nothing to do)
253
+
254
+ # Option 2: Symlink to primary .env.local
255
+ ln -s ~/projects/bu-sandbox-primary/.env.local .env.local
256
+ ```
257
+
258
+ Add this plugin to the shared environment:
259
+
260
+ ```bash
261
+ npx buwp-local start
262
+ ```
263
+
264
+ Now your plugin is mounted into the shared WordPress instance!
265
+
266
+ #### Add More Repositories
267
+
268
+ Repeat for additional plugins/themes:
269
+
270
+ ```bash
271
+ # Plugin B
272
+ cd ~/projects/bu-slideshow
273
+ npx buwp-local init --plugin
274
+ # Edit .buwp-local.json with projectName: "bu-sandbox"
275
+ npx buwp-local start
276
+
277
+ # Theme
278
+ cd ~/projects/responsive-framework
279
+ npx buwp-local init --theme
280
+ # Edit .buwp-local.json with projectName: "bu-sandbox"
281
+ npx buwp-local start
282
+ ```
283
+
284
+ ### Accessing the Shared Environment
285
+
286
+ All repositories share the same URL:
287
+
288
+ ```
289
+ http://bu-sandbox.local
290
+ ```
291
+
292
+ All plugins and themes are mounted:
293
+ - `/wp-content/plugins/bu-custom-analytics/` → `~/projects/bu-custom-analytics/`
294
+ - `/wp-content/plugins/bu-slideshow/` → `~/projects/bu-slideshow/`
295
+ - `/wp-content/themes/responsive-framework/` → `~/projects/responsive-framework/`
296
+
297
+ ### Managing Shared Environments
298
+
299
+ **Start the environment (from any repository):**
300
+
301
+ ```bash
302
+ cd ~/projects/bu-custom-analytics
303
+ npx buwp-local start
304
+ ```
305
+
306
+ **Stop the environment (from any repository):**
307
+
308
+ ```bash
309
+ cd ~/projects/bu-sandbox-primary
310
+ npx buwp-local stop
311
+ ```
312
+
313
+ **View logs (from any repository):**
314
+
315
+ ```bash
316
+ cd ~/projects/bu-slideshow
317
+ npx buwp-local logs -f
318
+ ```
319
+
320
+ **Destroy and rebuild:**
321
+
322
+ ```bash
323
+ cd ~/projects/bu-sandbox-primary
324
+ npx buwp-local destroy
325
+ npx buwp-local start
326
+ ```
327
+
328
+ ---
329
+
330
+ ## Configuration Consistency
331
+
332
+ ### ⚠️ Important: Keep Configs Synchronized
333
+
334
+ All repositories sharing a `projectName` must have **matching configuration**:
335
+
336
+ | Setting | Must Match | Why |
337
+ |---------|-----------|-----|
338
+ | `projectName` | ✅ Yes | Determines which project containers join |
339
+ | `hostname` | ✅ Yes | All repos should access same URL |
340
+ | `ports` | ✅ Yes | Port conflicts cause failures |
341
+ | `services` | ✅ Yes | Enables/disables Redis, S3, Shibboleth |
342
+ | `env` vars | ⚠️ Should | Avoid conflicting environment variables |
343
+ | `mappings` | ❌ No | Each repo adds its own mappings |
344
+
345
+ ### Best Practices
346
+
347
+ 1. **Use primary repository as source of truth**
348
+ - Make configuration changes in primary repo
349
+ - Copy settings to secondary repos
350
+ - Document which repo is primary
351
+
352
+ 2. **Keep secondary repos minimal**
353
+ - Only add `mappings` section
354
+ - Copy all other settings from primary
355
+
356
+ 3. **Use symlinks for shared files**
357
+ ```bash
358
+ ln -s ~/projects/bu-sandbox-primary/.env.local .env.local
359
+ ```
360
+
361
+ 4. **Document the setup**
362
+ - Add README.md in primary repo
363
+ - List all participating repositories
364
+ - Note any special configuration
365
+
366
+ ---
367
+
368
+ ## Comparison: Isolated vs Shared
369
+
370
+ | Aspect | Isolated | Shared |
371
+ |--------|----------|--------|
372
+ | **Use Case** | Solo development | Integration testing |
373
+ | **Databases** | Separate per project | One shared database |
374
+ | **WordPress** | Separate per project | One shared instance |
375
+ | **URLs** | Different per project | Same for all repos |
376
+ | **Ports** | Can differ | Must be identical |
377
+ | **Data Isolation** | Complete | Shared |
378
+ | **Setup Complexity** | Low | Medium |
379
+ | **Best For** | Independent work | Team collaboration |
380
+
381
+ ### When to Use Isolated Environments
382
+
383
+ ✅ Developing one plugin/theme independently
384
+ ✅ Need clean slate for testing
385
+ ✅ Don't need other plugins active
386
+ ✅ Want to test different WordPress versions
387
+ ✅ Working on experimental features
388
+ ✅ Need different PHP/MySQL settings per project
389
+
390
+ ### When to Use Shared Environments
391
+
392
+ ✅ Testing plugin interactions
393
+ ✅ Developing theme + plugins together
394
+ ✅ Mimicking production setup locally
395
+ ✅ Team collaborating on same codebase
396
+ ✅ Need persistent test data across plugins
397
+ ✅ Integration/acceptance testing
398
+ ✅ Want single URL for all development
399
+
400
+ ---
401
+
402
+ ## Troubleshooting
403
+
404
+ ### Port Conflicts
405
+
406
+ **Problem:** Can't start second project due to port conflicts
407
+
408
+ **Solution:** Use different ports in `.buwp-local.json`:
409
+
410
+ ```json
411
+ {
412
+ "ports": {
413
+ "http": 8081,
414
+ "https": 8444,
415
+ "db": 3307
416
+ }
417
+ }
418
+ ```
419
+
420
+ ### Shared Environment Config Drift
421
+
422
+ **Problem:** Repos have different configurations causing issues
423
+
424
+ **Solution:** Standardize configuration across all repos:
425
+
426
+ 1. Update primary repo with correct config
427
+ 2. Copy settings to all secondary repos
428
+ 3. Run `destroy` and `start` from primary
429
+
430
+ ### Can't Remove Plugin from Shared Environment
431
+
432
+ **Problem:** Need to remove a plugin from shared WordPress
433
+
434
+ **Solution:** Destroy and rebuild without that plugin:
435
+
436
+ ```bash
437
+ cd ~/projects/bu-sandbox-primary
438
+ npx buwp-local destroy
439
+
440
+ # Don't start from the plugin you want to remove
441
+ cd ~/projects/other-plugin
442
+ npx buwp-local start
443
+ ```
444
+
445
+ ### Database Confusion
446
+
447
+ **Problem:** Not sure which project's database you're using
448
+
449
+ **Solution:** Check Docker volumes:
450
+
451
+ ```bash
452
+ docker volume ls | grep db_data
453
+ ```
454
+
455
+ Each isolated project has its own: `{projectName}_db_data`
456
+
457
+ ### Start Order Issues
458
+
459
+ **Problem:** Last repo to start "wins" configuration
460
+
461
+ **Solution:** Always start from primary repo first:
462
+
463
+ ```bash
464
+ cd ~/projects/bu-sandbox-primary
465
+ npx buwp-local start
466
+
467
+ cd ~/projects/plugin-a
468
+ npx buwp-local start
469
+ ```
470
+
471
+ ---
472
+
473
+ ## Advanced: Hybrid Approach
474
+
475
+ You can use **both strategies** for different workflows:
476
+
477
+ ```bash
478
+ # Isolated environment for experimentation
479
+ cd ~/projects/bu-custom-analytics
480
+ # .buwp-local.json has projectName: "bu-custom-analytics"
481
+ npx buwp-local start
482
+ # Test independently at http://bu-custom-analytics.local
483
+
484
+ # Later: Test in shared environment
485
+ # Edit .buwp-local.json, change projectName to "bu-sandbox"
486
+ npx buwp-local start
487
+ # Now part of shared sandbox at http://bu-sandbox.local
488
+
489
+ # Switch back to isolated
490
+ # Restore original projectName
491
+ npx buwp-local destroy # Clean up shared
492
+ npx buwp-local start # Back to isolated
493
+ ```
494
+
495
+ **Tip:** Keep two config files:
496
+
497
+ ```bash
498
+ .buwp-local.json # Isolated (default)
499
+ .buwp-local.shared.json # Shared environment
500
+
501
+ # Switch between them
502
+ cp .buwp-local.shared.json .buwp-local.json # Use shared
503
+ cp .buwp-local.isolated.json .buwp-local.json # Use isolated
504
+ ```
505
+
506
+ ---
507
+
508
+ ## See Also
509
+
510
+ - [Getting Started](GETTING_STARTED.md) - Initial setup guide
511
+ - [Commands Reference](COMMANDS.md) - Full command list
512
+ - [Credentials Management](CREDENTIALS.md) - Managing credentials across projects
513
+ - [Architecture](ARCHITECTURE.md) - Technical implementation details