Skip to content

refactor: docker setup to be worktree-friendly#11291

Merged
frosso merged 35 commits intodevelopfrom
refactor/docker-worktree-friendly-setup
Feb 10, 2026
Merged

refactor: docker setup to be worktree-friendly#11291
frosso merged 35 commits intodevelopfrom
refactor/docker-worktree-friendly-setup

Conversation

@frosso
Copy link
Contributor

@frosso frosso commented Jan 28, 2026

Fixes WOOPMNT-5683

Changes proposed in this Pull Request

Making the docker setup friendlier to worktrees.
When running multiple WooPayments branches simultaneously using git worktrees, there are issues with port 8082 already in use, database tables colliding, yada yada.
The current docker setup assumes one setup, one developer, one branch at a time.
I reworked the docker configuration to be slightly more friendly towards having multiple feature branches running in parallel, whether it's work that you're reviewing or work that you have agents working on.
Each worktree has its own isolated WordPress instance, but they're all sharing a common database infrastructure and wp-content directories (plugins, themes, uploads).

┌─────────────────────────────────────────────────────────────────────────────┐
│                         SHARED INFRASTRUCTURE                               │
│                      (npm run infra:up - run once)                          │
│  ┌─────────────────────────────────────────┐  ┌──────────────────────────┐  │
│  │           MariaDB (wcpay_db)            │  │   phpMyAdmin :8083       │  │
│  │               :5678                     │  │   (login as root)        │  │
│  │  ┌───────────────────────────────────┐  │  │                          │  │
│  │  │ Databases:                        │  │  └────────────┬─────────────┘  │
│  │  │  • wordpress (shared site data)   │  │               │                │
│  │  │  • wcpay_tests_default            │  │◄──────────────┘                │
│  │  │  • wcpay_tests_feature_x          │  │                                │
│  │  │  • wcpay_tests_bugfix_123         │  │                                │
│  │  │    (one test DB per worktree)     │  │                                │
│  │  └───────────────────────────────────┘  │                                │
│  └──────────────────┬──────────────────────┘                                │
│                     │                                                       │
│  ┌──────────────────┴──────────────────────────────────────────────────┐    │
│  │                    Shared Docker Volumes                            │    │
│  │  wcpay-plugins │ wcpay-themes │ wcpay-uploads │ wcpay-mu-plugins    │    │
│  └─────────────────────────────────────────────────────────────────────┘    │
└───────────────────┼─────────────────────────────────────────────────────────┘
                    │
                    │ wcpay-network (Docker network)
                    │
      ┌─────────────┼─────────────┬─────────────────────┐
      │             │             │                     │
      ▼             ▼             ▼                     ▼
┌───────────────┐ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐
│   Worktree:   │ │   Worktree:   │ │   Worktree:   │ │               │
│    default    │ │   feature_x   │ │  bugfix_123   │ │     ...       │
│ (main repo)   │ │               │ │               │ │               │
├───────────────┤ ├───────────────┤ ├───────────────┤ ├───────────────┤
│  WordPress    │ │  WordPress    │ │  WordPress    │ │  WordPress    │
│  Container    │ │  Container    │ │  Container    │ │  Container    │
│    :8082      │ │    :8084      │ │    :8086      │ │    :auto      │
├───────────────┤ ├───────────────┤ ├───────────────┤ ├───────────────┤
│  .env:        │ │  .env:        │ │  .env:        │ │  .env:        │
│  WP_PORT=8082 │ │  WP_PORT=8084 │ │  WP_PORT=8086 │ │  WP_PORT=auto │
│  WORKTREE_ID= │ │  WORKTREE_ID= │ │  WORKTREE_ID= │ │  WORKTREE_ID= │
│    default    │ │   feature_x   │ │  bugfix_123   │ │     ...       │
└───────────────┘ └───────────────┘ └───────────────┘ └───────────────┘

Each worktree has:
✓ Own WordPress container (isolated PHP/Apache)
✓ Own port (auto-assigned, no conflicts)
✓ Own test database (parallel test runs)
✓ Own WooPayments code (bind-mounted from worktree)
✓ Own WC logs (docker/logs/wc-logs)

Shared across all worktrees:
✓ Site database (same data across branches)
✓ Plugins, themes, uploads, mu-plugins (Docker volumes)

Testing instructions

  • npm run down to stop your current containers
  • Check out this branch
  • npm run infra:up (optional)
  • npm run up:recreate to start wordpress (this also seeds existing plugins/themes from your local directories into the shared volumes)
  • Verify the site works at http://localhost:8082

To test the worktree flow:

Tip

I used this utility to create worktrees and set them up: https://github.com/johnlindquist/worktree-cli
I use it in combination with this worktree.json file:

`worktree.json` on my local setup

{
	"setup-worktree": [
		"[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\" && nvm use || true",
		"npx concurrently -n npm,composer,worktree -c blue,green,yellow 'npm ci' 'composer install --prefer-dist --ignore-platform-req=php' 'npm run worktree:setup'",
		"npx concurrently -n build,docker -c cyan,magenta 'npm run build:client' 'npm run up:recreate'",
		"echo 'Setup complete, you can run `npm start` to have webpack watch your files.'"
	]
}

  • git worktree add ../my-feature-branch develop to create a new worktree
  • cd ../my-feature-branch to navigate to it
  • npm ci && composer install --prefer-dist to install the dependencies
  • npm run worktree:setup to configure port and worktree ID
  • npm run up:recreate to start wordpress
  • Verify you can access it on the assigned port (check .env)
  • Verify plugins/themes from the main checkout are visible in this worktree

To test cleanup:

  • From the worktree, run npm run test:php -- --filter=some_quick_test to create a test database
  • Run npm run worktree:cleanup
  • Verify the test database was dropped and containers stopped

  • Run npm run changelog to add a changelog file, choose patch to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.
  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Post merge

@frosso frosso marked this pull request as ready for review January 28, 2026 12:34
@github-actions
Copy link
Contributor

github-actions bot commented Jan 28, 2026

Test the build

Option 1. Jetpack Beta

  • Install and activate Jetpack Beta.
  • Use this build by searching for PR number 11291 or branch name refactor/docker-worktree-friendly-setup in your-test.site/wp-admin/admin.php?page=jetpack-beta&plugin=woocommerce-payments

Option 2. Jurassic Ninja - available for logged-in A12s

🚀 Launch a JN site with this branch 🚀

ℹ️ Install this Tampermonkey script to get more options.


Build info:

  • Latest commit: f78978d
  • Build time: 2026-02-10 14:35:08 UTC

Note: the build is updated when a new commit is pushed to this PR.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 28, 2026

Size Change: +4.53 kB (0%)

Total Size: 954 kB

