Skip to content

Commit c2602a1

Browse files
committed
Moved directories into rootfs, removed syslog and postfix in favor of mu-plugin
1 parent efd5911 commit c2602a1

File tree

18 files changed

+49
-117
lines changed

18 files changed

+49
-117
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/docker-compose.yml
2+
/.env

Dockerfile

+6-18
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@ MAINTAINER Tomaz Zaman <tomaz@codeable.io>
55
RUN apk add --no-cache \
66
bash \
77
curl-dev \
8-
imagemagick-dev \
8+
imagemagick \
99
libpng-dev \
1010
libxml2-dev \
11-
mailx \
12-
mysql-client \
1311
nginx \
1412
openssl \
15-
postfix \
1613
redis \
17-
supervisor \
18-
syslog-ng
14+
supervisor
1915

2016
# Set up some useful environment variables
2117
ENV WP_ROOT /var/www/wordpress
@@ -31,7 +27,7 @@ WORKDIR /var/www/wordpress/wp-content
3127

3228
# Install the necessary php libraries and extensions to run the most common
3329
# WordPress plugins and functionality (like image manipulation with ImageMagick)
34-
RUN apk add --no-cache libtool build-base autoconf \
30+
RUN apk add --no-cache libtool build-base autoconf imagemagick-dev \
3531
&& export CFLAGS="-I/usr/src/php" \
3632
&& docker-php-ext-install \
3733
-j$(grep -c ^processor /proc/cpuinfo 2>/dev/null) \
@@ -40,7 +36,7 @@ RUN apk add --no-cache libtool build-base autoconf \
4036
gd mbstring xmlreader xmlwriter ftp mysqli opcache sockets \
4137
&& pecl install imagick \
4238
&& docker-php-ext-enable imagick \
43-
&& apk del libtool build-base autoconf
39+
&& apk del libtool build-base autoconf imagemagick-dev
4440

4541
# Download and extract WordPress into /var/www/wordpress
4642
RUN curl -o wordpress.tar.gz -SL $WP_DOWNLOAD_URL \
@@ -66,16 +62,8 @@ RUN chown -R wordpress:www-data $WP_ROOT \
6662
# Set proper ownership on Nginx's operational directories (for uploads)
6763
RUN chown -R www-data:www-data /var/lib/nginx
6864

69-
# Copy all the configuration files in etc and usr into image root
70-
COPY etc /etc/
71-
COPY usr /usr/
72-
73-
# Configure postfix
74-
RUN postconf inet_interfaces=localhost \
75-
smtputf8_enable=no \
76-
'myorigin=$mydomain' \
77-
mail_spool_directory=/var/spool/mail \
78-
mynetworks_style=class
65+
# Copy all the configuration files into image root
66+
COPY rootfs /
7967

8068
# Set the entrypoint which reads all the secret files to runtime ENV vars
8169
ENTRYPOINT [ "docker-entrypoint.sh" ]

README.md

+32-12
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,35 @@ General rule of thumb whether a configuration value should be a secret is that y
5959

6060
## Sending emails
6161

62-
This image also comes with `postfix` MTA (mail transfer agent) installed, since the default WordPress install is capable of sending emails. While the default configuration might work on your local development machine, it will most likely fail in production - the reason being most of cloud providers block the default port (25) to fight spam.
63-
64-
That's why you're strongly encouraged to set the following environment variables:
65-
66-
- `SMTP_DOMAIN` - the domain you send emails from
67-
- `SMTP_HOSTNAME` - server's hostname (can be the same as domain)
68-
- `SMTP_SERVER` - email provider's server (Mandrill, Sendgrid, Mailgun, etc)
69-
- `SMTP_USERNAME` - username/email for the email provider
70-
- `SMTP_PASSWORD` - should be in _secrets_!
71-
- `SMTP_PORT` - port for the email provider
72-
73-
You can find the last four values in your email provider's documentation.
62+
Docker images are supposed to be as light-weight (and with limited responsibilities) as possible, which is why this image comes with a very basic `sendmail` installation, which will not work on it's own - you need to provide a mail relay to send emails, like Google's SMTP server. To get emails working, create a file `wp-content/mu-plugins/smtp-config.php` and put the following code in it:
63+
64+
```
65+
<?php
66+
67+
defined( 'ABSPATH' ) or die( 'Please don\'t access this file directly.' );
68+
69+
/**
70+
* If the emails are still not sent properly, despite these settings
71+
* being set, visit https://myaccount.google.com/security and turn
72+
* on "Allow less secure apps". In any case, it's recommended to
73+
* create a separate email account for sending emails.
74+
*
75+
* You can either hard-code values in this file or provide them
76+
* via environment variables.
77+
*/
78+
79+
add_action('phpmailer_init', 'smtp_config');
80+
81+
function smtp_config($phpmailer) {
82+
$phpmailer->isSMTP();
83+
$phpmailer->Host = 'smtp.gmail.com';
84+
$phpmailer->SMTPAutoTLS = true;
85+
$phpmailer->SMTPAuth = true;
86+
$phpmailer->Port = 587;
87+
$phpmailer->Username = $_ENV['SMTP_EMAIL'];
88+
$phpmailer->Password = $_ENV['SMTP_PASSWORD'];
89+
}
90+
```
7491

7592
## Your own Nginx virtual hosts
7693

@@ -86,5 +103,8 @@ Many developers that use containers on a daily basis believe that each container
86103
- Some plugins (like WordFence) require files in WordPress root directory. Normally this is not a problem since those files can be safely moved into `wp-content` (which is shared among containers), just pay attention to file paths in those files.
87104
- If you require additional/different php settings, feel free to pass those settings in Nginx config, like `fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/wordpress/wp-content/wordfence-waf.php";` for example with WordFence.
88105

106+
## TODO:
107+
- implement a proper init system ([s6](https://skarnet.org/software/s6/)/[runit](smarden.org/runit/))
108+
89109
---
90110
This project, developed by [Codeable](https://codeable.io), is published under MIT License.

etc/supervisor.d/postfix.ini

-6
This file was deleted.

etc/supervisor.d/syslog-ng.ini

-7
This file was deleted.

etc/syslog-ng/syslog-ng.conf

-21
This file was deleted.

examples/k8s/secrets.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ metadata:
44
name: wordpress-secrets
55
type: Opaque
66
data:
7-
auth-key:
8-
secure-auth-key:
9-
logged-in-key:
10-
nonce-key:
11-
auth-salt:
12-
secure-auth-salt:
13-
logged-in-salt:
14-
nonce-salt:
15-
db-password:
7+
AUTH_KEY:
8+
SECURE_AUTH_KEY:
9+
LOGGED_IN_KEY:
10+
NONCE_KEY:
11+
AUTH_SALT:
12+
SECURE_AUTH_SALT:
13+
LOGGED_IN_SALT:
14+
NONCE_SALT:
15+
DB_PASSWORD:

examples/local/.env

-2
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,3 @@ WP_CACHE_KEY_SALT=cdbl-wp-
2121
WP_MEMORY_LIMIT=256M
2222
WP_SITEURL=http://localhost
2323
WP_HOME=http://localhost
24-
SMTP_DOMAIN=localhost
25-
SMTP_HOSTNAME=docker.localhost
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

usr/local/bin/start-postfix.sh

-42
This file was deleted.

0 commit comments

Comments
 (0)