-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from michaloo/v2
V2
- Loading branch information
Showing
8 changed files
with
393 additions
and
136 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,80 @@ | ||
# Dockerpresso | ||
|
||
Docker Compose configuration generator for fast Wordpress Theme or plugin development. | ||
Docker + Rapid Wordpress Development = Dockerpresso | ||
|
||
More information about reasons behind Dockerpresso are presented in [this blog post](https://medium.com/@michaloo/express-wordpress-theme-and-plugin-development-environment-e077d52535e0). | ||
|
||
## Fast start | ||
Docker Compose configuration generator for fast Wordpress theme or plugin development. | ||
|
||
``` | ||
mkdir your-new-project | ||
cd your-new-project | ||
docker run --rm -v `pwd`:/project michaloo/dockerpresso | ||
vim docker-compose.yml | ||
bash dockerpresso init | ||
vim .env | ||
bash dockerpresso up | ||
## Getting started | ||
|
||
Let's go straight to your shell: | ||
|
||
```sh | ||
# install dockerpresso | ||
curl -O https://raw.githubusercontent.com/michaloo/dockerpresso/master/bin/dockerpresso && chmod +x dockerpresso && mv dockerpresso /usr/local/bin | ||
|
||
# create your project directory | ||
mkdir your-new-project && cd your-new-project | ||
|
||
# initialize dockerpresso configuration | ||
dockerpresso init | ||
|
||
# decide what you want to develop and how to inject that into wordpress installation | ||
subl docker-compose.yml | ||
|
||
# write any additional provisioning script for adding plugins etc. | ||
subl Dockerpressofile | ||
|
||
# quickly review the wp-config.php setup | ||
subl .env | ||
|
||
# run it! | ||
dockerpresso up | ||
``` | ||
|
||
Open your Docker host name or ip in browser. Fresh Wordpress installation | ||
with your plugin or theme mounted in `wp-content` directory is ready | ||
to work on! | ||
Open your Docker host name or ip in your browser. Fresh Wordpress installation | ||
with your plugin or theme mounted in `wp-content` directory is ready to work on! | ||
|
||
## Installation | ||
## Basic usage | ||
|
||
In your project root directory execute: | ||
Once dockepresso is installed start by initializing your project: | ||
|
||
```docker run --rm -v `pwd`:/project michaloo/dockerpresso``` | ||
`dockerpresso init` | ||
|
||
It will generate following files in your project root: | ||
|
||
``` | ||
/dockerpresso | ||
.env | ||
/docker-compose.yml | ||
/docker-compose.admin.yml | ||
Dockerpressofile | ||
``` | ||
|
||
* `.env` contains environmental variables which controls your setup and wp-config.php | ||
|
||
* `docker-compose.yml` contains base Docker configuration for two services | ||
`web` and `mysql`. | ||
`web` and `mysql` | ||
|
||
* `docker-composer.admin.yml` contains configuration for two additional one-time | ||
commands services `web-cli` and `mysql-cli`. | ||
|
||
* `dockerpresso` is a bash script with simple shortcuts for most common commands. | ||
commands services `web-cli` and `mysql-cli` | ||
|
||
Please edit `docker-compose.yml` to enable theme or plugin development. | ||
|
||
## Basic usage | ||
* `Dockerpressofile` is a script where wp-cli can be used to prepare Wordpress installation (e.g. install required plugins) | ||
|
||
After installation you can start with following command: | ||
Please edit those files according to your needs and start the service. | ||
|
||
`bash dockerpresso init` | ||
|
||
Which will download latest Wordpress installation and prepare it to work with | ||
Docker Compose configuration. | ||
It will also create another file `.env` which will carry all configuration of | ||
database and Wordpress. Please fill it (you will need to setup at least following vars: `MYSQL_DATABASE`, `MYSQL_USER`, `MYSQL_PASSWORD` and `MYSQL_ROOT_PASSWORD`) and then run: | ||
|
||
`bash dockerpresso up` | ||
`dockerpresso up` | ||
|
||
Which will start web and mysql services. | ||
After launching it you should be able to complete Wordpress installation | ||
process when opening in browser your Docker host name or ip. | ||
|
||
## Components | ||
## Installation | ||
|
||
Dockerpresso is simple bash script. It requires bash, docker and docker-compose to run. | ||
|
||
You can install it with following one-liner to install it in `/usr/local/bin`: | ||
|
||
Dockerpresso project base on following components: | ||
`curl -O https://raw.githubusercontent.com/michaloo/dockerpresso/master/bin/dockerpresso && chmod +x dockerpresso && mv dockerpresso /usr/local/bin` | ||
|
||
* [michaloo/docker_wp-cli](https://github.com/michaloo/docker_wp-cli) | ||
Docker image with WP-CLI tool installed which is a base image for dockerpresso. | ||
All download and maintenance commands are done by WP-CLI. | ||
|
||
* [michaloo/wp-cli-environmentalize](https://github.com/michaloo/wp-cli-environmentalize) | ||
WP-CLI package which injects `getenv` into `wp-config.php` to make Wordpress | ||
to work on ENV variables set for docker containers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,248 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env sh | ||
set -e | ||
|
||
VERSION="2.0.0" | ||
|
||
SCRIPT_PATH=$(dirname "$0") | ||
|
||
DOCKERPRESSO_FILE="Dockerpressofile" | ||
MAIN_DC_FILE="docker-compose.yml" | ||
ADMIN_DC_FILE="docker-compose.admin.yml" | ||
ALL_DC_FILES="-f $MAIN_DC_FILE -f $ADMIN_DC_FILE" | ||
WP_CONFIG_SAMPLE_FILE="wp-config-sample.php" | ||
WP_CONFIG_FILE="wp-config.php" | ||
|
||
|
||
assert_initialized() { | ||
if [ ! -f $MAIN_DC_FILE ] || [ ! -f $ADMIN_DC_FILE ] || [ ! -f $DOCKERPRESSO_FILE ] ; then | ||
echo "Dockerpresso was not initialized correctly here, run \`dockerpresso init\`" >&2 | ||
exit 2 | ||
fi | ||
} | ||
|
||
ensure_downloaded() { | ||
if ! $(docker-compose $ALL_DC_FILES run --rm --no-deps web-cli test -f $WP_CONFIG_SAMPLE_FILE); then | ||
echo "It seems wordpress was not downloaded yet, downloading" | ||
$0 download | ||
fi | ||
} | ||
|
||
ensure_configured() { | ||
if ! $(docker-compose $ALL_DC_FILES run --rm --no-deps web-cli test -f $WP_CONFIG_FILE); then | ||
echo "It seems wordpress was not configured yet, configuring" | ||
$0 configure | ||
fi | ||
} | ||
|
||
wait_for_mysql() { | ||
while ! $0 mysql-check &> /dev/null; do | ||
printf "." | ||
sleep 1 | ||
done | ||
} | ||
|
||
case "$1" in | ||
--debug) # Argument acting as a simple flag | ||
set -x | ||
shift 1 | ||
;; | ||
esac | ||
|
||
case "$1" in | ||
up) | ||
assert_initialized | ||
docker-compose up -d --force-recreate | ||
ensure_downloaded | ||
ensure_configured | ||
wait_for_mysql | ||
echo "Running Dockerpressofile script" | ||
docker-compose $ALL_DC_FILES run --rm --no-deps web-cli < Dockerpressofile | ||
;; | ||
stop) | ||
assert_initialized | ||
docker-compose stop | ||
;; | ||
rm) | ||
assert_initialized | ||
docker-compose $ALL_DC_FILES rm | ||
;; | ||
ps) | ||
assert_initialized | ||
docker-compose $ALL_DC_FILES ps | ||
;; | ||
logs) | ||
assert_initialized | ||
docker-compose $ALL_DC_FILES logs | ||
;; | ||
down) | ||
assert_initialized | ||
docker-compose $ALL_DC_FILES down | ||
;; | ||
destroy) | ||
assert_initialized | ||
# docker-compose $ALL_DC_FILES run --rm --no-deps web-cli rm -rf . | ||
docker-compose $ALL_DC_FILES down -v | ||
;; | ||
mysql) | ||
assert_initialized | ||
docker-compose $ALL_DC_FILES run --rm mysql-cli | ||
;; | ||
version) | ||
echo $VERSION | ||
;; | ||
wp-version) | ||
assert_initialized | ||
docker-compose $ALL_DC_FILES run --rm --entrypoint wp web-cli core version | ||
;; | ||
init) | ||
echo "Initializing Dockerpresso (version $VERSION) in `pwd`" | ||
|
||
cat <<'EOT' >> .env | ||
MYSQL_DATABASE=database | ||
MYSQL_USER=user | ||
MYSQL_PASSWORD=password | ||
MYSQL_ROOT_PASSWORD=test | ||
DB_HOST=mysql | ||
DB_CHARSET= | ||
DB_COLLATE= | ||
TABLE_PREFIX=wp_ | ||
WP_DEBUG=true | ||
WP_DEBUG_LOG= | ||
WP_CACHE= | ||
WPCACHEHOME= | ||
UPLOADS= | ||
FS_METHOD= | ||
DISABLE_WP_CRON= | ||
DISALLOW_FILE_EDIT= | ||
EOT | ||
|
||
cat <<'EOT' >> docker-compose.admin.yml | ||
version: '2' | ||
services: | ||
web-cli: | ||
image: wordpress:cli | ||
command: bash | ||
env_file: .env | ||
volumes_from: | ||
- web | ||
links: | ||
- web | ||
- mysql | ||
mysql-cli: | ||
image: mariadb | ||
env_file: .env | ||
links: | ||
- mysql:mysql | ||
command: bash -c 'exec mysql -hmysql -uroot -p$MYSQL_ROOT_PASSWORD' | ||
volumes_from: | ||
- mysql | ||
EOT | ||
|
||
cat <<'EOT' >> docker-compose.yml | ||
version: '2' | ||
services: | ||
web: | ||
image: wordpress | ||
env_file: .env | ||
volumes: | ||
- ./wordpress_data:/var/www/html/ | ||
# uncomment line below to start theme development | ||
# - ./example-theme-src:/var/www/html/wp-content/themes/example-theme | ||
# uncomment line below to start plugin development | ||
# - ./example-plugin-src:/var/www/html/wp-content/plugins/example-plugin | ||
ports: | ||
- "80:80" | ||
links: | ||
- mysql | ||
mysql: | ||
image: mariadb | ||
env_file: .env | ||
ports: | ||
- "3306:3306" | ||
volumes: | ||
- mysql_data:/var/lib/mysql | ||
volumes: | ||
mysql_data: {} | ||
EOT | ||
|
||
cat <<'EOT' >> Dockerpressofile | ||
#!/usr/bin/env sh | ||
# This is file which will be run every time Dockerpresso managed Wordpress | ||
# is started or restarted. | ||
# You can use any wp-cli command here such as plugin installation or activation. | ||
# Use it to prepare environment your plugin or theme may need | ||
wp core install --url=localhost --title=Localhost --admin_user=admin --admin_password=pass [email protected] | ||
EOT | ||
echo "Edit docker-compose.yml and Dockerpresso files" | ||
echo "Run dockerpresso up to start" | ||
echo "Remember to add wordpress_data to .gitignore" | ||
;; | ||
mysql-check) | ||
docker-compose $ALL_DC_FILES run --rm mysql-cli bash -c 'exec mysqladmin ping -h"$DB_HOST" --silent' | ||
;; | ||
download) | ||
assert_initialized | ||
docker-compose $ALL_DC_FILES run --rm --no-deps web-cli wp core download | ||
;; | ||
configure) | ||
assert_initialized | ||
docker-compose $ALL_DC_FILES run --rm --no-deps web-cli wp config create --dbname="" --dbuser="" --skip-check --extra-php <<PHP | ||
define( 'WP_DEBUG', filter_var(getenv("WP_DEBUG"), FILTER_VALIDATE_BOOLEAN) ); | ||
define( 'WP_DEBUG_LOG', filter_var(getenv("WP_DEBUG_LOG"), FILTER_VALIDATE_BOOLEAN) ); | ||
define( 'WP_CACHE' , filter_var(getenv("WP_CACHE"), FILTER_VALIDATE_BOOLEAN) ); | ||
define( 'WPCACHEHOME', getenv("WPCACHEHOME") ); | ||
define( 'UPLOADS', getenv("UPLOADS") ); | ||
define('FS_METHOD', getenv("FS_METHOD") ); | ||
define('DISABLE_WP_CRON', filter_var(getenv("DISABLE_WP_CRON"), FILTER_VALIDATE_BOOLEAN)); | ||
define('DISALLOW_FILE_EDIT', filter_var(getenv("DISALLOW_FILE_EDIT"), FILTER_VALIDATE_BOOLEAN)); | ||
PHP | ||
|
||
docker-compose $ALL_DC_FILES run --rm --no-deps web-cli sed -i \ | ||
-e "s/define( 'DB_NAME',.*/define( 'DB_NAME', getenv('MYSQL_DATABASE') );/" \ | ||
-e "s/define( 'DB_USER',.*/define( 'DB_USER', getenv('MYSQL_USER') );/" \ | ||
-e "s/define( 'DB_PASSWORD',.*/define('DB_PASSWORD', getenv('MYSQL_PASSWORD') );/" \ | ||
-e "s/define( 'DB_HOST',.*/define( 'DB_HOST', getenv('DB_HOST') );/" \ | ||
-e "s/define( 'DB_CHARSET',.*/define( 'DB_CHARSET', getenv('DB_CHARSET') );/" \ | ||
-e "s/define( 'DB_COLLATE',.*/define( 'DB_COLLATE', getenv('DB_COLLATE') );/" \ | ||
-e "s/\$table_prefix =.*/\$table_prefix = getenv( 'TABLE_PREFIX' );/" \ | ||
wp-config.php | ||
;; | ||
cli) | ||
assert_initialized | ||
docker-compose $ALL_DC_FILES run --rm web-cli | ||
;; | ||
# cp) | ||
# docker-compose $ALL_DC_FILES run --no-deps -d web | ||
# docker cp $2 $(docker-compose $ALL_DC_FILES ps -q web):/var/www/html | ||
# docker-compose $ALL_DC_FILES stop web | ||
# docker-compose $ALL_DC_FILES rm web | ||
;; | ||
*) | ||
cp /dockerpresso-templates/* /project | ||
echo "Dockerpresso $VERSION" | ||
echo "Dockerpresso simplifies Wordpress theme and plugin development." | ||
echo "" | ||
echo "Usage:" | ||
echo "\tversion - show dockerpresso version" | ||
echo "\tinit - initialize dockerpresso based project and creates required files" | ||
echo "\tup - (re)creates both web and mysql containers and runs Dockerpresso provisioning script." | ||
echo "\t Creates wp-config.php and installs Wordpress if needed" | ||
echo "\tcli - starts a cli console where wp-cli can be used" | ||
echo "\tmysql - starts a cli console to interact with mysql database" | ||
echo "\tps - lists running docker containers" | ||
echo "\tlogs - show logs from the docker containers" | ||
echo "\tstop - stops docker containers" | ||
echo "\trm - removes docker containers" | ||
echo "\tdown - stops and removes docker containers" | ||
echo "\tdestroy - stops, removes docker containers and removes volumes with database and wordpress data" | ||
;; | ||
esac | ||
|
||
|
Oops, something went wrong.