Skip to content

Commit

Permalink
Misc housekeeping tasks / issue resolutions (visiblevc#164)
Browse files Browse the repository at this point in the history
* feat: bump default theme install to "twentytwenty"

* fix: include "must-use" plugins in plugin volume check

* chore: format run.sh with shfmt

* feat: increase upload_max_filesize to 50M

See: visiblevc#160 (comment)

Closes visiblevc#160

* fix: add --create-dirs to curl in dockerfile

* chore: fix contradicting compose file examples

Closes visiblevc#152

* fix: improve plugin volumes check to also include plugins that are a single php file
  • Loading branch information
dsifford authored Nov 15, 2019
1 parent 7f6af33 commit bed7fc0
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 56 deletions.
20 changes: 12 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,26 @@ RUN echo "deb http://ftp.debian.org/debian $(sed -n 's/^VERSION=.*(\(.*\)).*/\1/
zip \
&& docker-php-ext-enable imagick \
&& docker-php-ext-enable redis \
&& { \
echo 'memory_limit = 512M'; \
# See https://github.com/visiblevc/wordpress-starter/issues/160#issuecomment-544561961
echo 'upload_max_filesize = 50M'; \
} > /usr/local/etc/php/php.ini \
# See https://secure.php.net/manual/en/opcache.installation.php
&& echo 'memory_limit = 512M' >> /usr/local/etc/php/php.ini \
&& { \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=2'; \
echo 'opcache.fast_shutdown=1'; \
echo 'opcache.enable_cli=1'; \
echo 'opcache.memory_consumption = 128'; \
echo 'opcache.interned_strings_buffer = 8'; \
echo 'opcache.max_accelerated_files = 4000'; \
echo 'opcache.revalidate_freq = 2'; \
echo 'opcache.fast_shutdown = 1'; \
echo 'opcache.enable_cli = 1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini \
&& sed -i 's/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf \
# Fixes issue where error is logged stating apache could not resolve the
# fully qualified domain name
&& echo 'ServerName localhost' > /etc/apache2/conf-available/fqdn.conf \
# Grab and install wp-cli from remote
&& curl \
&& curl --create-dirs \
-o /usr/local/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
-o /etc/bash_completion.d/wp-cli https://raw.githubusercontent.com/wp-cli/wp-cli/master/utils/wp-completion.bash \
&& a2enconf fqdn \
Expand Down
67 changes: 39 additions & 28 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,46 @@ The only thing you need to get started is a `docker-compose.yml` file:
```yml
version: '3'
services:
wordpress:
image: visiblevc/wordpress:latest
ports:
- 8080:80
- 443:443
volumes:
- ./data:/data # Required if importing an existing database
- ./tweaks.ini:/usr/local/etc/php/conf.d/tweaks.ini # Optional tweaks to the php.ini config
- ./wp-content/uploads:/app/wp-content/uploads
- ./yourplugin:/app/wp-content/plugins/yourplugin # Plugin development
- ./yourtheme:/app/wp-content/themes/yourtheme # Theme development
environment:
DB_HOST: db # must match db service name below
DB_NAME: wordpress
DB_PASS: root # must match below
PLUGINS: >-
academic-bloggers-toolkit,
co-authors-plus,
[WP-API]https://github.com/WP-API/WP-API/archive/master.zip,
URL_REPLACE: localhost:8080
WP_DEBUG: 'true'
db:
image: mysql:5.7 # or mariadb:10
volumes:
- data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
wordpress:
image: visiblevc/wordpress

# required for mounting bindfs
cap_add:
- SYS_ADMIN
devices:
- /dev/fuse
# required on certain cloud hosts
security_opt:
- apparmor:unconfined

ports:
- 8080:80
- 443:443
volumes:
- ./data:/data
- ./scripts:/docker-entrypoint-initwp.d
environment:
DB_NAME: wordpress
DB_PASS: root
PLUGINS: >-
academic-bloggers-toolkit
co-authors-plus
[WP-API]https://github.com/WP-API/WP-API/archive/master.zip
db:
image: mariadb:10 # or mysql:5.7
volumes:
- data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root

phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 22222:80

volumes:
data: {}
data:
```
**Need PHPMyAdmin? Add it as a service**
Expand Down
2 changes: 1 addition & 1 deletion example/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3"
version: '3'
services:
wordpress:
image: visiblevc/wordpress
Expand Down
50 changes: 31 additions & 19 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
# shellcheck disable=SC1091

if ! sudo mount -a 2>/dev/null; then
if ! sudo mount -a 2> /dev/null; then
printf '\e[1;31mERROR:\e[0m %s' \
'Container running with improper privileges.
'Container running with improper privileges.
Be sure your service is configured with the following options:
___
Expand Down Expand Up @@ -80,7 +80,7 @@ core install:
rewrite structure:
hard: true
" >~/.wp-cli/config.yml
" > ~/.wp-cli/config.yml

# Apache config adustments
sudo sed -i \
Expand All @@ -98,7 +98,7 @@ main() {
--host="${DB_HOST:-db}" \
--user="${DB_USER:-root}" \
--password="${DB_PASS:-root}" \
--silent >/dev/null; do
--silent > /dev/null; do
sleep 1
done

Expand Down Expand Up @@ -153,7 +153,8 @@ init() {
s/.*\[\(.*\)\]\([^[:blank:]]*\).*/\1\n\2/p # Matches [key]value form
t # If previous match succeeds, skip to end
{p; p;} # Assumes normal form
' <<<"$raw_line")
' <<< "$raw_line"
)
plugin_deps[${keyvalue[0]}]="${keyvalue[1]}"
done

Expand All @@ -163,13 +164,14 @@ init() {
s/.*\[\(.*\)\]\([^[:blank:]]*\).*/\1\n\2/p # Matches [key]value form
t # If previous match succeeds, skip to end
{p; p;} # Assumes normal form
' <<<"$raw_line")
' <<< "$raw_line"
)
theme_deps[${keyvalue[0]}]="${keyvalue[1]}"
done

# If no theme dependencies or volumes exist, fall back to default
if [[ ${#theme_deps[@]} == 0 && $(check_volumes -t) == "" ]]; then
theme_deps[twentynineteen]=twentynineteen
theme_deps[twentytwenty]=twentytwenty
fi

sudo chown -R admin:admin /app
Expand All @@ -181,12 +183,12 @@ init() {
}

check_database() {
wp core is-installed 2>/dev/null && return
wp core is-installed 2> /dev/null && return

wp --color db create |& logger

declare data_path
data_path=$(find /data -name '*.sql' -print -quit 2>/dev/null)
data_path=$(find /data -name '*.sql' -print -quit 2> /dev/null)
if [[ ! "$data_path" ]]; then
wp --color core install |& logger
return
Expand Down Expand Up @@ -221,7 +223,8 @@ check_plugins() {
mapfile -t plugin_values < <(
for key in "${plugin_keys[@]}"; do
echo "${plugin_deps[$key]}"
done)
done
)

if [[ "${#plugin_keys[@]}" -gt 0 ]]; then
wp --color plugin install "${plugin_values[@]}" |& logger
Expand Down Expand Up @@ -258,7 +261,8 @@ check_themes() {
mapfile -t theme_values < <(
for key in "${theme_keys[@]}"; do
echo "${theme_deps[$key]}"
done)
done
)

if [[ "${#theme_values[@]}" -gt 0 ]]; then
wp --color theme install "${theme_values[@]}" |& logger
Expand All @@ -282,19 +286,27 @@ check_volumes() {
if [[ ! -f ~/.dockercache ]]; then
{
(
find /app/wp-content/plugins/* \
-maxdepth 0 \
find /app/wp-content/{plugins,mu-plugins} \
-maxdepth 1 \
-type d \
-printf 'plugin\t%f\n' 2>/dev/null
-printf 'plugin\t%f\n' 2> /dev/null
) &
(
find /app/wp-content/themes/* \
-maxdepth 0 \
find /app/wp-content/{plugins,mu-plugins} \
-maxdepth 1 \
-type f \
-name '*.php' \
-exec basename '{}' .php \; \
| awk '{ print "plugin\t" $0 }'
) &
(
find /app/wp-content/themes \
-maxdepth 1 \
-type d \
-printf 'theme\t%f\n' 2>/dev/null
-printf 'theme\t%f\n' 2> /dev/null
) &
wait
} >~/.dockercache
} > ~/.dockercache
fi

declare opt OPTIND
Expand Down Expand Up @@ -322,7 +334,7 @@ declare -i term_width=70
h1() {
declare border padding text
border='\e[1;34m'"$(printf '=%.0s' $(seq 1 "$term_width"))"'\e[0m'
padding="$(printf ' %.0s' $(seq 1 $(((term_width - $(wc -m <<<"$*")) / 2))))"
padding="$(printf ' %.0s' $(seq 1 $(((term_width - $(wc -m <<< "$*")) / 2))))"
text="\\e[1m$*\\e[0m"
echo -e "$border"
echo -e "${padding}${text}${padding}"
Expand Down

0 comments on commit bed7fc0

Please sign in to comment.