Permalink
Browse files

Use docker-compose for all Docker commands (#4592)

  • Loading branch information...
pento committed Jan 19, 2018
1 parent a2d64e1 commit 85be4c7e30c851d0a24bd7df82f990f26377bd0c
Showing with 35 additions and 31 deletions.
  1. +23 −20 bin/install-docker.sh
  2. +1 −2 bin/setup-local-env.sh
  3. +9 −2 docker-compose.yml
  4. +2 −7 test/e2e/plugins/index.js
@@ -18,45 +18,48 @@ if ! docker info >/dev/null 2>&1; then
exit 1
fi
# Stop existing containers
echo -e $(status_message "Stopping Docker containers...")
docker-compose down --remove-orphans >/dev/null 2>&1
# Download image updates
echo -e $(status_message "Downloading Docker image updates...")
docker-compose pull --parallel
# Launch the containers
echo -e $(status_message "Updating and starting Docker containers...")
if ! docker-compose up -d; then
# Launching may fail due to the docker config file directory having changed.
# Remove the old wordpress-dev container, and try again.
docker container rm -fv wordpress-dev
docker-compose up -d
fi
echo -e $(status_message "Starting Docker containers...")
docker-compose up -d >/dev/null
HOST_PORT=$(docker inspect --format '{{(index (index .HostConfig.PortBindings "80/tcp") 0).HostPort}}' wordpress-dev)
HOST_PORT=$(docker-compose port wordpress 80 | awk -F : '{printf $2}')
# Wait until the docker containers are setup properely
echo -en $(status_message "Attempting to connect to wordpress...")
until $(curl -L http://localhost:$HOST_PORT -so - 2>&1 | grep -q "WordPress"); do
echo -n '.'
sleep 5
done
echo ' done!'
echo ''
# Install WordPress
echo -en $(status_message "Installing WordPress...")
docker run -it --rm --volumes-from wordpress-dev --network container:wordpress-dev wordpress:cli core install --url=localhost:$HOST_PORT --title=Gutenberg --admin_user=admin --admin_password=password --admin_email=test@test.com >/dev/null
echo -e $(status_message "Installing WordPress...")
docker-compose run --rm cli core install --url=localhost:$HOST_PORT --title=Gutenberg --admin_user=admin --admin_password=password --admin_email=test@test.com >/dev/null
# Check for WordPress updates, just in case the WordPress image isn't up to date.
docker-compose run --rm cli core update >/dev/null
CURRENT_URL=$(docker run -it --rm --volumes-from wordpress-dev --network container:wordpress-dev wordpress:cli option get siteurl)
# If the 'wordpress' volume wasn't during the down/up earlier, but the post port has changed, we need to update it.
CURRENT_URL=$(docker-compose run -T --rm cli option get siteurl)
if [ "$CURRENT_URL" != "http://localhost:$HOST_PORT" ]; then
docker run -it --rm --volumes-from wordpress-dev --network container:wordpress-dev wordpress:cli option update home "http://localhost:$HOST_PORT"
docker run -it --rm --volumes-from wordpress-dev --network container:wordpress-dev wordpress:cli option update siteurl "http://localhost:$HOST_PORT"
docker-compose run --rm cli option update home "http://localhost:$HOST_PORT" >/dev/null
docker-compose run --rm cli option update siteurl "http://localhost:$HOST_PORT" >/dev/null
fi
echo ' done!'
# Activate Gutenberg
echo -en $(status_message "Activating Gutenberg...")
docker run -it --rm --volumes-from wordpress-dev --network container:wordpress-dev wordpress:cli plugin activate gutenberg >/dev/null
echo ' done!'
echo -e $(status_message "Activating Gutenberg...")
docker-compose run --rm cli plugin activate gutenberg >/dev/null
# Install the PHPUnit test scaffolding
echo -en $(status_message "Installing PHPUnit test scaffolding...")
echo -e $(status_message "Installing PHPUnit test scaffolding...")
docker-compose run --rm wordpress_phpunit /app/bin/install-wp-tests.sh wordpress_test root example mysql latest false >/dev/null
echo ' done!'
# Install Composer
echo -e $(status_message "Installing and updating Composer modules...")
@@ -23,8 +23,7 @@ cd "$(dirname "$0")/.."
`---'
EOT
CURRENT_URL=$(docker run -it --rm --volumes-from wordpress-dev --network container:wordpress-dev wordpress:cli option get siteurl)
CURRENT_URL="${CURRENT_URL//[[:space:]]/}"
CURRENT_URL=$(docker-compose run -T --rm cli option get siteurl)
echo -e "\nWelcome to...\n"
echo -e "\033[95m$GUTENBERG\033[0m"
@@ -10,8 +10,14 @@ services:
WORDPRESS_DB_PASSWORD: example
ABSPATH: /usr/src/wordpress/
volumes:
- wordpress:/var/www/html
- .:/var/www/html/wp-content/plugins/gutenberg
cli:
image: wordpress:cli
volumes:
- wordpress:/var/www/html
- .:/var/www/html/wp-content/plugins/gutenberg
container_name: wordpress-dev
mysql:
image: mysql:5.7
@@ -33,4 +39,5 @@ services:
- .:/app
volumes:
testsuite: {}
testsuite:
wordpress:
@@ -3,14 +3,9 @@ const exec = promisify( require( 'child_process' ).exec );
module.exports = ( on, config ) => {
// Retrieve the port that the docker container is running on
return exec( 'docker inspect --format \'{{(index (index .HostConfig.PortBindings "80/tcp") 0).HostPort}}\' wordpress-dev' )
return exec( 'docker-compose run -T --rm cli option get siteurl' )
.then( ( stdout ) => {
const port = parseInt( stdout );
const url = 'http://localhost:' + port;
if ( stdout && config.baseUrl !== url ) {
config.baseUrl = url;
}
config.baseUrl = stdout.trim();
return config;
} )
.catch( () => {

0 comments on commit 85be4c7

Please sign in to comment.