Filename Size Change
release/woocommerce-payments/dist/blocks-checkout-rtl.css 2.89 kB +24 B (+1%)
release/woocommerce-payments/dist/blocks-checkout.css 2.89 kB +23 B (+1%)
release/woocommerce-payments/dist/blocks-checkout.js 54.7 kB +609 B (+1%)
release/woocommerce-payments/dist/index.js 158 kB +367 B (0%)
release/woocommerce-payments/dist/chunks/express-checkout-previews.js 3.51 kB +3.51 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 1.46 kB
release/woocommerce-payments/assets/css/admin.rtl.css 1.46 kB
release/woocommerce-payments/assets/css/success.css 1.06 kB
release/woocommerce-payments/assets/css/success.rtl.css 1.06 kB
release/woocommerce-payments/dist/cart-block-rtl.css 113 B
release/woocommerce-payments/dist/cart-block.css 112 B
release/woocommerce-payments/dist/cart-block.js 16.8 kB
release/woocommerce-payments/dist/cart.js 5.32 kB
release/woocommerce-payments/dist/checkout-rtl.css 1.01 kB
release/woocommerce-payments/dist/checkout.css 1.01 kB
release/woocommerce-payments/dist/checkout.js 34 kB
release/woocommerce-payments/dist/express-checkout-rtl.css 367 B
release/woocommerce-payments/dist/express-checkout.css 367 B
release/woocommerce-payments/dist/express-checkout.js 17.4 kB
release/woocommerce-payments/dist/frontend-tracks.js 883 B
release/woocommerce-payments/dist/index-rtl.css 21.7 kB
release/woocommerce-payments/dist/index.css 21.7 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 1.09 kB
release/woocommerce-payments/dist/multi-currency-rtl.css 3.82 kB
release/woocommerce-payments/dist/multi-currency-switcher-block.js 19.2 kB
release/woocommerce-payments/dist/multi-currency.css 3.83 kB
release/woocommerce-payments/dist/multi-currency.js 25.5 kB
release/woocommerce-payments/dist/order-rtl.css 740 B
release/woocommerce-payments/dist/order.css 740 B
release/woocommerce-payments/dist/order.js 22.3 kB
release/woocommerce-payments/dist/plugins-page-rtl.css 484 B
release/woocommerce-payments/dist/plugins-page.css 484 B
release/woocommerce-payments/dist/plugins-page.js 2.65 kB
release/woocommerce-payments/dist/product-details-rtl.css 433 B
release/woocommerce-payments/dist/product-details.css 436 B
release/woocommerce-payments/dist/product-details.js 12.4 kB
release/woocommerce-payments/dist/settings-rtl.css 12.4 kB
release/woocommerce-payments/dist/settings.css 12.3 kB
release/woocommerce-payments/dist/settings.js 153 kB
release/woocommerce-payments/dist/subscription-edit-page.js 1.81 kB
release/woocommerce-payments/dist/subscription-product-onboarding-modal-rtl.css 527 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 527 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 1.98 kB
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 730 B
release/woocommerce-payments/dist/subscriptions-empty-state-rtl.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.js 1.9 kB
release/woocommerce-payments/dist/success.js 6.03 kB
release/woocommerce-payments/dist/tos-rtl.css 235 B
release/woocommerce-payments/dist/tos.css 235 B
release/woocommerce-payments/dist/tos.js 3 kB
release/woocommerce-payments/dist/wc-payments-review-prompt-rtl.css 1.66 kB
release/woocommerce-payments/dist/wc-payments-review-prompt.css 1.66 kB
release/woocommerce-payments/dist/wc-payments-review-prompt.js 14.9 kB
release/woocommerce-payments/dist/wc-payments-settings-spotlight-rtl.css 1.66 kB
release/woocommerce-payments/dist/wc-payments-settings-spotlight.css 1.66 kB
release/woocommerce-payments/dist/wc-payments-settings-spotlight.js 28.2 kB
release/woocommerce-payments/dist/woopay-direct-checkout.js 5.69 kB
release/woocommerce-payments/dist/woopay-express-button.js 22.9 kB
release/woocommerce-payments/dist/woopay-rtl.css 4.27 kB
release/woocommerce-payments/dist/woopay.css 4.25 kB
release/woocommerce-payments/dist/woopay.js 70.9 kB
release/woocommerce-payments/includes/subscriptions/assets/css/plugin-page.css 625 B
release/woocommerce-payments/includes/subscriptions/assets/js/plugin-page.js 814 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/i18n-loader.js 2.46 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/jetpack-script-data.js 880 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/i18n-loader.js 1.02 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/script-data.js 69 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/babel.config.js 163 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.css 2.46 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.js 14.3 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.rtl.css 2.46 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-connection.css 10.1 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-connection.js 31.5 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-connection.rtl.css 10.1 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.css 198 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.js 280 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.rtl.css 198 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.css 625 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.js 331 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.rtl.css 626 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-users.js 415 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-users-connection.js 159 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-ajax.js 520 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-callables.js 585 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.css 218 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.js 521 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.css 719 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.js 412 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-users.js 625 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/about.css 1.04 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-empty-state.css 294 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-order-statuses.css 408 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin.css 3.59 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/checkout.css 301 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/modal.css 746 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/view-subscription.css 574 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/wcs-upgrade.css 414 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin-pointers.js 543 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin.js 9.4 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.js 6.78 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.min.js 3.84 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-coupon.js 545 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-subscription.js 2.52 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.js 22.2 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.min.js 11.7 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/payment-method-restrictions.js 1.29 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/wcs-meta-boxes-order.js 507 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/payment-methods.js 358 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/single-product.js 428 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/view-subscription.js 1.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/wcs-cart.js 782 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/modal.js 1.09 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/wcs-upgrade.js 1.26 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.css 391 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.js 3.04 kB

