Skip to content

Commit 657784d

Browse files
committed
simplify wp setup script
1 parent 2586bb0 commit 657784d

File tree

2 files changed

+113
-58
lines changed

2 files changed

+113
-58
lines changed

wp-plugin-test-env.sh

Lines changed: 0 additions & 58 deletions
This file was deleted.

wp-up.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/usr/bin/sh
2+
set -e
3+
4+
# sets up a WordPress development environment in Docker for the current dir
5+
6+
# requires docker, curl
7+
8+
# WordPress Configuration
9+
10+
wp_user="admin"
11+
wp_pass="pass"
12+
13+
14+
## That's all, stop editing! Happy developing. ##
15+
16+
cwd=$(pwd)
17+
cwd_name=$(basename $(pwd))
18+
19+
db_container="wp-db-$cwd_name"
20+
wp_container="wp-$cwd_name"
21+
22+
if [ -z "$1" ]; then
23+
mount_target="/opt/$cwd_name"
24+
post_setup(){
25+
:
26+
}
27+
message(){
28+
echo -e "\tThis directory is mounted in /opt/$cwd_name"
29+
}
30+
fi
31+
32+
# TODO instead of passing args detect what the user wants - it's WordPress
33+
34+
if [ "$1" = "plugin" ]; then
35+
name=$cwd_name; # TODO detect from index.php plugin.php ${cwd_name}.php etc
36+
mount_target="/var/www/html/wp-content/plugins/$name"
37+
post_setup(){
38+
docker exec -d $wp_container wp --allow-root plugin activate $cwd_name
39+
}
40+
message(){
41+
echo -e "\tThe $name plugin was installed and activated"
42+
}
43+
fi
44+
45+
if [ "$1" = "theme" ]; then
46+
name=$cwd_name; # TODO detect from functions.php
47+
mount_target="/var/www/html/wp-content/themes/$name"
48+
post_setup(){
49+
docker exec -d $wp_container wp --allow-root theme activate $cwd_name
50+
}
51+
message(){
52+
echo -e "\tThe $name theme was installed and activated"
53+
}
54+
fi
55+
56+
# TODO better ascii art
57+
58+
echo
59+
echo -e "\t###################################################"
60+
echo -e "\t# #"
61+
echo -e "\t# Fixing up that nice dev env in docker ... #"
62+
echo -e "\t# #"
63+
echo -e "\t###################################################"
64+
echo
65+
echo
66+
67+
# TODO persist database to hidden folder
68+
docker run -d \
69+
--name $db_container \
70+
-e MYSQL_ROOT_PASSWORD='root' \
71+
--restart unless-stopped \
72+
mariadb >/dev/null # 2>&1
73+
74+
# TODO persist uploads/media to hidden folder
75+
docker run -d \
76+
--name $wp_container \
77+
-p 127.0.0.1::80 \
78+
--link $db_container:mysql \
79+
--restart unless-stopped \
80+
-v $(pwd):$mount_target \
81+
ak05/wordpress-test >/dev/null # 2>&1
82+
83+
port=$(docker ps --filter name=$wp_container --format="{{.Ports}}" \
84+
| sed 's/127\.0\.0\.1:\([0-9]\+\).*$/\1/')
85+
86+
# wait until environment is launched
87+
until $(curl -LNs 127.0.0.1:$port | grep -qi '<html') ; do
88+
sleep 1
89+
done
90+
91+
docker exec -d $wp_container wp --allow-root core install \
92+
--url="localhost:$port" \
93+
--title="Testing $cwd_name" \
94+
--admin_user="$wp_user" \
95+
--admin_password="$wp_pass" \
96+
--admin_email="$wp_email"
97+
98+
post_setup
99+
100+
echo -e "\tWordPress running on http://localhost:$port"
101+
echo
102+
message
103+
echo
104+
echo -e "\tAdministrator Credentials:"
105+
echo
106+
echo -e "\tusername: $wp_user"
107+
echo -e "\tpassword: $wp_pass"
108+
echo
109+
echo
110+
echo -e "\tget a bash shell on the container by running:"
111+
echo
112+
echo -e "\tdocker exec -it $wp_container bash"
113+
echo

0 commit comments

Comments
 (0)