diff --git a/.eslintrc b/.eslintrc index 81bffab..6dc47ec 100644 --- a/.eslintrc +++ b/.eslintrc @@ -36,7 +36,7 @@ rules: max-len: [2, 120] new-cap: 1 valid-jsdoc: 0 - no-use-before-define: 1 + no-use-before-define: [0, { "functions": false }] block-scoped-var: 0 strict: 0 no-underscore-dangle: 0 diff --git a/.gitignore b/.gitignore index 046f84c..313914f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ wp-config.php +!setup/wp-config.php node_modules npm-debug.log vendor @@ -11,8 +12,14 @@ wp-content/uploads # these are customized by the setup composer.json +!setup/composer.json deploy-exclude-list.txt +!setup/deploy-exclude-list.txt deploy.sh +!setup/deploy.sh gulpfile.js +!setup/gulpfile.js package.json - +!setup/package.json +backup-db.sh +!setup/backup-db.sh diff --git a/docker-entrypoint-wordpress.sh b/docker-entrypoint-wordpress.sh index 02d3a28..f960186 100755 --- a/docker-entrypoint-wordpress.sh +++ b/docker-entrypoint-wordpress.sh @@ -24,10 +24,10 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then # version 4.4.1 decided to switch to windows line endings, that breaks our seds and awks # https://github.com/docker-library/wordpress/issues/116 # https://github.com/WordPress/WordPress/commit/1acedc542fba2482bab88ec70d4bea4b997a92e4 - sed -ri 's/\r\n|\r/\n/g' ./setup/wp-config* + sed -ri 's/\r\n|\r/\n/g' ./setup/wp-config-sample* if [ ! -e wp-config.php ]; then - awk '/^\/\*.*stop editing.*\*\/$/ && c == 0 { c = 1; system("cat") } { print }' ./setup/wp-config.php > wp-config.php <<'EOPHP' + awk '/^\/\*.*stop editing.*\*\/$/ && c == 0 { c = 1; system("cat") } { print }' ./setup/wp-config-sample.php > wp-config.php <<'EOPHP' // If we're behind a proxy server and using HTTPS, we need to alert Wordpress of that fact // see also http://codex.wordpress.org/Administration_Over_SSL#Using_a_Reverse_Proxy if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { diff --git a/setup/README.md b/setup/README.md index c5968be..d544850 100644 --- a/setup/README.md +++ b/setup/README.md @@ -12,20 +12,18 @@ This creates four docker containers: - NPM Container (install javascript dependencies, and task run for the default theme) - Composer Container (wordpress plugins & *wordpress itself* which is version controlled via composer) -If you update the package.json or composer.json file you have to rebuild the images `docker-compose build`. +If you update the package.json or composer.json file you have to rebuild the images `docker-compose build && sh build.sh`. -Copy the files from the composer container. This is so we don't have to re-install the composer packages every `up` and they can also be rsynced up to the server for deployment. -- `docker cp wp-docker-composer:/var/www/html/wp-content/plugins ./wp-content/` -- `docker cp wp-docker-composer:/var/www/html/wordpress .` +Copy the files from the composer container. This is so we don't have to re-install the composer packages every `up` and they can also be rsynced up to the server for deployment. Run `sh build.sh` **Note**: You don't have to re-run above if you already have the wordpress and plugins folders in the local directory and you haven't changed the composer.json file. ## Building and Deploying To prepare for deploying: -`docker run -i -t -v $(pwd)/.:/deploy -w="/deploy" wordpress_npm npm run build` +`sh build.sh` -**Note** wordpress_npm will be a different name depending on the root name of your folder e.g. 'my-wordpress-site_npm'. +**Note** The Docker image name depends on the root name of your folder e.g. 'my-wordpress-site_npm'. This runs the build command in package.json within a temporary container built from the wordpress_npm image. @@ -34,19 +32,27 @@ This current setup uses `rsync` via `deploy.sh` (which was copied into the root Update the `deploy.sh` file by changing USERNAME, DOMAIN, and FOLDER to match your remote server's information. Then you can run `sh deploy.sh`. On your server: -- `cp setup/htaccess-remote .htaccess` (this version has more security settings) -- `cp setup/wp-config.php wp-config.php`. Then update the database values to match what you have configured with your web host AND fill in the unique keys and salts ([generate these](https://api.wordpress.org/secret-key/1.1/salt)). It's also a good idea to change the table prefix from `wp_` to something unique. +- `cp setup/htaccess-remote .htaccess` (this version has more security settings but you will need to update it with your site details). +- `cp setup/wp-config-sample.php wp-config.php`. Then update the database values to match what you have configured with your web host AND fill in the unique keys and salts ([generate these](https://api.wordpress.org/secret-key/1.1/salt)). It's also a good idea to change the table prefix from `wp_` to something unique. ## More Details #### Adding more Wordpress Plugins Add the plugins to composer.json (search for the [here](https://wpackagist.org)); a few are in there already as examples. -#### Connecting to the MySql Container from Sequel Pro? +#### Connecting to the MySql Container from Sequel Pro. Host: 0.0.0.0 Port: 32769 or something similar. Make sure you check the actual port as it can be different everytime. `docker ps -a`. +#### Remote DB Syncing with Local +This technique is very basic at the moment. +- create a folder on your remote server called "_db_backups" +- Update the "backup-db.sh" file in your root directory with your mysql info and then run this script: `sh backup-db.sh` on your remote server. +- Then on your local machine, copy the generated mysql dump files: `scp -P 2222 -r USER_NAME@HOST_ADDRESSS:/absolute/path/to/_db_backups/ .` +- You can then use these gzipped mysql files locally when you spin up your dev environment. +- *Note* You can also setup a crontab (example in the setup folder) to run this script on a certain schedule. + #### Kill And remove All containers `docker rm -fv $(docker ps -aq)` @@ -58,5 +64,5 @@ If you don't have a use for a custom theme that has a dev workflow run on NPM an ## Todo - Add details on remote server configuration. -- Include steps on deploying (via rsync to start). - Remove gulp (or make it more agnostic to the setup). +- Create better/safer way to backup whole site (db, uploads, etc...) diff --git a/setup/backup-db.sh b/setup/backup-db.sh new file mode 100755 index 0000000..61b5477 --- /dev/null +++ b/setup/backup-db.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# note: keep the password within the single quotes below +mysqldump -u USERNAME -p'PW' DB_NAME | gzip > $HOME/public_html/_db_backups/DBNAME_`date '+%m-%d-%Y_%H-%M'`.sql.gz diff --git a/setup/build.sh b/setup/build.sh new file mode 100644 index 0000000..a7b5391 --- /dev/null +++ b/setup/build.sh @@ -0,0 +1,11 @@ +#!/bin/bash -e + +echo "Please enter Docker NPM image name (e.g. my-wordpress-site_npm): " +read imagename + +echo "Copying Wordpress Plugins from Container" && +docker cp wp-docker-composer:/var/www/html/wp-content/plugins ./wp-content/ && +echo "Copying Wordpress from Container" && +docker cp wp-docker-composer:/var/www/html/wordpress . && +echo "Building CSS and JS for template" && +docker run --rm -i -t -v $(pwd)/.:/var/www/html -w="/var/www/html" $imagename npm run build && diff --git a/setup/crontab b/setup/crontab new file mode 100644 index 0000000..0dd0ad0 --- /dev/null +++ b/setup/crontab @@ -0,0 +1 @@ +# 25 0 * * 0 "$HOME/html/backup-db.sh" diff --git a/setup/setup.sh b/setup/setup.sh index 5df6ffd..a8ad869 100644 --- a/setup/setup.sh +++ b/setup/setup.sh @@ -6,6 +6,7 @@ customized_files=( 'deploy-exclude-list.txt' 'gulpfile.js' 'package.json' + 'backup-db.sh' ) for i in ${customized_files[@]}; do diff --git a/setup/wp-config-sample.php b/setup/wp-config-sample.php new file mode 100644 index 0000000..b2b60b2 --- /dev/null +++ b/setup/wp-config-sample.php @@ -0,0 +1,117 @@ +