4
4
set -e
5
5
6
6
# Common variables.
7
- DOCKER_COMPOSE_FILE_OPTIONS=" -f $( dirname " $0 " ) /docker-compose.yml"
8
7
WP_DEBUG=${WP_DEBUG-true}
9
8
SCRIPT_DEBUG=${SCRIPT_DEBUG-true}
9
+ WP_VERSION=${WP_VERSION-" latest" }
10
10
11
11
# Include useful functions
12
12
. " $( dirname " $0 " ) /includes.sh"
13
13
14
- # These are the containers and values for the development site.
15
- CLI=' cli'
16
- CONTAINER=' wordpress'
17
- SITE_TITLE=' AMP Dev'
14
+ # Make sure Docker containers are running
15
+ dc up -d > /dev/null 2>&1
18
16
19
17
# Get the host port for the WordPress container.
20
- HOST_PORT=$( docker-compose $DOCKER_COMPOSE_FILE_OPTIONS port $CONTAINER 80 | awk -F : ' {printf $2}' )
18
+ HOST_PORT=$( dc port $CONTAINER 80 | awk -F : ' {printf $2}' )
21
19
22
20
# Wait until the Docker containers are running and the WordPress site is
23
21
# responding to requests.
@@ -32,72 +30,92 @@ echo ''
32
30
# dirty up the tests.
33
31
if [ " $1 " == ' --reset-site' ]; then
34
32
echo -e $( status_message " Resetting test database..." )
35
- docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI db reset --yes --quiet
33
+ wp db reset --yes --quiet
34
+ fi
35
+
36
+ if [ ! -z " $WP_VERSION " ] && [ " $WP_VERSION " != " latest" ]; then
37
+ # Potentially downgrade WordPress
38
+ echo -e $( status_message " Downloading WordPress version $WP_VERSION ..." )
39
+ wp core download --version=${WP_VERSION} --force --quiet
36
40
fi
37
41
38
42
# Install WordPress.
39
43
echo -e $( status_message " Installing WordPress..." )
40
- # The `-u 33` flag tells Docker to run the command as a particular user and
41
- # prevents permissions errors. See: https://github.com/WordPress/gutenberg/pull/8427#issuecomment-410232369
42
- docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI core install --title=" $SITE_TITLE " --admin_user=admin --admin_password=password --admin_email=test@test.com --skip-email --url=http://localhost:$HOST_PORT --quiet
43
-
44
- if [ " $E2E_ROLE " = " author" ]; then
45
- echo -e $( status_message " Creating an additional author user for testing..." )
46
- # Create an additional author user for testing.
47
- docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI user create author author@example.com --role=author --user_pass=authpass --quiet
48
- # Assign the existing Hello World post to the author.
49
- docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI post update 1 --post_author=2 --quiet
50
- fi
44
+ wp core install --title=" $SITE_TITLE " --admin_user=admin --admin_password=password --admin_email=test@test.com --skip-email --url=http://localhost:$HOST_PORT --quiet
45
+
46
+ # Create additional users.
47
+ echo -e $( status_message " Creating additional users..." )
48
+ wp user create editor editor@example.com --role=editor --user_pass=password --quiet
49
+ echo -e $( status_message " Editor created! Username: editor Password: password" )
50
+ wp user create author author@example.com --role=author --user_pass=password --quiet
51
+ echo -e $( status_message " Author created! Username: author Password: password" )
52
+ wp user create contributor contributor@example.com --role=contributor --user_pass=password --quiet
53
+ echo -e $( status_message " Contributor created! Username: contributor Password: password" )
54
+ wp user create subscriber subscriber@example.com --role=subscriber --user_pass=password --quiet
55
+ echo -e $( status_message " Subscriber created! Username: subscriber Password: password" )
51
56
52
57
# Make sure the uploads and upgrade folders exist and we have permissions to add files.
53
58
echo -e $( status_message " Ensuring that files can be uploaded..." )
54
- docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER mkdir -p /var/www/html/wp-content/uploads /var/www/html/wp-content/upgrade
55
- docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER chmod 767 /var/www/html/wp-content/plugins /var/www/html/wp-config.php /var/www/html/wp-settings.php /var/www/html/wp-content/uploads /var/www/html/wp-content/upgrade
56
-
57
- CURRENT_WP_VERSION=$( docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm $CLI core version)
59
+ container mkdir -p \
60
+ /var/www/html/wp-content/uploads \
61
+ /var/www/html/wp-content/upgrade
62
+ container chmod 767 \
63
+ /var/www/html/wp-content \
64
+ /var/www/html/wp-content/plugins \
65
+ /var/www/html/wp-config.php \
66
+ /var/www/html/wp-settings.php \
67
+ /var/www/html/wp-content/uploads \
68
+ /var/www/html/wp-content/upgrade
69
+
70
+ CURRENT_WP_VERSION=$( wp core version | tr -d ' \r' )
58
71
echo -e $( status_message " Current WordPress version: $CURRENT_WP_VERSION ..." )
59
72
60
73
if [ " $WP_VERSION " == " latest" ]; then
61
74
# Check for WordPress updates, to make sure we're running the very latest version.
62
75
echo -e $( status_message " Updating WordPress to the latest version..." )
63
- docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI core update --quiet
76
+ wp core update --quiet
64
77
echo -e $( status_message " Updating The WordPress Database..." )
65
- docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI core update-db --quiet
78
+ wp core update-db --quiet
66
79
fi
67
80
68
81
# If the 'wordpress' volume wasn't during the down/up earlier, but the post port has changed, we need to update it.
69
82
echo -e $( status_message " Checking the site's url..." )
70
- CURRENT_URL=$( docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm $CLI option get siteurl)
83
+ CURRENT_URL=$( wp option get siteurl)
71
84
if [ " $CURRENT_URL " != " http://localhost:$HOST_PORT " ]; then
72
- docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI option update home " http://localhost:$HOST_PORT " --quiet
73
- docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI option update siteurl " http://localhost:$HOST_PORT " --quiet
85
+ wp option update home " http://localhost:$HOST_PORT " --quiet
86
+ wp option update siteurl " http://localhost:$HOST_PORT " --quiet
74
87
fi
75
88
76
89
# Install a dummy favicon to avoid 404 errors.
77
90
echo -e $( status_message " Installing a dummy favicon..." )
78
- docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER touch /var/www/html/favicon.ico
91
+ container touch /var/www/html/favicon.ico
92
+ container chmod 767 /var/www/html/favicon.ico
79
93
80
94
# Activate AMP plugin.
81
95
echo -e $( status_message " Activating AMP plugin..." )
82
- docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI plugin activate amp --quiet
96
+ wp plugin activate amp --quiet
83
97
84
98
# Install & activate Gutenberg plugin.
85
99
echo -e $( status_message " Installing and activating Gutenberg plugin..." )
86
- # todo: Use `wp plugin install --activate` once WP-CLI is updated, see https://github.com/wp-cli/extension-command/issues/176.
87
- docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI plugin install gutenberg --activate --quiet
88
- docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI plugin activate gutenberg --quiet
100
+ wp plugin install gutenberg --activate --force --quiet
101
+
102
+ # Set pretty permalinks.
103
+ echo -e $( status_message " Setting permalink structure..." )
104
+ wp rewrite structure ' %postname%' --hard --quiet
89
105
90
106
# Configure site constants.
91
107
echo -e $( status_message " Configuring site constants..." )
92
- WP_DEBUG_CURRENT=$( docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm -u 33 $CLI config get --type=constant --format=json WP_DEBUG)
108
+ WP_DEBUG_CURRENT=$( wp config get --type=constant --format=json WP_DEBUG | tr -d ' \r' )
109
+
93
110
if [ " $WP_DEBUG " != $WP_DEBUG_CURRENT ]; then
94
- docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI config set WP_DEBUG $WP_DEBUG --raw --type=constant --quiet
95
- WP_DEBUG_RESULT=$( docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm -u 33 $CLI config get --type=constant --format=json WP_DEBUG)
111
+ wp config set WP_DEBUG $WP_DEBUG --raw --type=constant --quiet
112
+ WP_DEBUG_RESULT=$( wp config get --type=constant --format=json WP_DEBUG | tr -d ' \r ' )
96
113
echo -e $( status_message " WP_DEBUG: $WP_DEBUG_RESULT ..." )
97
114
fi
98
- SCRIPT_DEBUG_CURRENT=$( docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm -u 33 $CLI config get --type=constant --format=json SCRIPT_DEBUG)
115
+
116
+ SCRIPT_DEBUG_CURRENT=$( wp config get --type=constant --format=json SCRIPT_DEBUG | tr -d ' \r' )
99
117
if [ " $SCRIPT_DEBUG " != $SCRIPT_DEBUG_CURRENT ]; then
100
- docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI config set SCRIPT_DEBUG $SCRIPT_DEBUG --raw --type=constant --quiet
101
- SCRIPT_DEBUG_RESULT=$( docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm -u 33 $CLI config get --type=constant --format=json SCRIPT_DEBUG)
118
+ wp config set SCRIPT_DEBUG $SCRIPT_DEBUG --raw --type=constant --quiet
119
+ SCRIPT_DEBUG_RESULT=$( wp config get --type=constant --format=json SCRIPT_DEBUG | tr -d ' \r ' )
102
120
echo -e $( status_message " SCRIPT_DEBUG: $SCRIPT_DEBUG_RESULT ..." )
103
121
fi
0 commit comments