Skip to content

Commit b78529b

Browse files
committed
updating the stack
1 parent fabeff4 commit b78529b

30 files changed

+11863
-5605
lines changed

.dockerignore

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
*
2-
!code/themes
3-
!code/plugins
4-
!data/php/multisite.htaccess
5-
!data/php/docker-entrypoint.sh
2+
wp-content/themes/**/src
3+
!wp-content/themes
4+
!wp-content/plugins
5+
!data/docker-entrypoint.sh
6+
!data/.well-known
7+
!data/wpcli-user.sh
8+
!data/cron.conf
9+
!data/multisite.htaccess
10+
!data/uploads.ini
11+

.gitignore

+32-23
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1-
.DS_Store
2-
/.htaccess
3-
/code/plugins/akismet
4-
/code/plugins/hello.php
5-
/code/plugins/index.php
6-
/code/tests/shots
7-
/code/themes/**/*.css.map
8-
/code/themes/**/*.js.map
9-
/code/themes/index.php
10-
/code/themes/twenty*
11-
/index.php
12-
/license.txt
13-
/local-config.php
14-
/npm-debug.log
15-
/readme.html
16-
/wp-*.php
17-
/wp-admin
18-
/wp-includes
19-
/xmlrpc.php
20-
data/db/.db
1+
/*
2+
data/mysql/.db
213
data/nginx/log
22-
data/uploads
23-
data/wordpress*
4+
data/wordpress
245
data/certs
25-
node_modules
6+
!.gitignore
7+
!.gitmodules
8+
!.dockerignore
9+
!.editorconfig
10+
!.gitlab-ci.yml
11+
!logo.png
12+
!changelog.md
13+
!LICENSE
14+
!deploy.sh
15+
!docker-compose.yml
16+
!Dockerfile
17+
!package.json
18+
!postcss.config.js
19+
!README.md
20+
!test.docker-compose.yml
21+
!tsconfig.json
22+
!webpack.config.js
23+
!wp-content
24+
wp-content/*
25+
!tests
26+
!wp-content/plugins
27+
!wp-content/themes
28+
wp-content/plugins/hello.php
29+
wp-content/plugins/akismet
30+
wp-content/themes/twenty*
31+
wp-content/themes/index.php
32+
!data/
33+
*.DS_Store
34+
!kubernetes

Dockerfile

+41-32
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,63 @@
1-
FROM php:7.1-apache
1+
FROM php:7.3-apache
2+
23
# install the PHP extensions we need
3-
RUN set -ex; \
4-
\
5-
apt-get update; \
6-
apt-get install -y \
7-
libjpeg-dev \
8-
libpng-dev \
9-
; \
10-
rm -rf /var/lib/apt/lists/*; \
11-
\
12-
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
13-
docker-php-ext-install gd mysqli opcache
14-
15-
RUN echo 'installing WP-CLI'; \
16-
curl -o /usr/local/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar; \
17-
chmod +x /usr/local/bin/wp
18-
# TODO consider removing the *-dev deps and only keeping the necessary lib* packages
4+
RUN apt-get update \
5+
&& apt-get install -y \
6+
libjpeg-dev \
7+
libpng-dev \
8+
sudo \
9+
&& rm -rf /var/lib/apt/lists/* \
10+
&& docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
11+
&& docker-php-ext-install gd mysqli opcache
12+
13+
RUN curl -o /usr/local/bin/wp-cli.phar https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
14+
COPY ./data/wpcli-user.sh /usr/local/bin/wp
15+
RUN chmod +x /usr/local/bin/wp
16+
RUN chmod +x /usr/local/bin/wp-cli.phar
1917

2018
# set recommended PHP.ini settings
2119
# see https://secure.php.net/manual/en/opcache.installation.php
2220
RUN { \
23-
echo 'opcache.memory_consumption=128'; \
24-
echo 'opcache.interned_strings_buffer=8'; \
25-
echo 'opcache.max_accelerated_files=4000'; \
26-
echo 'opcache.revalidate_freq=2'; \
27-
echo 'opcache.fast_shutdown=1'; \
28-
echo 'opcache.enable_cli=1'; \
21+
echo 'opcache.memory_consumption=128'; \
22+
echo 'opcache.interned_strings_buffer=8'; \
23+
echo 'opcache.max_accelerated_files=4000'; \
24+
echo 'opcache.revalidate_freq=2'; \
25+
echo 'opcache.fast_shutdown=1'; \
26+
echo 'opcache.enable_cli=1'; \
2927
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
3028

31-
RUN a2enmod rewrite expires
3229

33-
COPY ./code/themes /var/www/html/wp-content/themes
34-
COPY ./code/plugins /var/www/html/wp-content/plugins
30+
# Adding 404 injection protection
31+
# CVE-2007-0450
32+
RUN { \
33+
echo 'AllowEncodedSlashes NoDecode'; \
34+
echo 'ServerSignature Off'; \
35+
echo 'ServerTokens Prod'; \
36+
echo 'ErrorDocument 404 "404: The requested resource could not be found."'; \
37+
echo 'ErrorDocument 403 "403: Access Denied. The requested resource requires authentication."'; \
38+
} >> /etc/apache2/apache2.conf
39+
40+
RUN a2enmod rewrite expires headers
41+
42+
COPY ./wp-content/ /var/www/html/wp-content/
43+
COPY ./data/uploads.ini /usr/local/etc/php/conf.d/uploads.ini
3544

3645
VOLUME /var/www/html
3746

3847
EXPOSE 80
3948

40-
ENV WORDPRESS_VERSION 4.9.1
41-
ENV WORDPRESS_SHA1 5376cf41403ae26d51ca55c32666ef68b10e35a4
49+
ENV WORDPRESS_VERSION 5.2.4
4250

4351
RUN set -ex; \
44-
curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \
52+
curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \
4553
tar -xzf wordpress.tar.gz -C /usr/src/; \
4654
rm wordpress.tar.gz; \
4755
chown -R www-data:www-data /usr/src/wordpress
4856

49-
COPY ./data/php/multisite.htaccess /usr/src/wordpress/multisite.htaccess
50-
COPY ./data/php/docker-entrypoint.sh /usr/local/bin/
51-
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
57+
COPY ./data/multisite.htaccess /usr/src/wordpress/multisite.htaccess
58+
COPY ./data/docker-entrypoint.sh /usr/local/bin/
59+
COPY ./data/cron.conf /etc/crontabs/www-data
60+
RUN chmod 600 /etc/crontabs/www-data
5261

5362
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
5463
CMD ["apache2-foreground"]

code/themes/test/dist/scripts.min.js

-17
This file was deleted.

code/themes/test/functions.php

-12
This file was deleted.

data/cron.conf

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Cron configuration file, set to run WordPress cron once every minute
2+
* * * * * php /usr/src/wordpress/wp-cron.php

data/php/docker-entrypoint.sh renamed to data/docker-entrypoint.sh

+31-12
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,7 @@ EOPHP
126126
echo "$@" | sed -e 's/[\/&]/\\&/g'
127127
}
128128
php_escape() {
129-
local escaped="$(php -r 'var_export(('"$2"') $argv[1]);' -- "$1")"
130-
if [ "$2" = 'string' ] && [ "${escaped:0:1}" = "'" ]; then
131-
escaped="${escaped//$'\n'/"' + \"\\n\" + '"}"
132-
fi
133-
echo "$escaped"
129+
php -r 'var_export(('$2') $argv[1]);' -- "$1"
134130
}
135131
set_config() {
136132
key="$1"
@@ -220,12 +216,35 @@ EOPHP
220216
done
221217
fi
222218

223-
# if [ -z "${WORDPRESS_LOCAL_DEV+x}" ]; then
224-
# wp --allow-root core multisite-convert
225-
# mv .htaccess backup.htaccess
226-
# mv multisite.htaccess .htaccess
227-
# wp --allow-root search-replace "/blog/%year%/%monthnum%/%day%/%postname%/" "/%postname%" wp_options
228-
# wp --allow-root rewrite flush
229-
# fi
219+
if [ -z "${WORDPRESS_LOCAL_DEV+x}" ] && [ ! -f backup.htaccess ]; then
220+
wp core is-installed || wp core multisite-install --skip-config --title="test" --admin_email="[email protected]"
221+
mv .htaccess backup.htaccess
222+
mv multisite.htaccess .htaccess
223+
wp search-replace "/blog/%year%/%monthnum%/%day%/%postname%/" "blog/%postname%" wp_options
224+
wp rewrite flush
225+
fi
226+
227+
if [ -d "/var/www/html/wp-content/uploads/cache" ]; then
228+
chown -R www-data:www-data /var/www/html/wp-content/uploads/cache
229+
fi
230+
if [ -d "/var/www/html/wp-content/cache" ]; then
231+
chown -R www-data:www-data /var/www/html/wp-content/cache
232+
fi
233+
234+
235+
if [ -d "/var/www/html/wp-content/uploads/cache" ]; then
236+
chown -R www-data:www-data /var/www/html/wp-content/uploads/cache
237+
fi
238+
if [ -d "/var/www/html/wp-content/cache" ]; then
239+
chown -R www-data:www-data /var/www/html/wp-content/cache
240+
fi
241+
242+
243+
sed -i "/stop editing/i \
244+
\@ini_set('session.cookie_httponly', true);\n \
245+
\@ini_set('session.cookie_secure', true);\n \
246+
\@ini_set('session.use_only_cookies', true);\n \
247+
define('WP_MEMORY_LIMIT', '256M');\n \
248+
define( 'WP_MAX_MEMORY_LIMIT', '256M' );" wp-config.php
230249

231250
exec "$@"
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# BEGIN WordPress
2-
<IfModule mod_rewrite.c>
31
RewriteEngine On
42
RewriteBase /
53
RewriteRule ^index\.php$ - [L]
64

7-
# uploaded files
8-
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
5+
# Allow access from all domains for webfonts.
6+
<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|webmanifest)$">
7+
Header set Access-Control-Allow-Origin "*"
8+
</FilesMatch>
99

1010
# add a trailing slash to /wp-admin
1111
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
@@ -16,5 +16,3 @@ RewriteRule ^ - [L]
1616
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
1717
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
1818
RewriteRule . index.php [L]
19-
</IfModule>
20-
# END WordPress

data/nginx/default.conf

-42
This file was deleted.

data/nginx/wordpress.conf

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
upstream localhost {
2+
server wp:80;
3+
}
4+
5+
server {
6+
listen 80;
7+
server_name localhost;
8+
index index.php index.html;
9+
error_page 404 index.php?error=404;
10+
client_max_body_size 0;
11+
root /var/www/html;
12+
13+
location / {
14+
rewrite ^(.*) https://$host$1 permanent;
15+
}
16+
}
17+
18+
server {
19+
listen 443 ssl;
20+
server_name localhost;
21+
root /var/www/html;
22+
index index.php;
23+
client_max_body_size 0;
24+
25+
location / {
26+
proxy_pass http://localhost;
27+
proxy_set_header X-Forwarded-Proto https;
28+
}
29+
30+
31+
#ssl on;
32+
33+
ssl_certificate /etc/nginx/certs/nginx-selfsigned.crt;
34+
ssl_certificate_key /etc/nginx/certs/nginx-selfsigned.key;
35+
ssl_dhparam /etc/nginx/certs/dhparam.pem;
36+
}

data/uploads.ini

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
file_uploads = On
2+
memory_limit = 256M
3+
upload_max_filesize = 60M
4+
post_max_size = 60M
5+
max_execution_time = 600

data/wpcli-user.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
# This is a wrapper so that wp-cli can run as the www-data user so that permissions
3+
# remain correct
4+
/usr/local/bin/wp-cli.phar --allow-root "$@"

0 commit comments

Comments
 (0)