compressed-size-action

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Docker development setup to support running multiple WooPayments branches simultaneously using git worktrees. The key architectural change is splitting the infrastructure (database and phpMyAdmin) from the WordPress containers, allowing each worktree to have its own isolated WordPress instance while sharing a common database server.

Changes:

  • Split docker-compose.yml into shared infrastructure (docker-compose.infra.yml) and per-worktree WordPress containers
  • Implemented automatic port allocation and worktree identification via .env.local files
  • Added per-worktree test database isolation to prevent conflicts when running tests in parallel
  • Updated all scripts and npm commands to support the new worktree-friendly architecture

Reviewed changes

Copilot reviewed 8 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
package.json Updated npm scripts to use .env.local for env-specific configuration and added new commands for infrastructure management and worktree cleanup
docker-compose.yml Refactored to define only the WordPress container, using external network and environment variables for worktree isolation
docker-compose.infra.yml New file defining shared infrastructure (MariaDB and phpMyAdmin) used across all worktrees
default.env Cleaned up to remove database-specific variables now defined in docker-compose.infra.yml
bin/docker-port-setup.sh New script that auto-allocates available ports and generates unique worktree identifiers
bin/docker-setup.sh Updated to detect and handle shared database scenarios, avoiding duplicate WordPress installs across worktrees
bin/docker-worktree-cleanup.sh New script to clean up Docker resources before removing a worktree
bin/run-tests.sh Updated to use worktree-specific test databases for parallel test execution
bin/check-test-coverage.sh Updated to support .env.local configuration
bin/jurassic-tube-setup.sh Updated to detect WordPress port from .env.local
bin/cli.sh Updated to support .env.local configuration
.husky/post-checkout Updated to auto-configure Docker settings when checking out code
docker/README.md Comprehensive rewrite documenting the new worktree-friendly setup with architecture diagrams and workflows
.gitignore Added .env.local to ignored files
.env.local.example New example file showing configuration options
changelog/refactor-docker-worktree-friendly-setup Added changelog entry for this dev-focused change

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1 to 35
networks:
wcpay-network:
name: wcpay-network

services:
db:
container_name: wcpay_db
image: mariadb:10.5.8
restart: unless-stopped
ports:
- "5678:3306"
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
volumes:
- ./docker/data:/var/lib/mysql
networks:
- wcpay-network

phpmyadmin:
container_name: wcpay_phpmyadmin
image: phpmyadmin:latest
restart: unless-stopped
ports:
- "8083:80"
environment:
PMA_HOST: db
PMA_USER: root
PMA_PASSWORD: wordpress
depends_on:
- db
networks:
- wcpay-network
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change for existing users. The container names have changed from woocommerce_payments_wordpress, woocommerce_payments_mysql, and woocommerce_payments_phpmyadmin to wcpay_wp_${WORKTREE_ID}, wcpay_db, and wcpay_phpmyadmin respectively.

When users run npm run infra:up, they'll create new database containers with empty databases, losing their existing development data. Consider adding migration documentation or a migration script that:

  1. Backs up data from the old woocommerce_payments_mysql container
  2. Restores it to the new wcpay_db container
  3. Cleans up the old containers

Alternatively, document this breaking change clearly in the README so users know to export their data before upgrading.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I tried this out, and the DB contents do persist after running npm run infra:up. It would be nice to get someone else to confirm.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think Copilot missed the mounted volume with the actual database files. The comment stands true if someone creates a container with database storage inside the container filesystem and runs it forever, but even a mere system cleanup will destroy the data in such a scenario.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 23 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

