Skip to content

Commit

Permalink
Allow access to the WordPress installation if DOCKER_ENV=localwpdev (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
notnownikki authored Aug 10, 2018
1 parent a88f379 commit 29ccdcb
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ languages/gutenberg.pot
phpcs.xml
yarn.lock
docker-compose.override.yml
/wordpress
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ Then, run a setup script to check if docker and node are configured properly and
./bin/setup-local-env.sh
```

If you're developing themes, or core WordPress functionality alongside Gutenberg, you can access the WordPress files in `wordpress/` by running the following command instead:
```
DOCKER_ENV=localwpdev ./bin/setup-local-env.sh
```

If everything was successful, you'll see the following ascii art:
```
Welcome to...
Expand Down
10 changes: 10 additions & 0 deletions bin/bootstrap-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

WP_VERSION=${WP_VERSION-latest}
DOCKER=${DOCKER-false}
DOCKER_ENV=${DOCKER_ENV-ci}
DOCKER_COMPOSE_FILE_OPTIONS="-f docker-compose.yml"

if [ "$DOCKER_ENV" == "localwpdev" ]; then
DOCKER_COMPOSE_FILE_OPTIONS="${DOCKER_COMPOSE_FILE_OPTIONS} -f docker-compose-localdev.yml"
fi
12 changes: 6 additions & 6 deletions bin/install-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Exit if any command fails.
set -e

WP_VERSION=${WP_VERSION-latest}
. "$(dirname "$0")/bootstrap-env.sh"

# Include useful functions.
. "$(dirname "$0")/includes.sh"
Expand All @@ -22,15 +22,15 @@ fi

# Stop existing containers.
echo -e $(status_message "Stopping Docker containers...")
docker-compose down --remove-orphans >/dev/null 2>&1
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS down --remove-orphans >/dev/null 2>&1

# Download image updates.
echo -e $(status_message "Downloading Docker image updates...")
docker-compose pull
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS pull

# Launch the containers.
echo -e $(status_message "Starting Docker containers...")
docker-compose up -d >/dev/null
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS up -d >/dev/null

# Set up WordPress Development site.
# Note: we don't bother installing the test site right now, because that's
Expand All @@ -39,8 +39,8 @@ docker-compose up -d >/dev/null

# Install the 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 $WP_VERSION false > /dev/null
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm wordpress_phpunit /app/bin/install-wp-tests.sh wordpress_test root example mysql $WP_VERSION false > /dev/null

# Install Composer. This is only used to run WordPress Coding Standards checks.
echo -e $(status_message "Installing and updating Composer modules...")
docker-compose run --rm composer install
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm composer install
22 changes: 12 additions & 10 deletions bin/install-wordpress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ set -e
# Gutenberg script includes.
. "$(dirname "$0")/includes.sh"

# Set up environment variables
. "$(dirname "$0")/bootstrap-env.sh"

# These are the containers and values for the development site.
CLI='cli'
CONTAINER='wordpress'
SITE_TITLE='Gutenberg Dev'
WP_VERSION=${WP_VERSION-latest}

# If we're installing/re-installing the test site, change the containers used.
if [ "$1" == '--e2e_tests' ]; then
Expand All @@ -20,15 +22,15 @@ if [ "$1" == '--e2e_tests' ]; then

if ! docker ps | grep -q $CONTAINER; then
echo -e $(error_message "WordPress e2e tests run in their own Docker container, but that container wasn't found.")
echo "Please restart your Docker containers by running 'docker-compose down && docker-compose up -d' or"
echo "Please restart your Docker containers by running 'docker-compose $DOCKER_COMPOSE_FILE_OPTIONS down && docker-compose $DOCKER_COMPOSE_FILE_OPTIONS up -d' or"
echo "by running './bin/setup-local-env.sh' again."
echo ""
exit 1
fi
fi

# Get the host port for the WordPress container.
HOST_PORT=$(docker-compose port $CONTAINER 80 | awk -F : '{printf $2}')
HOST_PORT=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS port $CONTAINER 80 | awk -F : '{printf $2}')

# Wait until the Docker containers are running and the WordPress site is
# responding to requests.
Expand All @@ -43,27 +45,27 @@ echo ''
# dirty up the tests.
if [ "$1" == '--e2e_tests' ]; then
echo -e $(status_message "Resetting test database...")
docker-compose run --rm $CLI db reset --yes >/dev/null
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CLI db reset --yes >/dev/null
fi

# Install WordPress.
echo -e $(status_message "Installing WordPress...")
# The `-u 33` flag tells Docker to run the command as a particular user and
# prevents permissions errors. See: https://github.com/WordPress/gutenberg/pull/8427#issuecomment-410232369
docker-compose run --rm -u 33 $CLI core install --title="$SITE_TITLE" --admin_user=admin --admin_password=password [email protected] --skip-email --url=http://localhost:$HOST_PORT >/dev/null
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI core install --title="$SITE_TITLE" --admin_user=admin --admin_password=password [email protected] --skip-email --url=http://localhost:$HOST_PORT >/dev/null

if [ "$WP_VERSION" == "latest" ]; then
# Check for WordPress updates, to make sure we're running the very latest version.
docker-compose run --rm -u 33 $CLI core update >/dev/null
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI core update >/dev/null
fi

# 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)
CURRENT_URL=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm $CLI option get siteurl)
if [ "$CURRENT_URL" != "http://localhost:$HOST_PORT" ]; then
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
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CLI option update home "http://localhost:$HOST_PORT" >/dev/null
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CLI option update siteurl "http://localhost:$HOST_PORT" >/dev/null
fi

# Activate Gutenberg.
echo -e $(status_message "Activating Gutenberg...")
docker-compose run --rm $CLI plugin activate gutenberg >/dev/null
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CLI plugin activate gutenberg >/dev/null
8 changes: 6 additions & 2 deletions bin/run-wp-unit-tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash


# Set up environment variables
. "$(dirname "$0")/bootstrap-env.sh"

cd "$(dirname "$0")/../"

export PATH="$HOME/.composer/vendor/bin:$PATH"
Expand Down Expand Up @@ -29,8 +33,8 @@ fi

echo Running with the following versions:
if [[ $DOCKER = "true" ]]; then
docker-compose run --rm wordpress_phpunit php -v
docker-compose run --rm wordpress_phpunit phpunit --version
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm wordpress_phpunit php -v
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm wordpress_phpunit phpunit --version
else
php -v
phpunit --version
Expand Down
5 changes: 4 additions & 1 deletion bin/setup-local-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Exit if any command fails
set -e

# Set up environment variables
. "$(dirname "$0")/bootstrap-env.sh"

# Include useful functions
. "$(dirname "$0")/includes.sh"

Expand All @@ -23,7 +26,7 @@ cd "$(dirname "$0")/.."
`---'
EOT

CURRENT_URL=$(docker-compose run -T --rm cli option get siteurl)
CURRENT_URL=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm cli option get siteurl)

echo -e "\nWelcome to...\n"
echo -e "\033[95m$GUTENBERG\033[0m"
Expand Down
12 changes: 12 additions & 0 deletions docker-compose-localdev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.1'

services:

wordpress:
volumes:
- ./wordpress:/var/www/html

cli:
image: wordpress:cli
volumes:
- ./wordpress:/var/www/html

1 comment on commit 29ccdcb

@force2reckin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x

Please sign in to comment.