From b9d745fc6a2c90ffc3cef6c439e647a2da0bf109 Mon Sep 17 00:00:00 2001 From: "Matthew Riley MacPherson (tofumatt)" Date: Thu, 26 Jul 2018 02:44:03 +0100 Subject: [PATCH] feat: Add SSL development option (fix #8211) --- CONTRIBUTING.md | 9 +++++++-- bin/install-wordpress.sh | 18 +++++++++++++----- docker-compose.yml | 8 ++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 69c7174fea19fd..cdf0019b4eab55 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,9 +38,14 @@ cd gutenberg ``` Then, run a setup script to check if docker and node are configured properly and starts the local WordPress instance. You may need to run this script multiple times if prompted. -``` +```bash ./bin/setup-local-env.sh -``` +``` + +If you want to access the site via HTTPS, you can set up your local environment to use SSL: +```bash +./bin/setup-local-env.sh --ssl +``` If everything was successful, you'll see the following ascii art: ``` diff --git a/bin/install-wordpress.sh b/bin/install-wordpress.sh index 773fe1f1f43e6a..524c5e790fbeea 100755 --- a/bin/install-wordpress.sh +++ b/bin/install-wordpress.sh @@ -26,13 +26,21 @@ if [ "$1" == '--e2e_tests' ]; then fi fi +# By default we use HTTP to serve the site, but we allow SSL sites with a +# flag. +PROTOCOL='http' +if [ "$1" == '--ssl' ]; then + HOST_PORT=$(docker-compose port wordpress 443 | awk -F : '{printf $2}') + PROTOCOL='https' +fi + # Get the host port for the WordPress container. HOST_PORT=$(docker-compose port $CONTAINER 80 | awk -F : '{printf $2}') # Wait until the Docker containers are running and the WordPress site is # responding to requests. echo -en $(status_message "Attempting to connect to WordPress...") -until $(curl -L http://localhost:$HOST_PORT -so - 2>&1 | grep -q "WordPress"); do +until $(curl -L --insecure $PROTOCOL://localhost:$HOST_PORT -so - 2>&1 | grep -q "WordPress"); do echo -n '.' sleep 5 done @@ -47,15 +55,15 @@ fi # Install WordPress. echo -e $(status_message "Installing WordPress...") -docker-compose run --rm $CLI core install --title="$SITE_TITLE" --admin_user=admin --admin_password=password --admin_email=test@test.com --skip-email --url=http://localhost:$HOST_PORT >/dev/null +docker-compose run --rm $CLI core install --title="$SITE_TITLE" --admin_user=admin --admin_password=password --admin_email=test@test.com --skip-email --url=$PROTOCOL://localhost:$HOST_PORT >/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 # 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-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 +if [ "$CURRENT_URL" != "$PROTOCOL://localhost:$HOST_PORT" ]; then + docker-compose run --rm $CLI option update home "$PROTOCOL://localhost:$HOST_PORT" >/dev/null + docker-compose run --rm $CLI option update siteurl "$PROTOCOL://localhost:$HOST_PORT" >/dev/null fi # Activate Gutenberg. diff --git a/docker-compose.yml b/docker-compose.yml index 0e8dbad05597ac..fb0d4db66b0e2c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ services: image: wordpress ports: - 8888:80 + - 9999:443 environment: WORDPRESS_DB_PASSWORD: example ABSPATH: /usr/src/wordpress/ @@ -14,6 +15,13 @@ services: - .:/var/www/html/wp-content/plugins/gutenberg - ./test/e2e/test-plugins:/var/www/html/wp-content/plugins/gutenberg-test-plugins - ./test/e2e/test-mu-plugins:/var/www/html/wp-content/mu-plugins + command: | + /bin/bash -c " + apt-get update && \ + apt-get install -y --no-install-recommends ssl-cert && \ + a2enmod ssl && \ + a2ensite default-ssl && \ + docker-entrypoint.sh apache2-foreground" cli: image: wordpress:cli