.husky/post-merge:44

  • The variable DEV_TOOLS_PLUGIN_PATH is used without quotes in several places (lines 33, 37, 40, 44). If the path contains spaces or special characters, this could cause the script to fail or behave unexpectedly. While the path is typically sanitized, it's best practice to always quote variable expansions in shell scripts to handle edge cases. Change instances like 'cd $DEV_TOOLS_PLUGIN_PATH' to 'cd "$DEV_TOOLS_PLUGIN_PATH"'.
	if [ "$(cd $DEV_TOOLS_PLUGIN_PATH && git rev-parse --show-toplevel 2>/dev/null)" = "$(cd $DEV_TOOLS_PLUGIN_PATH && pwd)" ]; then
		echo
		echo "\033[32mDetermining if there is an update for the WCPay Dev Tools plugin...\033[0m"

		DEV_TOOLS_BRANCH=$(cd $DEV_TOOLS_PLUGIN_PATH && git branch --show-current)
		if [ "$DEV_TOOLS_BRANCH" = "trunk" ]; then
			echo "  \033[32mThe current branch is trunk. Check if we are safe to pull from origin/trunk...\033[0m"
			if [ "$(cd $DEV_TOOLS_PLUGIN_PATH && git status --porcelain)" ]; then
				echo "\033[33m  There are uncommitted local changes on the WCPay Dev Tools repo. Skipping any attempt to update it.\033[0m"
			else
				echo "  \033[32mPulling the latest changes from origin/trunk, if any...\033[0m"
				cd $DEV_TOOLS_PLUGIN_PATH && git pull

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

package.json Outdated
"start": "npm run watch",
"dev": "npm run up && npm run watch",
"up:recreate": "bash bin/docker-preflight.sh && docker compose up --build --force-recreate -d && ./bin/docker-setup.sh && bash -c 'source .env 2>/dev/null; echo \"Site available at http://localhost:${WORDPRESS_PORT:-8082}\"'",
"up": "bash bin/docker-preflight.sh && docker compose up --build -d && bash bin/docker-seed-volumes.sh && bash -c 'source .env 2>/dev/null; echo \"Site available at http://localhost:${WORDPRESS_PORT:-8082}\"'",
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'up' script on line 61 calls docker-seed-volumes.sh but doesn't call docker-setup.sh. This means that when users run 'npm run up' (for subsequent startups), the WordPress setup won't be triggered. While this might be intentional for performance (assuming setup only needs to run once), it could lead to confusion if containers are stopped and restarted but the setup state is lost (e.g., if WordPress files are corrupted or the container is recreated externally). Consider documenting this behavior clearly or adding a check in the 'up' command to detect if setup is needed.

Suggested change
"up": "bash bin/docker-preflight.sh && docker compose up --build -d && bash bin/docker-seed-volumes.sh && bash -c 'source .env 2>/dev/null; echo \"Site available at http://localhost:${WORDPRESS_PORT:-8082}\"'",
"up": "bash bin/docker-preflight.sh && docker compose up --build -d && bash bin/docker-seed-volumes.sh && ./bin/docker-setup.sh && bash -c 'source .env 2>/dev/null; echo \"Site available at http://localhost:${WORDPRESS_PORT:-8082}\"'",

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@RadoslavGeorgiev RadoslavGeorgiev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol, I didn't realize how much code would be involved in this setup :D

It's amazing that you have considered all existing scripts, but it will take me a while to review everything. I'll continue next week, but it looks pretty promising at first glance! I like that you decided to use individual test DBs instead of whole separate instances for them.

My main concern so far is maintaining the wp-content directories easily accessible. I still have to check how that works with local mappings, as my current setup includes:

services:
  wordpress:
    volumes:
      - /Users/rado/Projects/woocommerce/plugins/woocommerce:/var/www/html/wp-content/plugins/woocommerce
      - /Users/rado/Projects/product-feed:/var/www/html/wp-content/plugins/open-ai-feed

It would be cool to be able to maintain those external directories.

Leaving my notes for now, and I'll continue the review/testing next week.

echo "Updating the WordPress database..."
cli wp core update-db --quiet

echo "Configuring WordPress to work with ngrok (in order to allow creating a Jetpack-WPCOM connection)";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved these lines up in this file, to ensure they exist in the wp-config.php

@frosso frosso self-assigned this Feb 6, 2026
@frosso frosso requested review from a team and mgascam and removed request for a team February 6, 2026 11:18
Copy link
Contributor

@mgascam mgascam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @frosso.

I tried the worktree setup while working on a couple of tasks and it worked well for me. Definitely much better than having two separate checkouts. My setup is pretty much "vanilla" (Docker-based with no customizations) but the whole flow — worktree:setup, up:recreate, running both sites in parallel — was smooth and easy to follow.

I'm happy to approve as I think it's a great improvement.

