-
Notifications
You must be signed in to change notification settings - Fork 806
/
Copy pathrun.sh
executable file
·137 lines (115 loc) · 4.68 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
set -e
# This file is run for the Docker image defined in Dockerfile.
# These commands will be run each time the container is run.
#
# If you modify anything here, remember to build the image again by running:
# jetpack docker build-image
user="${APACHE_RUN_USER:-www-data}"
group="${APACHE_RUN_GROUP:-www-data}"
# Download WordPress
[ -f /var/www/html/xmlrpc.php ] || wp --allow-root core download
# Configure WordPress
if [ ! -f /var/www/html/wp-config.php ]; then
echo "Creating wp-config.php ..."
# Loop until wp cli exits with 0
# because if running the containers for the first time,
# the mysql container will reject connections until it has set the database data
# See "No connections until MySQL init completes" in https://hub.docker.com/_/mysql/
times=15
i=1
while [ "$i" -le "$times" ]; do
sleep 3
wp --allow-root config create \
--dbhost=${MYSQL_HOST} \
--dbname=${MYSQL_DATABASE} \
--dbuser=${MYSQL_USER} \
--dbpass=${MYSQL_PASSWORD} \
&& break
[ ! $? -eq 0 ] || break;
echo "Waiting for creating wp-config.php until mysql is ready to receive connections"
(( i++ ))
done
echo "Setting other wp-config.php constants..."
wp --allow-root config set WP_DEBUG true --raw --type=constant
wp --allow-root config set WP_DEBUG_LOG true --raw --type=constant
wp --allow-root config set WP_DEBUG_DISPLAY false --raw --type=constant
wp --allow-root config set SCRIPT_DEBUG true --raw --type=constant
# Respecting Dockerfile-forwarded environment variables
# Allow to be reverse-proxied from https
wp --allow-root config set "_SERVER['HTTPS']" "isset( \$_SERVER['HTTP_X_FORWARDED_PROTO'] ) && \$_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ? 'on' : NULL" \
--raw \
--type=variable
# Allow this installation to run on http or https.
wp --allow-root config set DOCKER_REQUEST_URL \
"( ! empty( \$_SERVER['HTTPS'] ) ? 'https://' : 'http://' ) . ( ! empty( \$_SERVER['HTTP_HOST'] ) ? \$_SERVER['HTTP_HOST'] : 'localhost' )" \
--raw \
--type=constant
wp --allow-root config set WP_SITEURL "DOCKER_REQUEST_URL" --raw --type=constant
wp --allow-root config set WP_HOME "DOCKER_REQUEST_URL" --raw --type=constant
# Tell WP-CONFIG we're in a docker instance.
wp --allow-root config set JETPACK_DOCKER_ENV true --raw --type=constant
fi
# Copy single site htaccess if none is present
if [ ! -f /var/www/html/.htaccess ]; then
cp /var/lib/jetpack-config/htaccess /var/www/html/.htaccess
fi
# Clean up old method of including psysh (used from 2019 until 2021)
if [[ -e /var/www/html/wp-cli.yml ]] && grep -q '^require: /usr/local/bin/psysh$' /var/www/html/wp-cli.yml; then
TMP="$(grep -v '^require: /usr/local/bin/psysh$' /var/www/html/wp-cli.yml || true)"
if [[ -z "$TMP" ]]; then
rm /var/www/html/wp-cli.yml
else
echo "$TMP" > /var/www/html/wp-cli.yml
fi
fi
if [ "$COMPOSE_PROJECT_NAME" == "jetpack_dev" ] ; then
# If we don't have the wordpress test helpers, download them
if [ ! -d /tmp/wordpress-develop/tests ]; then
# Get latest WordPress unit-test helper files
svn co \
https://develop.svn.wordpress.org/trunk/tests/phpunit/data \
/tmp/wordpress-develop/tests/phpunit/data \
--trust-server-cert \
--non-interactive
svn co \
https://develop.svn.wordpress.org/trunk/tests/phpunit/includes \
/tmp/wordpress-develop/tests/phpunit/includes \
--trust-server-cert \
--non-interactive
fi
# Create a wp-tests-config.php if there's none currently
if [ ! -f /tmp/wordpress-develop/wp-tests-config.php ]; then
cp /var/lib/jetpack-config/wp-tests-config.php /tmp/wordpress-develop/wp-tests-config.php
fi
# Symlink jetpack into wordpress-develop for WP >= 5.6-beta1
WP_TESTS_JP_DIR="/tmp/wordpress-develop/tests/phpunit/data/plugins/jetpack"
if [ ! -L $WP_TESTS_JP_DIR ] || [ ! -e $WP_TESTS_JP_DIR ]; then
ln -s /var/www/html/wp-content/plugins/jetpack $WP_TESTS_JP_DIR
fi
fi
for DIR in /usr/local/src/jetpack-monorepo/projects/plugins/*; do
[ -d "$DIR" ] || continue # We are only interested in directories, e.g. different plugins.
PLUGIN="$(basename $DIR)"
# Symlink plugins into the wp-content dir.
if [ ! -e /var/www/html/wp-content/plugins/"$PLUGIN" ]; then
echo "Linking the $PLUGIN plugin."
ln -s "$DIR" /var/www/html/wp-content/plugins/"$PLUGIN"
fi
done
WP_HOST_PORT=":$HOST_PORT"
if [ 80 -eq "$HOST_PORT" ]; then
WP_HOST_PORT=""
fi
chmod +x /var/scripts/run-extras.sh && . /var/scripts/run-extras.sh
# Clean up pre-existing Apache pid file
APACHE_PID_FILE="/run/apache2/apache2.pid"
if [ -e $APACHE_PID_FILE ]; then
rm -f $APACHE_PID_FILE
fi
echo
echo "Open http://${WP_DOMAIN}${WP_HOST_PORT}/ to see your site!"
echo
# Run apache in the foreground so the container keeps running
echo "Running Apache in the foreground"
apachectl -D FOREGROUND