Skip to content

Commit 1f2f75b

Browse files
committed
Fixed #3
Support for multisite. Merge branch 'mu' Conflicts: Dockerfile README.md docker-compose.yml
2 parents 566e910 + 8ae3b3d commit 1f2f75b

10 files changed

Lines changed: 533 additions & 329 deletions

Dockerfile

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,39 @@ FROM nickbreen/wp-cli:v1.0.0
22

33
MAINTAINER Nick Breen <nick@foobar.net.nz>
44

5-
ENV MYSQL_ROOT_PASSWORD="" \
5+
ENV WP_DB_ROOT_USER="root" \
6+
WP_DB_ROOT_PASSWORD="" \
67
WP_LOCALE="" \
78
WP_DB_HOST="" \
89
WP_DB_PORT="" \
910
WP_DB_NAME="" \
1011
WP_DB_USER="" \
1112
WP_DB_PASSWORD="" \
1213
WP_DB_PREFIX="" \
14+
WP_SUBDOMAINS="" \
1315
WP_URL="" \
1416
WP_TITLE="" \
1517
WP_ADMIN_USER="" \
1618
WP_ADMIN_PASSWORD="" \
1719
WP_ADMIN_EMAIL="" \
18-
WP_THEMES="" \
19-
BB_THEMES="" \
20-
WP_PLUGINS="" \
21-
BB_PLUGINS="" \
22-
WP_OPTIONS="" \
23-
WP_IMPORT="" \
2420
WP_EXTRA_PHP=""
2521

2622
RUN mkdir -p /usr/local/share/php/
27-
COPY oauth.php /usr/local/share/php/
23+
COPY php/* /usr/local/share/php/
2824

2925
COPY setup.sh /etc/profile.d/
3026

31-
RUN php -l /usr/local/share/php/oauth.php && bash -n /etc/profile.d/setup.sh
27+
RUN for f in /usr/local/share/php/*.php; do php -l $f; done && bash -n /etc/profile.d/setup.sh
3228

3329
RUN useradd -M -N -g www-data -d /var/www -s /bin/bash wp
3430

35-
RUN mkdir -p /var/www/wp-content/uploads && \
36-
chown -R wp:www-data /var/www && \
37-
chmod -R g-w /var/www && \
38-
chmod -R g+w /var/www/wp-content/uploads
31+
WORKDIR /var/www
3932

40-
VOLUME /var/www /var/www/wp-content/uploads
33+
RUN mkdir -p wp-content/uploads && \
34+
chown -R wp:www-data . && \
35+
chmod -R g-w . && \
36+
chmod -R g+w wp-content/uploads
4137

42-
WORKDIR /var/www
38+
COPY wp-cli.yml /
39+
40+
VOLUME /var/www /var/www/wp-content/uploads

README.md

Lines changed: 88 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,122 @@
1-
Automated set up utilities for WordPress.
1+
Automated set up utilities for [WordPress].
22

33
WordPress is set up with a non-root user.
44

55
Volumes for the docroot and wp-content/uploads directories are configured.
66

7+
The installation is hardcoded to `/var/www`.
8+
79
# Usage
810

9-
To automatically setup WP use two containers:
11+
See `docker-compose.yml` for a usage example.
1012

11-
# docker-compose.yml
12-
wp-setup:
13-
image: nickbreen/wp-setup
14-
environment:
15-
# yadda, see below
13+
`attach` or `exec` (etc) into the container and execute `setup`.
1614

17-
# Configuration
15+
docker exec -itu wp CONTAINER bash -l -c 'setup'
1816

19-
The database configuration can be specified explicitly with:
17+
This image provides and uses [WP-CLI].
2018

21-
- ```WP_DB_HOST```
22-
- ```WP_DB_PORT```
23-
- ```WP_DB_NAME```
24-
- ```WP_DB_USER```
25-
- ```WP_DB_PASSWORD```
26-
- ```WP_DB_PREFIX```
19+
## Download
2720

28-
If any are omitted then values are inferred from the linked ```:mysql``` container, otherwise sensible defaults are used.
21+
The version and a locale can be specified with environment variables.
2922

30-
Variable | Value inferred from | Default
31-
-------------------- | ------------------------------ | ---------
32-
```WP_DB_NAME``` | ```MYSQL_ENV_MYSQL_DATABASE``` | wordpress
33-
```WP_DB_USER``` | ```MYSQL_ENV_MYSQL_USER``` | wordpress
34-
```WP_DB_PASSWORD``` | ```MYSQL_ENV_MYSQL_PASSWORD``` | wordpress
35-
```WP_DB_HOST``` | ```MYSQL_PORT_3306_TCP_ADDR``` | mysql
36-
```WP_DB_PORT``` | ```MYSQL_PORT_3306_TCP_PORT``` | 3306
37-
```WP_DB_PREFIX``` | N/A | wp_
23+
| Variable | Example | Default
24+
|------------|---------|---------
25+
| WP_VERSION | 4.4.2 | Latest
26+
| WP_LOCALE | en_NZ | en_US
3827

39-
```--extra-php``` is supported with the ```WP_EXTRA_PHP``` environment variable. E.g.
28+
## Configuration
4029

41-
WP_EXTRA_PHP: |
42-
define('DISABLE_WP_CRON', true);
30+
The database configuration can be specified explicitly with environment variables.
4331

44-
## Installation
32+
If any are omitted then values are inferred from the linked ```:mysql```
33+
container, otherwise sensible defaults are used.
4534

46-
The initial DB is installed, if not already installed in the DB, using the variables; each has a useless default value, so make sure you set them:
47-
- ```WP_LOCALE``` (default ```en_NZ```)
48-
- ```WP_URL```
49-
- ```WP_TITLE```
50-
- ```WP_ADMIN_USER```
51-
- ```WP_ADMIN_PASSWORD```
52-
- ```WP_ADMIN_EMAIL```
35+
| Variable | Value inferred from | Default
36+
|----------------| -------------------------| ---------
37+
| WP_DB_NAME | MYSQL_ENV_MYSQL_DATABASE | wordpress
38+
| WP_DB_USER | MYSQL_ENV_MYSQL_USER | wordpress
39+
| WP_DB_PASSWORD | MYSQL_ENV_MYSQL_PASSWORD | wordpress
40+
| WP_DB_HOST | MYSQL_PORT_3306_TCP_ADDR | mysql
41+
| WP_DB_PORT | MYSQL_PORT_3306_TCP_PORT | 3306
42+
| WP_DB_PREFIX | N/A | wp_
5343

54-
## Themes and Plugins
44+
`--extra-php` is supported with the `WP_EXTRA_PHP` environment variable. E.g.
5545

56-
Themes and plugins can be installed from the WordPress.org repository, from a URL to the theme's or plugin's ZIP file. I.e.:
46+
WP_EXTRA_PHP: |
47+
define('DISABLE_WP_CRON', true);
5748

58-
Each theme or plugin is on its own line.
49+
## Installation
5950

60-
WP_THEMES: |
61-
theme-slug
62-
http://theme.domain/theme-url.zip
51+
The initial DB is installed, if not already installed in the DB, using the
52+
following variables; the setup script will complain if any are unset.
6353

64-
WP_PLUGINS: |
65-
plugin-slug
66-
https://plugin.domain/plugin-url.zip
54+
| Variable | Example | Default
55+
|-------------------|---------------------|---------
56+
| WP_LOCALE | en_NZ | en_US
57+
| WP_URL | http://example.com |
58+
| WP_TITLE | Example Title |
59+
| WP_ADMIN_EMAIL | admin@example.com |
60+
| WP_ADMIN_USER | admin |
61+
| WP_ADMIN_PASSWORD | |
6762

68-
Themes and plugins can also be installed from [Bitbucket] (OAuth 1.0a supported for private repositories) and [GitHub] (HTTP Basic Auth using personal access tokens for private repositories):
63+
## Multisite
6964

70-
BB_KEY: "BitBucket API OAuth Key"
71-
BB_SECRET: "BitBucket API OAuth Secret"
72-
BB_PLUGINS: |
73-
account/repo [tag]
74-
BB_THEMES: |
75-
account/repo [tag]
76-
GH_TOKEN: username:token
77-
GH_THEME: |
78-
CherryFramework/CherryFramework
65+
Multisite is supported, it is enabled when the `WP_SUBDOMAINS` environment
66+
variable is set.
7967

80-
[Bitbucket]: https://bitbucket.com "Bitbucket"
81-
[GitHub]: https://github.com "GitHub"
68+
| Variable | Example
69+
|---------------|---------
70+
| WP_SUBDOMAINS | "yes"
8271

83-
## Options
72+
Path-based multisites are not supported.
8473

85-
Any WordPress options can be set as JSON using ```WP_OPTIONS```. E.g.
74+
A domain mapping plugin is not required. Use the convenience function to
75+
register a new site.
8676

87-
WP_OPTIONS: |
88-
timezone_string "Pacific/Auckland"
89-
some_complex_option {"access_key_id":"...","secret_access_key":"..."}
77+
WP_COMMANDS: |
78+
new_site sitea sitea.dev http://sitea.dev "Site A"
79+
wp --url=http://sitea.dev theme activate twentyfourteen
9080

91-
Simple strings must be quoted.
81+
## Themes and Plugins
9282

93-
To set non-JSON options, use ```WP_COMMANDS```.
83+
Themes and plugins can be installed from the WordPress.org repository, from a
84+
URL to the theme's or plugin's ZIP file using `WP_COMMANDS`; e.g.:
9485

95-
## Arbitrary WP-CLI Commands
86+
WP_COMMANDS: |
87+
wp theme install theme-slug --version=1.2.3
88+
wp theme install http://example.com/theme.zip --activate
89+
wp plugin install plugin-slug --version=1.2.3
90+
wp plugin install https://example.com/plugin.zip
9691

97-
Any WP-CLI command can be executed; e.g.:
92+
Themes and plugins can also be installed from [Bitbucket] (OAuth 1.0a supported
93+
for private repositories) and [GitHub] (HTTP Basic Auth using personal access
94+
tokens for private repositories); e.g.:
9895

9996
WP_COMMANDS: |
100-
rewrite structure /%postname%
101-
rewrite flush
97+
wp github theme install CherryFramework/CherryFramework v3.1.5
98+
wp github theme install CherryFramework/CherryFramework v3.1.5 --token=XXX
99+
wp bitbucket plugin install CherryFramework/cherry-plugin v3.1.5
100+
wp bitbucket plugin install CherryFramework/cherry-plugin v3.1.5 --key=XXX --secret=XXX
101+
102+
For both GitHub and Bitbucket the version/release tag is optional and defaults
103+
to the `latest` release, or if no releases exist, to `master`.
104+
105+
[WP-CLI]: http://wp-cli.org
106+
[Bitbucket]: https://bitbucket.com
107+
[GitHub]: https://github.com
108+
[WordPress]: https://wordpress.org
109+
110+
## Arbitrary Commands
111+
112+
Any arbitrary commands can be executed, actually any commands as the
113+
value is processed by `sh`. Any environment variable prefixed with `WP_COMMANDS`
114+
will be processed.
115+
116+
WP_COMMANDS_0: | # Install plugins
117+
wp plugin install jetpack --activate
118+
WP_COMMANDS_1: | # Configure themes
119+
wp theme activate twentyfourteen
120+
WP_COMMANDS_2: | # Set some options
121+
wp rewrite structure /%postname%
122+
wp rewrite flush

docker-compose.yml

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,42 @@ db:
66
MYSQL_USER: wordpress
77
MYSQL_PASSWORD: wordpress
88

9-
wp-setup:
9+
wp:
1010
build: .
11+
command: [ "/sbin/my_init", "--", "setuser", "wp", "bash", "-l", "-c", "while ! wp server --host=0.0.0.0 --docroot=/var/www; do sleep 5; done" ]
1112
links:
1213
- db:mysql
13-
volumes_from:
14-
- wp
14+
ports:
15+
- 80:8080
1516
environment:
16-
WP_EXTRA_PHP: |-
17-
define('DISABLE_WP_CRON', true);
18-
CRON_D_WP: |-
17+
CRON_D_WP: |
1918
PATH=/usr/local/bin:$$PATH
20-
* * * * * wp wp cron event list --format=csv --fields=hook,next_run_relative --path=/var/www | awk -F ',' '$$2 == "now" {print $$1}' | xargs -r -l1 wp cron event run --path=/var/www
21-
WP_URL: http://localhost
22-
WP_ADMIN_USER: admin
23-
WP_ADMIN_PASSWORD: admin
24-
WP_ADMIN_EMAIL: admin@localhost
25-
WP_PLUGINS: |-
26-
rest-api
27-
GH_PLUGINS: |-
28-
WP-API/OAuth1
29-
WP-API/Basic-Auth
30-
GH_THEMES: |-
31-
CherryFramework/CherryFramework
19+
* * * * * wp wp cron event list --format=csv --fields=hook,next_run_relative | awk -F ',' '$$2 == "now" {print $$1}' | xargs -r -l1 wp cron event run
3220
33-
wp:
21+
setup:
3422
build: .
35-
command: [ "/sbin/my_init", "--", "setuser", "wp", "bash", "-l", "-c", "while ! wp server --host=0.0.0.0 --docroot=/var/www; do sleep 5; done" ]
3623
links:
3724
- db:mysql
38-
ports:
39-
- 80:8080
25+
volumes_from:
26+
- wp
27+
environment:
28+
WP_LOCALE: en_NZ
29+
WP_VERSION: 4.4.2
30+
WP_TITLE: Main
31+
WP_SUBDOMAINS: "yes"
32+
WP_URL: http://main.dev
33+
WP_ADMIN_USER: admin
34+
WP_ADMIN_PASSWORD: admin
35+
WP_ADMIN_EMAIL: admin@main.dev
36+
WP_EXTRA_PHP: |
37+
define('DISABLE_WP_CRON', TRUE);
38+
WP_COMMANDS_0: |
39+
wp --url=http://main.dev theme activate twentyfifteen
40+
WP_COMMANDS_1: |
41+
new_site sitea sitea.dev http://sitea.dev "Site A"
42+
wp --url=http://sitea.dev theme activate twentyfourteen
43+
WP_COMMANDS_2: |
44+
new_site siteb siteb.dev http://siteb.dev "Site B"
45+
wp --url=http://sitea.dev theme activate twentythirteen
46+
WP_COMMANDS_END: |
47+
wp site list

0 commit comments

Comments
 (0)