Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use docker-compose for all Docker commands #4592

Merged
merged 4 commits into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions bin/install-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand Down
3 changes: 1 addition & 2 deletions bin/setup-local-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 9 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,4 +39,5 @@ services:
- .:/app

volumes:
testsuite: {}
testsuite:
wordpress:
9 changes: 2 additions & 7 deletions test/e2e/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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( () => {
Expand Down