From a4d33f6afdd54652329f1e3e2c2c85503d7d3366 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 31 Aug 2026 02:27:30 +0000 Subject: [PATCH] Fix pressbooks.sh: wp-cli commands failing with "core: not found" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit wp-config.php's WORDPRESS_CONFIG_EXTRA requires extra-config.php, but the ephemeral "docker run wordpress:cli ..." containers used for every wp-cli call only mounted html/, not that file — loading wp-config.php there hit a PHP fatal, which broke the wordpress:cli entrypoint's own internal "wp help $1" probe for whether to prepend "wp". That probe failing silently falls through to exec-ing the raw subcommand as a literal binary ("core: not found") instead of running it through wp-cli at all. Fixed by: bind-mounting extra-config.php into every wp-cli invocation too, guarding the require with file_exists so a missing mount can't fatal wp-config.php again, and spelling "wp" out explicitly in the wpcli wrapper functions rather than depending on the entrypoint's own bootstrap-dependent auto-detection. Updated the manual-retry command printed on failure and the README's wp-cli example to match. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01P1Xynq3mBwtH45f8bTDfta --- services/pressbooks.sh | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/services/pressbooks.sh b/services/pressbooks.sh index 54b3f5d..aa3c514 100644 --- a/services/pressbooks.sh +++ b/services/pressbooks.sh @@ -311,7 +311,14 @@ _pressbooks_normalize_slug() { # code, never wp-config.php, .env, or any book's own content/DB rows). _pressbooks_install_plugins_and_themes() { local _dir="$1" _net="$2" _port="$3" - _pb_wpcli() { docker run --rm --network "$_net" -v "${_dir}/html:/var/www/html" --env-file "${_dir}/.env" wordpress:cli "$@"; } + # "wp" is spelled out explicitly rather than relying on the wordpress:cli + # entrypoint's own "wp help $1 && set -- wp $@" auto-detection — that + # probe itself runs through wp-cli's bootstrap, so anything that breaks + # the bootstrap (a bad wp-config.php, a missing bind mount) makes the + # probe fail *silently* and falls through to exec-ing the raw + # subcommand as if it were a binary ("core: not found") instead of + # surfacing the real error. + _pb_wpcli() { docker run --rm --network "$_net" -v "${_dir}/html:/var/www/html" -v "${_dir}/extra-config.php:/usr/local/etc/pressbooks/extra-config.php:ro" --env-file "${_dir}/.env" wordpress:cli wp "$@"; } local _plugin_url _book_url _aldine_url _publisher_url _plugin_url="$(_pressbooks_latest_zip_url pressbooks)" @@ -608,7 +615,17 @@ PBCOMPOSE # Loads the file written above — see the comment there for why the PHP # itself doesn't live directly in this env var. This line has no "$" in # it at all, so it can't run into Compose's .env interpolation. - local _CONFIG_EXTRA="require '/usr/local/etc/pressbooks/extra-config.php';" + # + # Guarded with file_exists rather than a bare require: this same + # wp-config.php (baked once, on the persistent html/ volume) is also + # loaded by every ephemeral "docker run wordpress:cli ..." wp-cli + # invocation below, which only mounts html/ itself — a bare require + # here would fatal in any such container unless it also mounts + # extra-config.php at this exact path. Confirmed live: that fatal was + # swallowing wp-cli's own internal "is this a valid subcommand" probe, + # so "core install" ran as a literal, nonexistent "core" binary instead + # of being handed to wp-cli at all ("core: not found"). + local _CONFIG_EXTRA="if (file_exists('/usr/local/etc/pressbooks/extra-config.php')) { require '/usr/local/etc/pressbooks/extra-config.php'; }" backup_if_exists .env cat > .env << PBENV @@ -656,7 +673,8 @@ PBENV sleep 1; _tries=$((_tries + 1)) done - _wpcli() { docker run --rm --network "$WP_NET" -v "$DIR/html:/var/www/html" --env-file "$DIR/.env" wordpress:cli "$@"; } + # "wp" spelled out explicitly — see _pb_wpcli's comment above for why. + _wpcli() { docker run --rm --network "$WP_NET" -v "$DIR/html:/var/www/html" -v "$DIR/extra-config.php:/usr/local/etc/pressbooks/extra-config.php:ro" --env-file "$DIR/.env" wordpress:cli wp "$@"; } log_info "Running wp-cli core install..." if ! _wpcli core install \ @@ -667,7 +685,9 @@ PBENV --admin_email="$PB_ADMIN_EMAIL" \ --skip-email; then log_error "wp-cli core install failed — WordPress may not have been ready yet. Retry manually:" - log_error " docker run --rm --network $WP_NET -v $DIR/html:/var/www/html --env-file $DIR/.env wordpress:cli core install ..." + log_error " docker run --rm --network $WP_NET -v $DIR/html:/var/www/html \\" + log_error " -v $DIR/extra-config.php:/usr/local/etc/pressbooks/extra-config.php:ro \\" + log_error " --env-file $DIR/.env wordpress:cli wp core install ..." return 1 fi @@ -771,6 +791,7 @@ refreshes the Pressbooks plugin/themes to their latest release. ## wp-cli \`\`\`bash docker run --rm --network $WP_NET -v $DIR/html:/var/www/html \\ + -v $DIR/extra-config.php:/usr/local/etc/pressbooks/extra-config.php:ro \\ --env-file $DIR/.env wordpress:cli wp \`\`\`