Skip to content

Breaking change in 3.0 causes errors when running from wp-cli docker container #546

@MikeMcTiernan

Description

@MikeMcTiernan

In 3.0, it appears that the method within bootstrap that initiates the Google\Cloud\Storage\StorageClient instance was changed so that it returns a null value if the key_json setting isn't set, whereas previously, the method would still set and return a client if the setting wasn't present. This change breaks tools that are run from docker containers, such as those based on the official wordpress:cli image, that may rely on mounting volumes from a standard wordpress container, such as wordpress:5.

To give an example, as part of our CI release process, we dump the database tables from our staging site, perform a search and replace to swap out the hosts, and then migrate that data to our production environment. We do this using the following command:

docker run \
  -it \
  --rm \
  --volumes-from my-running-wordpress-container wordpress:cli-php7.2 \
 bash -c \
   "wp --allow-root search-replace https://staging.my-wordpress-site.dev https://www.my-wordpress-site.dev --export --all-tables"

Because the volumes are mounted from a running wordpress container, the environment variables are not carried with them, nor do we particularly care whether or not WP Stateless can function for the purpose of dumping the database tables. Taking a look at https://github.com/udx/wp-stateless/blob/v3.0/lib/classes/class-bootstrap.php#L219-L220:

          $gs_client = $this->init_gs_client();
          StreamWrapper::register($gs_client);

Because $gs_client is null if key_json is not set, StreamWrapper::register($gs_client); will throw an exception.

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to wpCloud\StatelessMedia\StreamWrapper::register() must be an instance of Google\Cloud\Storage\StorageClient, null given, called in /var/www/html/wp-content/plugins/wp-stateless/lib/classes/class-bootstrap.php on line 220 and defined in /var/www/html/wp-content/plugins/wp-stateless/lib/classes/class-gs-stream-wrapper.php:86

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions