Skip to content

Commit

Permalink
Large refactor + improvements (#97)
Browse files Browse the repository at this point in the history
* big refactor + improvements/bugfixes

* add security fix from #98

* fix rewrite flush

* Add php7.1 dockerfile

* adjust volume check from grout=1000 to group!=root for better coverage

* address items from code review
  • Loading branch information
dsifford committed May 23, 2017
1 parent 3c41538 commit 76150f8
Show file tree
Hide file tree
Showing 15 changed files with 539 additions and 526 deletions.
File renamed without changes.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ wp-content/*
!wp-content/themes/

# WordPress Starter Dev Files
Dockerfile-test
/Dockerfile
/docker-compose.yml
test.sh
37 changes: 35 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
# Changelog

This changelog is for the Docker image. There might be changes to the gulpfile that are not listed here.
## 0.15.0 - latest

## 0.14.0 - latest
### Deprecations

**Note:** Both deprecations will still work as usual until the next release cycle.

#### `[local]plugin-name` & `[local]theme-name` syntax

The build process is now aware of locally-volumed plugins and themes automatically.

Additionally, listing locally-volumed plugins and themes in your `docker-compose.yml` file is optional; you may list them if you'd like to keep your compose file declarative, or you may skip listing them completely. The build will complete the same either way.

#### `SEARCH_REPLACE` has been renamed to `URL_REPLACE`

We chose to rename this because, although you may search and replace strings that are not URLs, the build process requires them to be.

This name reflects that requirement better and will lead to less confusion down the road.

### `VERBOSE` environement variable

Logging has been changed to show necessary information by default.

### Improvements
- Add `php7.1` base image.
- Widespread efficiency improvements to build process.
- Reduce the number of Dockerfile layers.
- If `SERVER_NAME` is specified (eg. `example.com`), create a `ServerAlias` in the apache configs for `www.example.com`.

### Fixes
- Plugins and themes are only pruned if they meet the following criteria (Closes #51):
- Not listed in `docker-compose.yml`.
- Not added as a local volume.
- Adjust permissions of volumed files and directories so that they remain editable outside the container, and remain secure. (Closes #12)
- Fix critical security vulnerability. HT @joerybruijntjes.

## 0.14.0
- Add `SERVER_NAME` variable to allow for quickly setting that directive in the apache config for users interested in running in production.

## 0.13.0
Expand Down
121 changes: 27 additions & 94 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

A Docker Wordpress development environment by the team at [Visible](https://visible.vc/) and some awesome [contributors](https://github.com/visiblevc/wordpress-starter/graphs/contributors). Our goal is to make Wordpress development slightly less frustrating.

- [Introduction](#introduction)
- [Example](./example/)
- [Requirements](#requirements)
- [Getting Started](#getting-started)
- [Available Images](#available-images)
- [Introduction](#introduction)
- [Example](#example)
- [Default Wordpress Admin Credentials](#default-wordpress-admin-credentials)
- [Default Database Credentials](#default-database-credentials)
- [Service Environment Variables](#service-environment-variables)
Expand All @@ -18,6 +18,16 @@ A Docker Wordpress development environment by the team at [Visible](https://visi
- [Using in Production](#using-in-production)
- [Contributing](#contributing)

### Introduction

We wrote a series of articles explaining in depth the philosophy behind this project:

- [Intro: A slightly less shitty WordPress developer workflow](https://visible.vc/engineering/wordpress-developer-workflow/)
- [Part 1: Setup a local development environment for WordPress with Docker](https://visible.vc/engineering/docker-environment-for-wordpress/)
- [Part 2: Setup an asset pipeline for WordPress theme development](https://visible.vc/engineering/asset-pipeline-for-wordpress-theme-development/)
- [Part 3: Optimize your wordpress theme assets and deploy to S3](https://visible.vc/engineering/optimize-wordpress-theme-assets-and-deploy-to-s3-cloudfront/)
- Part 4: Auto deploy your site on your server (coming)

### Requirements

Well, to run a Docker environment, you will need Docker. The Dockerfile is only for an Apache+PHP+Wordpress container, you will need a `MySQL` or `MariaDB` container to run a website. We use Docker Compose 1.6+ for the orchestration.
Expand All @@ -29,102 +39,26 @@ This project has 2 parts: the Docker environment and a set of tools for theme de
```
# copy the files
git clone https://github.com/visiblevc/wordpress-starter.git
rm -rf .git Dockerfile run.sh README.md CHANGELOG.md ISSUE_TEMPLATE.md
# navigate to example directory
cd wordpress-starter/example
# start the website at localhost:8080
docker-compose up
docker-compose up -d && docker-compose logs -f wordpress
```

**NOTE:** If you run on MacOS with Docker in VirtualBox, you will want to forward the port by running this `VBoxManage controlvm vm-name natpf1 "tcp8080,tcp,127.0.0.1,8080,,8080"`. If you use another port than `8080`, change it in the command.

##### This repository does 2 things:

1. Include the files to create a wordpress Docker image (visiblevc/wordpress)
2. Include build tools to develop wordpress themes (gulp)

If you don't plan to build the Docker image yourself, you shouldn't care for 1. We publish the image on Docker Hub and you can grab it directly from there. That's why you can safely remove the Dockerfile and run.sh.

The reason we remove `.git`, `README.md` and `CHANGELOG.md` is because we assume you will start your own repository, named after your project. There is virtually no benefit keeping ties with our remote git repository.

### Available Images

| PHP Version | Tags |
| ----------- | ---- |
| **7.0** | `latest` `latest-php7.0` `<version>-php7.0` |
| **7.1** | `latest` `latest-php7.1` `<version>-php7.1` |
| **7.0** | `latest-php7.0` `<version>-php7.0` |
| **5.6** | `latest-php5.6` `<version>-php5.6`|

If you need a specific version, look at the [Changelog](CHANGELOG.md)

### Introduction

We wrote a series of articles explaining in depth the philosophy behind this project:

- [Intro: A slightly less shitty WordPress developer workflow](https://visible.vc/engineering/wordpress-developer-workflow/)
- [Part 1: Setup a local development environment for WordPress with Docker](https://visible.vc/engineering/docker-environment-for-wordpress/)
- [Part 2: Setup an asset pipeline for WordPress theme development](https://visible.vc/engineering/asset-pipeline-for-wordpress-theme-development/)
- [Part 3: Optimize your wordpress theme assets and deploy to S3](https://visible.vc/engineering/optimize-wordpress-theme-assets-and-deploy-to-s3-cloudfront/)
- Part 4: Auto deploy your site on your server (coming)

### Example

The only thing you need to get started is a `docker-compose.yml` file:

```yml
version: '2'
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,
[local]my-local-plugin
THEMES: >-
[local]my-local-theme
SEARCH_REPLACE: yoursite.com,localhost:8080
WP_DEBUG: 'true'
db:
image: mysql:5.7 # or mariadb:10
volumes:
- data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
volumes:
data: {}
```
**Need PHPMyAdmin? Add it as a service**
```yml
version: '2'
services:
wordpress:
# same as above
db:
# same as above
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- 22222:80
volumes:
data:
```
### Default Wordpress Admin Credentials

To access the Wordpress Admin at `/wp-admin`, the default values are as follows:
Expand Down Expand Up @@ -163,12 +97,11 @@ Variable | Default Value | Description
`WP_DEBUG_DISPLAY` | `'false'` | [Click here](https://codex.wordpress.org/WP_DEBUG#WP_DEBUG_DISPLAY) for more information
`WP_DEBUG_LOG` | `'false'` | [Click here](https://codex.wordpress.org/WP_DEBUG#WP_DEBUG_LOG) for more information
`WP_VERSION` | `latest` | Specify the WordPress version to install. Accepts any valid semver number, `latest`, or `nightly` for beta builds.
`THEMES` | | Comma-separated list of themes you want to install in either of the following forms<ul><li>`theme-slug`: Used when installing theme direct from WordPress.org</li><li>`[theme-slug]https://themesite.com/theme.zip`: Used when installing theme from URL</li><li>`[local]theme-slug`: Used when you have the theme downloaded to a local folder that you have volumed to the `./wp-content/themes` directory.</li></ul>
`PLUGINS` | | Comma-separated list of plugins you want to install in either of the following forms:<ul><li>`plugin-slug`: Used when installing plugin direct from WordPress.org.</li><li>`[plugin-slug]http://pluginsite.com/plugin.zip`: Used when installing plugin from URL.</li><li>`[local]plugin-slug`: Used when you have the plugin downloaded to a local folder that you have volumed to the `./wp-content/plugins` directory.</li></ul>
`THEMES` | | Comma-separated list of themes you want to install in either of the following forms<ul><li>`theme-slug`: Used when installing theme direct from WordPress.org</li><li>`[theme-slug]https://themesite.com/theme.zip`: Used when installing theme from URL</li></ul>
`PLUGINS` | | Comma-separated list of plugins you want to install in either of the following forms:<ul><li>`plugin-slug`: Used when installing plugin direct from WordPress.org.</li><li>`[plugin-slug]http://pluginsite.com/plugin.zip`: Used when installing plugin from URL.</li></ul>
`MULTISITE` | `'false'` | Set to `'true'` to enable multisite
`PERMALINKS` | `/%year%/%monthnum%/%postname%/` | A valid WordPress permalink [structure tag](https://codex.wordpress.org/Using_Permalinks#Structure_Tags)
`SEARCH_REPLACE` | | Comma-separated string in the form of `current-url,replacement-url`<ul><li>When defined, `current-url` will be replaced with `replacement-url` on build (useful for development environments utilizing a database copied from a live site)<li>**Note:** If you are running Docker using Docker Machine, your replacement url MUST be the output of the following command: `echo $(docker-machine ip <your-machine-name>):8080`</li></ul>
`VERBOSE` | `'false'` | Set to `'true'` to run build with verbose logging
`URL_REPLACE` | | Comma-separated string in the form of `current-url,replacement-url`<ul><li>When defined, `current-url` will be replaced with `replacement-url` on build (useful for development environments utilizing a database copied from a live site)<li>**Note:** If you are running Docker using Docker Machine, your replacement url MUST be the output of the following command: `echo $(docker-machine ip <your-machine-name>):8080`</li></ul>

#### `db`
Variable | Default Value | Description
Expand All @@ -193,24 +126,24 @@ If you have an exported `.sql` file from an existing website, drop the file into
If the SQL dump changes for some reason, you can reload the database by running:

```sh
docker exec wordpress /bin/bash "wp db import $(find /data/*.sql | head -n 1) --allow-root"
docker-compose exec wordpress /bin/bash "wp db import $(find /data/*.sql | head -n 1) --allow-root"
```

If you want to create a dump of your development database, you can run:

```sh
npm run wp db export /data --allow-root
docker-compose exec wordpress /bin/bash 'wp db export /data --allow-root'
```

Finally, sometimes your development environment runs on a different domain than your live one. The live will be `example.com` and the development `localhost:8080`. This project does a search and replace for you. You can set the `SEARCH_REPLACE: example.com,localhost:8080` environment variable in the `docker-compose.yml`.
Finally, sometimes your development environment runs on a different domain than your live one. The live will be `example.com` and the development `localhost:8080`. This project does a search and replace for you. You can set the `URL_REPLACE: example.com,localhost:8080` environment variable in the `docker-compose.yml`.

## Using in Production

### Adjustments to `docker-compose.yml`

```yml
# If something isn't shown, assume it's the same as the examples above
version: '2'
version: '3'
services:
wordpress:
ports:
Expand Down Expand Up @@ -245,7 +178,7 @@ Name Command State
project_db_1 docker-entrypoint.sh mysqld Up
project_wordpress_1 docker-php-entrypoint /run.sh Up

$ docker exec -it project_wordpress_1 /bin/bash
$ docker-compose exec wordpress /bin/bash
root@4e16c7fe4a10:/app# certbot --apache
```

Expand All @@ -258,7 +191,7 @@ Name Command State
project_db_1 docker-entrypoint.sh mysqld Up
project_wordpress_1 docker-php-entrypoint /run.sh Up

$ docker exec -it project_wordpress_1 /bin/bash
$ docker-compose exec wordpress /bin/bash
root@4e16c7fe4a10:/app# certbot renew
```

Expand Down
20 changes: 0 additions & 20 deletions docker-compose.yml

This file was deleted.

67 changes: 67 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

# Quickstart

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: yoursite.com,localhost:8080
WP_DEBUG: 'true'
db:
image: mysql:5.7 # or mariadb:10
volumes:
- data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
volumes:
data: {}
```
**Need PHPMyAdmin? Add it as a service**
```yml
version: '3'
services:
wordpress:
# same as above
db:
# same as above
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- 22222:80
volumes:
data:
```
## Running the example
1. Run the following command in the root of the example directory.
```sh
$ docker-compose up -d && docker-compose logs -f wordpress
```

2. When the build is finished, hit <kbd>ctrl</kbd>-<kbd>c</kbd> to detach from the logs and visit `localhost:8080` in your browser.

File renamed without changes.
30 changes: 30 additions & 0 deletions example/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: '3'
services:
wordpress:
image: visiblevc/wordpress:0.15.0-php7.1
ports:
- 8080:80
- 443:443
volumes:
- ./data:/data
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
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- 22222:80
volumes:
data:
File renamed without changes.
Loading

0 comments on commit 76150f8

Please sign in to comment.