Skip to content

Instantly share code, notes, and snippets.

@borkweb
Last active September 14, 2022 02:29
Show Gist options
  • Save borkweb/2d9188d44803de3b7d1f7fb6853c9c7d to your computer and use it in GitHub Desktop.
Save borkweb/2d9188d44803de3b7d1f7fb6853c9c7d to your computer and use it in GitHub Desktop.
How I set up the wp-cli testing environment with docker
#!/bin/bash
container="wp-cli-mysql"
container_status=$( docker container inspect -f '{{.State.Status}}' $container );
echo "Setting environment variables"
export WP_CLI_TEST_DBHOST=127.0.0.1:3310
export WP_CLI_TEST_DBROOTUSER=root
export WP_CLI_TEST_DBROOTPASS=password
export WP_CLI_TEST_DBNAME=wp_cli_test
export WP_CLI_TEST_DBUSER=wp_cli_test
export WP_CLI_TEST_DBPASS=password1
if [ "$container_status" == "exited" ]; then
echo "Starting wp-cli-mysql container"
docker start $container
echo "...started"
elif [ "$container_status" == "" ]; then
echo "Creating wp-cli-mysql container"
docker run -p 3310:3306 --restart always --env MYSQL_ROOT_HOST=% --name=$container -e MYSQL_ROOT_PASSWORD=$WP_CLI_TEST_DBROOTPASS -d mysql/mysql-server:8.0
echo "...created"
echo "Preparing database"
sleep 30
composer prepare-tests
fi
echo "Ready to rock and roll"
# This is what I do to get all the appropriate env values set
source /path/to/cli-db.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment