├── CHANGELOG.md ├── README.md ├── bin └── dockerpresso ├── documentation ├── HOW_TO_CHANGE_WP_CONFIG.md └── HOW_TO_IMPORT_EXISTING_WORDPRESS.md └── example-theme └── style.css /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | ## v2.1.0 4 | 5 | **REQUIRES MIGRATION (see below)** 6 | 7 | Couple more significant enhancements: 8 | 9 | - rolled back to use local directory for Wordpress files 🤦 10 | It's just too convenient to have easy access to any Wordpress file in code editor, even if it seems like antipattern, but ease of development is primary goal of dockerpresso. 11 | Wordpress files will be now available in `wordpress_directory`. 12 | - this resolved a problem cause by trying to download Wordpress on every `up` 13 | - added `WORDPRESS_VERSION` env variable to control which version of Wordpress is used 14 | - updated and improved overall documentation 15 | 16 | **MIGRATION** 17 | 18 | Existing projects should be rebuild by running following commands. 19 | **THIS WILL OVERWRITE all dockerpresso files and custom changes needs manual porting.** 20 | 21 | ```sh 22 | # make sure latest version of dockerpresso is installed 23 | dockerpresso destroy 24 | dockerpresso init 25 | # edit docker-compose.yml and optionally other files since they were just overwritten 26 | dockerpresso up 27 | ``` 28 | 29 | ## v2.0.2 30 | 31 | Smaller improvements 32 | 33 | - don't mount volume to local directory - which can be changed breaking some commands 34 | - add this changelog file 35 | 36 | ## v2.0.1 37 | 38 | Hotfix for broken comment. 39 | 40 | 41 | ## v2.0.0 42 | 43 | This release simplifies dockerpresso: 44 | 45 | - no other dependencies than bash 46 | - dockerpresso is supposed to be installed in /usr/local/bin or similar place instead of in each project 47 | - no separate templates files, everything is in one bash script 48 | - no custom docker images or installers, I know I already wrote that, but this is just a single bash script now 49 | - commands simplified and reworked for easier usage 50 | - documentation slightly updated 51 | 52 | 53 | ## v0.0.1 54 | 55 | Initial version 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dockerpresso 2 | 3 | Docker + Rapid Wordpress Development = Dockerpresso 4 | 5 | 6 | Docker Compose configuration generator for fast Wordpress theme or plugin development. 7 | 8 | ## Getting started 9 | 10 | Let's go straight to your shell: 11 | 12 | ```sh 13 | # install dockerpresso 14 | curl -O https://raw.githubusercontent.com/michaloo/dockerpresso/master/bin/dockerpresso && chmod +x dockerpresso && mv dockerpresso /usr/local/bin 15 | 16 | # create your project directory 17 | mkdir your-new-project && cd your-new-project 18 | 19 | # initialize dockerpresso configuration 20 | dockerpresso init 21 | 22 | # decide what you want to develop and how to inject that into wordpress installation 23 | subl docker-compose.yml 24 | 25 | # run it! 26 | dockerpresso up 27 | ``` 28 | 29 | Open your Docker host name or ip in your browser. Fresh Wordpress installation 30 | with your plugin or theme mounted in `wp-content` directory is ready to work on! 31 | 32 | ## Quick overview 33 | 34 | ### Installation 35 | 36 | Dockerpresso is simple sh script. It requires `sh`, `docker` and `docker-compose` to run. 37 | 38 | You can install it with following one-liner to put it in `/usr/local/bin`: 39 | 40 | `curl -O https://raw.githubusercontent.com/michaloo/dockerpresso/master/bin/dockerpresso && chmod +x dockerpresso && mv dockerpresso /usr/local/bin` 41 | 42 | ### Initialization 43 | 44 | Once `dockepresso` is installed start by initializing your project: 45 | 46 | ```sh 47 | dockerpresso init 48 | ``` 49 | 50 | It will generate following files in your project root: 51 | 52 | ```sh 53 | .env 54 | /docker-compose.yml 55 | /docker-compose.admin.yml 56 | Dockerpressofile 57 | wordpress_data 58 | ``` 59 | 60 | **`.env`** 61 | 62 | Contains environmental variables which controls your docker setup and `wp-config.php`. 63 | Defaults should work in most cases, but you may want to review it to adjust to your project needs. 64 | 65 | **`docker-compose.yml`** 66 | 67 | Base docker-compose configuration for two services - `web` (php and apache) and `mysql`. 68 | This is **key file to edit** and define how your project will be injected in Wordpress installation. 69 | It comes with examples how to mount theme or plugin. Depending on what your project is you will mount it 70 | to `/var/www/html/wp-content/themes` or `/var/www/html/wp-content/plugins` inside docker container. 71 | 72 | **`docker-composer.admin.yml`** 73 | 74 | Contains configuration for two additional one-time commands services `web-cli` and `mysql-cli`. 75 | They allow to execute wp-cli commands (managing Wordpress via command line) and run SQL queries. 76 | This file should not require any edits. 77 | 78 | **`Dockerpressofile`** 79 | 80 | This is a script where wp-cli can be used to prepare Wordpress installation for your project. 81 | This is best place to install required plugins (imagine you are writing WooCommerce plugin, then install and activate WooCommerce here). 82 | You can use `dockerpresso cli` to run those command manually before writing this script. 83 | Editing this file is optional. 84 | 85 | **`wordpress_data`** 86 | 87 | This is directory exposing all Wordpress files from inside the container. 88 | It's a little antipattern thing actually but it's here for convienence. 89 | You should consider it as a ephemeral directory where files can be overwriten at any time and are managed by other places such as `Dockerpressofile`, but it may be very handy to open in your code editor (IDE) other plugins, themes or core wordpress files. 90 | **This directory should not be renamed or commited into git repository!** 91 | 92 | 93 | ### Starting up 94 | 95 | `dockerpresso up` 96 | 97 | Which will start `web` and `mysql` services, make sure that `wp-config.php` is present and correct. 98 | Then it will run script from `Dockerpressofile` which by default just installs Wordpress. 99 | 100 | Every time this command it run it will recreate docker containers making sure current 101 | 102 | 103 | ## Guides 104 | 105 | - [How to change things in wp-config.php?](./documentation/HOW_TO_CHANGE_WP_CONFIG.md) 106 | - [How to import existing Wordpress?](./documentation/HOW_TO_IMPORT_EXISTING_WORDPRESS.md) 107 | -------------------------------------------------------------------------------- /bin/dockerpresso: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | set -e 3 | 4 | VERSION="2.1.0" 5 | 6 | SCRIPT_PATH=$(dirname "$0") 7 | 8 | DOCKERPRESSO_FILE="Dockerpressofile" 9 | MAIN_DC_FILE="docker-compose.yml" 10 | ADMIN_DC_FILE="docker-compose.admin.yml" 11 | ALL_DC_FILES="-f $ADMIN_DC_FILE -f $MAIN_DC_FILE" 12 | WP_CONFIG_SAMPLE_FILE="wp-login.php" 13 | WP_CONFIG_FILE="wp-config.php" 14 | 15 | 16 | assert_initialized() { 17 | if [ ! -f $MAIN_DC_FILE ] || [ ! -f $ADMIN_DC_FILE ] || [ ! -f $DOCKERPRESSO_FILE ] ; then 18 | echo "Dockerpresso was not initialized correctly here, run \`dockerpresso init\`" >&2 19 | exit 2 20 | fi 21 | } 22 | 23 | ensure_downloaded() { 24 | if ! $(docker-compose $ALL_DC_FILES run --rm web-cli test -f $WP_CONFIG_SAMPLE_FILE); then 25 | echo "It seems Wordpress was not downloaded yet, downloading..." 26 | $0 download 27 | fi 28 | } 29 | 30 | ensure_configured() { 31 | if ! $(docker-compose $ALL_DC_FILES run --rm web-cli test -f $WP_CONFIG_FILE); then 32 | echo "It seems Wordpress was not configured yet, configuring..." 33 | $0 configure 34 | fi 35 | } 36 | 37 | wait_for_mysql() { 38 | while ! $0 mysql-check &> /dev/null; do 39 | printf "." 40 | sleep 1 41 | done 42 | echo "" 43 | } 44 | 45 | case "$1" in 46 | --debug) # Argument acting as a simple flag 47 | set -x 48 | shift 1 49 | ;; 50 | esac 51 | 52 | case "$1" in 53 | up) 54 | assert_initialized 55 | mkdir -p wordpress_data 56 | ensure_downloaded 57 | ensure_configured 58 | docker-compose up -d --force-recreate 59 | wait_for_mysql 60 | echo "Running Dockerpressofile script" 61 | docker-compose $ALL_DC_FILES run -T --rm web-cli < Dockerpressofile 62 | ;; 63 | stop) 64 | assert_initialized 65 | docker-compose stop 66 | ;; 67 | rm) 68 | assert_initialized 69 | docker-compose $ALL_DC_FILES rm 70 | ;; 71 | ps) 72 | assert_initialized 73 | docker-compose $ALL_DC_FILES ps 74 | ;; 75 | logs) 76 | assert_initialized 77 | docker-compose $ALL_DC_FILES logs 78 | ;; 79 | down) 80 | assert_initialized 81 | docker-compose $ALL_DC_FILES down 82 | ;; 83 | destroy) 84 | assert_initialized 85 | # docker-compose $ALL_DC_FILES run --rm web-cli rm -rf . 86 | docker-compose $ALL_DC_FILES down -v 87 | rm -rf ./wordpress_data 88 | ;; 89 | mysql) 90 | assert_initialized 91 | docker-compose $ALL_DC_FILES run --rm mysql-cli 92 | ;; 93 | version) 94 | echo $VERSION 95 | ;; 96 | wp-version) 97 | assert_initialized 98 | docker-compose $ALL_DC_FILES run --rm --entrypoint wp web-cli core version 99 | ;; 100 | init) 101 | echo "Initializing Dockerpresso (version $VERSION) in `pwd`" 102 | 103 | cat <<'EOT' > .env 104 | # dockerpresso 2.1.0 105 | WORDPRESS_VERSION=latest 106 | WORDPRESS_LOCALE=en_US 107 | 108 | MYSQL_DATABASE=database 109 | MYSQL_USER=user 110 | MYSQL_PASSWORD=password 111 | MYSQL_ROOT_PASSWORD=test 112 | 113 | DB_HOST=mysql 114 | DB_CHARSET= 115 | DB_COLLATE= 116 | TABLE_PREFIX=wp_ 117 | 118 | WP_DEBUG=true 119 | WP_DEBUG_LOG= 120 | WP_CACHE= 121 | WPCACHEHOME= 122 | UPLOADS= 123 | 124 | FS_METHOD= 125 | DISABLE_WP_CRON= 126 | DISALLOW_FILE_EDIT= 127 | TAR_OPTIONS=--no-same-owner 128 | EOT 129 | 130 | cat <<'EOT' > docker-compose.admin.yml 131 | # dockerpresso 2.1.0 132 | version: '2' 133 | services: 134 | web-cli: 135 | image: wordpress:cli 136 | command: bash 137 | env_file: .env 138 | volumes_from: 139 | - web 140 | links: 141 | - web 142 | - mysql 143 | mysql-cli: 144 | image: mariadb 145 | env_file: .env 146 | links: 147 | - mysql:mysql 148 | command: bash -c 'exec mysql -hmysql -uroot -p$$MYSQL_ROOT_PASSWORD' 149 | volumes_from: 150 | - mysql 151 | EOT 152 | 153 | cat <<'EOT' > docker-compose.yml 154 | # dockerpresso 2.1.0 155 | version: '2' 156 | services: 157 | web: 158 | image: wordpress:$WORDPRESS_VERSION 159 | env_file: .env 160 | restart: always 161 | volumes: 162 | - ./wordpress_data:/var/www/html/ 163 | # uncomment line below to start theme development 164 | # directory below should contain theme style.css file 165 | # - ./example-theme-src:/var/www/html/wp-content/themes/example-theme 166 | # uncomment line below to start plugin development 167 | # directory below should contain main plugin PHP file 168 | # - ./example-plugin-src:/var/www/html/wp-content/plugins/example-plugin 169 | ports: 170 | - "80:80" 171 | links: 172 | - mysql 173 | mysql: 174 | image: mariadb 175 | restart: always 176 | env_file: .env 177 | ports: 178 | - "3306:3306" 179 | volumes: 180 | - mysql_data:/var/lib/mysql 181 | volumes: 182 | mysql_data: {} 183 | 184 | EOT 185 | 186 | cat <<'EOT' > Dockerpressofile 187 | #!/usr/bin/env sh 188 | # dockerpresso 2.1.0 189 | 190 | # This is file which will be run every time Dockerpresso managed Wordpress 191 | # is started or restarted. 192 | # You can use any wp-cli command here such as plugin installation or activation. 193 | # Use it to prepare environment your plugin or theme may need 194 | 195 | 196 | wp core install --url=localhost --title=Localhost --admin_user=admin --admin_password=pass --admin_email=admin@localhost.local 197 | 198 | EOT 199 | 200 | mkdir -p wordpress_data 201 | 202 | echo "Created following files:" 203 | echo "\t.env env vars for wp-config.php, defaults should be fine for most cases" 204 | echo "\tdocker-compose.yml main docker-compose file, edit it first to define your project" 205 | echo "\tdocker-compose.admin.yml additional docker-compose file to run one-off commands, does not require edits" 206 | echo "\tDockerpressofile sh script to provision Wordpress instance, good for installing plugins, changing options etc." 207 | echo "\twordpress_data contains wordpress files, convinent for debugging other plugins, themes or core files" 208 | echo "" 209 | echo "Review those files and run \`dockerpresso up\` to start" 210 | echo "Remember to add \`wordpress_data\` to .gitignore" 211 | ;; 212 | mysql-check) 213 | docker-compose $ALL_DC_FILES run --rm -T mysql-cli bash -c 'exec mysqladmin ping -h"$DB_HOST" --silent' 214 | ;; 215 | download) 216 | assert_initialized 217 | docker-compose $ALL_DC_FILES run --rm -T web-cli bash -c 'wp core download --version="$WORDPRESS_VERSION" --locale="$WORDPRESS_LOCALE"' 218 | ;; 219 | configure) 220 | assert_initialized 221 | docker-compose $ALL_DC_FILES run --rm -T web-cli wp config create --dbname="" --dbuser="" --skip-check --extra-php <