From 7b70cea20d1a4c02ef8c37ed46c5a398280ce23e Mon Sep 17 00:00:00 2001 From: Jordalgo Date: Tue, 24 Jan 2017 18:09:25 -0500 Subject: [PATCH 1/6] Add: setup/wp-config.php to gitignore --- .gitignore | 1 + setup/wp-config.php | 117 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 setup/wp-config.php diff --git a/.gitignore b/.gitignore index 046f84c..c6e0843 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ wp-config.php +!setup/wp-config.php node_modules npm-debug.log vendor diff --git a/setup/wp-config.php b/setup/wp-config.php new file mode 100644 index 0000000..b2b60b2 --- /dev/null +++ b/setup/wp-config.php @@ -0,0 +1,117 @@ + Date: Sun, 5 Feb 2017 14:44:27 -0500 Subject: [PATCH 2/6] Update: eslintrc --- .eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From d647bcf0d08907ee937fe87e1213563d7304ad6a Mon Sep 17 00:00:00 2001 From: Jordalgo Date: Sun, 5 Feb 2017 14:44:58 -0500 Subject: [PATCH 3/6] Update readme and change wp-config file name so the sample file doesn't get ignored by deploy-exclude --- docker-entrypoint-wordpress.sh | 4 ++-- setup/README.md | 4 ++-- setup/{wp-config.php => wp-config-sample.php} | 0 3 files changed, 4 insertions(+), 4 deletions(-) rename setup/{wp-config.php => wp-config-sample.php} (100%) 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..39bf3c5 100644 --- a/setup/README.md +++ b/setup/README.md @@ -34,8 +34,8 @@ 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 diff --git a/setup/wp-config.php b/setup/wp-config-sample.php similarity index 100% rename from setup/wp-config.php rename to setup/wp-config-sample.php From f31d5520e21b157cd92da3ead35a433c35b860cf Mon Sep 17 00:00:00 2001 From: Jordalgo Date: Sun, 19 Feb 2017 06:52:44 -0500 Subject: [PATCH 4/6] Update: build process Add flag to remove the docker container after running the build command. --- setup/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/README.md b/setup/README.md index 39bf3c5..81a0d4b 100644 --- a/setup/README.md +++ b/setup/README.md @@ -23,7 +23,7 @@ Copy the files from the composer container. This is so we don't have to re-insta ## Building and Deploying To prepare for deploying: -`docker run -i -t -v $(pwd)/.:/deploy -w="/deploy" wordpress_npm npm run build` +`docker run --rm -i -t -v $(pwd)/.:/deploy -w="/deploy" wordpress_npm npm run build` **Note** wordpress_npm will be a different name depending on the root name of your folder e.g. 'my-wordpress-site_npm'. From ffd085aaca9d3cccae26a9c3e7d3fdf27faa90a1 Mon Sep 17 00:00:00 2001 From: Jordalgo Date: Mon, 20 Feb 2017 08:34:51 -0500 Subject: [PATCH 5/6] Add: instructions on creating basic db backups --- .gitignore | 8 +++++++- setup/README.md | 12 ++++++++++-- setup/backup-db.sh | 3 +++ setup/crontab | 1 + setup/setup.sh | 1 + 5 files changed, 22 insertions(+), 3 deletions(-) create mode 100755 setup/backup-db.sh create mode 100644 setup/crontab diff --git a/.gitignore b/.gitignore index c6e0843..313914f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,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/setup/README.md b/setup/README.md index 81a0d4b..90ea332 100644 --- a/setup/README.md +++ b/setup/README.md @@ -42,11 +42,19 @@ On your server: #### 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 +66,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/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 From 509ef57b4d789143ce872da3be8433fe55caec66 Mon Sep 17 00:00:00 2001 From: Jordalgo Date: Wed, 31 Jan 2018 11:44:29 -0500 Subject: [PATCH 6/6] Add: build script and update readme --- setup/README.md | 10 ++++------ setup/build.sh | 11 +++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 setup/build.sh diff --git a/setup/README.md b/setup/README.md index 90ea332..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 --rm -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. 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 &&