Just one idea for the future: it would be nice to have a utility to list all worktrees and their associated ports. Feels like the building blocks are already in place.

frosso and others added 4 commits February 6, 2026 20:31
Co-authored-by: Miguel Gasca <miguel.gasca@automattic.com>
Co-authored-by: Miguel Gasca <miguel.gasca@automattic.com>
@frosso
Copy link
Contributor Author

frosso commented Feb 6, 2026

Thank you @mgascam ! That's a good idea - @dmallory42 had a similar command in mind, and I think it would make sense in this setup because it could just be using git's native utilities. Worktree helpers do allow you to list the worktrees, but they don't list ports/docker containers/etc. So I could definitely go down with that 👍
I pretty much copied it with a few mods in 67c89db

I'll wait for @RadoslavGeorgiev 's review as well, before merging.

Copy link
Contributor

@RadoslavGeorgiev RadoslavGeorgiev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For such a significant change, all of this looks soo good! Thank you for also implementing my idea regarding the Docker volumes and not having to manually copy files!

I have a few comments, but they are all minor. So far I've tested with an old machine, and everything seems to work as advertised. I intentionally went vanilla and did not use the worktree-cli package, I'll leave that for next time.

Just curious, is there a specific migration path you have in mind for other devs? It doesn't really seem like one is needed, as npm run up without the infra running will already tell you what to do, but I wanted to check.

Comment on lines +56 to +60
docker exec $WP_CONTAINER bash -c "grep -q '\\\$_SERVER\[.HTTP_HOST.\] = DOCKER_HOST' /var/www/html/wp-config.php || sed -i \"/define.*'DOCKER_HOST'/a \\\\\\\$_SERVER['HTTP_HOST'] = DOCKER_HOST;\" /var/www/html/wp-config.php"
cli wp config set DOCKER_REQUEST_URL "( ! empty( \$_SERVER['HTTPS'] ) ? 'https://' : 'http://' ) . DOCKER_HOST" --raw
cli wp config set WP_SITEURL DOCKER_REQUEST_URL --raw
cli wp config set WP_HOME DOCKER_REQUEST_URL --raw

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a cool set of defaults. In the future, we might want to try to read these from a file.

@dmvrtx
Copy link
Contributor

dmvrtx commented Feb 10, 2026

I tested it without adding a worktree and there is a permamanent warning about orphan containers. E.g. npm run worktree:status says:

Warnings:
  - Orphan container: wcpay_wp_default (no matching worktree)

  To clean up: docker stop <name> && docker rm <name>

But it seems to be a false alert, as the container is used for the default repository.

@frosso
Copy link
Contributor Author

frosso commented Feb 10, 2026

Thanks @RadoslavGeorgiev and @dmvrtx for the most recent reviews!

Just curious, is there a specific migration path you have in mind for other devs? It doesn't really seem like one is needed, as npm run up without the infra running will already tell you what to do, but I wanted to check.

Yeah, like you said, I don't think we need any specific migration path. My intention was to have the whole thing as painless as possible if somebody doesn't want to use worktrees or if they aren't using a specific WT utility.

Copy link
Contributor

@RadoslavGeorgiev RadoslavGeorgiev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good from my side :)

Copy link
Contributor

@dmvrtx dmvrtx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for quickly addressing the pseudo-orphans! Looks good!

@frosso frosso added this pull request to the merge queue Feb 10, 2026
Merged via the queue into develop with commit cb0426c Feb 10, 2026
43 checks passed
@frosso frosso deleted the refactor/docker-worktree-friendly-setup branch February 10, 2026 16:42
@oaratovskyi
Copy link
Contributor

@RadoslavGeorgiev and @frosso it broke my local with the next error:

Error: There has been a critical error on this website.Learn more about troubleshooting WordPress. There has been a critical error on this website.

what should I do to fix it?

I have followed the PR instructions with npm run infra:up and npm run up:recreate.

@dmvrtx
Copy link
Contributor

dmvrtx commented Feb 11, 2026

what should I do to fix it?

@oaratovskyi Most probably it is the new Dev Tools that broke it. Go to docker/wordpress/wp-content/plugins/woocommerce-payments-dev-tools and try running composer install.

@oaratovskyi
Copy link
Contributor

That was it @dmvrtx. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants