├── README.md └── wpedeploy.sh /README.md: -------------------------------------------------------------------------------- 1 | This code is **old and no longer works** for Sage v9 and later. Check out [Toby's blog post](https://tobyschrapel.com/deploying-sage-9-blade-templates-to-wp-engine-using-gitlab-ci-pipelines/) for a solution. 2 | 3 | --- 4 | 5 | # Deploy Roots Bedrock WordPress project to WP Engine hosting platform 6 | 7 | Works up to Bedrock 1.7.2. Deploys themes, plugins, and mu-plugins. 8 | 9 | Repo: [https://github.com/hello-jason/bedrock-deploy-to-wpengine](https://github.com/hello-jason/bedrock-deploy-to-wpengine) 10 | 11 | ## Changelog 12 | 13 | v2 - Removes build process for Sage theme. Now focuses purely on deploying your Bedrock project, regardless of theme. Grab the branch `master`. 14 | 15 | v1 - Works up to Bedrock 1.7.2, Sage 8.5. Grab the branch `release/1.0.0`. 16 | 17 | ## Description 18 | 19 | This bash script prepares a WordPress project built on Root's [Bedrock](https://roots.io/bedrock/) boilerplate and deploys it **to the WP Engine hosting platform**. 20 | 21 | WP Engine expects to see a standard WordPress project in the document root for your account. Since Bedrock shifts folders and files around a bit, this script temporarily moves everything back to their original locations (on a safe, temporary branch), which is then pushed to WP Engine. 22 | 23 | The result is a properly-versioned Bedrock repo that you can safely and repeatedly deploy to WP Engine's production and staging environments. 24 | 25 | Demo: 26 | 27 | * Demo Bedrock site on WP Engine: [http://rootsbedrock.wpengine.com/](http://rootsbedrock.wpengine.com/) 28 | * Demo Bedrock site repo: [https://github.com/hello-jason/bedrock-on-wpengine-demo](https://github.com/hello-jason/bedrock-on-wpengine-demo) 29 | 30 | ## Installation & Setup 31 | 32 | ### 1. Grab the script 33 | 34 | Source code is available at [https://github.com/hello-jason/bedrock-deploy-to-wpengine](https://github.com/hello-jason/bedrock-deploy-to-wpengine). This repo is not meant to be cloned into your project. Rather, just grab the `wpedeploy.sh` file and place it in the top-level directory of your Bedrock project, and keep it with your project's repo. 35 | 36 | ### 2. Setup git push 37 | 38 | Follow [these instructions from WP Engine](https://wpengine.com/git/) to setup SSH access and git push for your WP Engine account. 39 | 40 | This readme assumes your remotes are named as follows: 41 | 42 | * **Production**: wpeproduction 43 | * **Staging**: wpestaging 44 | 45 | ## Usage 46 | 47 | Run at the **top level** of your project, in the same directory as your `.env` and `composer.json` files. Replace each remote name with the ones you created during step 1. 48 | 49 | Deploy to staging: 50 | 51 | ``` 52 | bash wpedeploy.sh wpestaging 53 | ``` 54 | 55 | Deploy to production: 56 | 57 | ``` 58 | bash wpedeploy.sh wpeproduction 59 | ``` 60 | 61 | ## FAQs 62 | 63 | * **Which branch does it deploy?** - Deploys the local branch you run it on to whichever WP Engine remote you specify (production or staging) 64 | * **What about the uploads directory?** - Completely ignores the uploads directory. You'll have to upload that separately [via SFTP](https://wpengine.com/support/sftp/). 65 | * **How does it handle plugin versions?** - You can upgrade or downgrade version numbers in the `composer.json` file, run `composer update`, then run this script to deploy the new version to WP Engine. However, this script **will not delete** plugins from WP Engine's servers; you will have to do that via SFTP or wp-admin. 66 | * **What about WordPress core?** - This script only deploys the contents of `wp-content` to WP Engine's servers. You should keep WordPress core updated in your composer file, but that only benefits your local dev environment. You will manage WP core for your publicly-facing site in WP Engine's interface directly. 67 | * **Why doesn't it work on Ubuntu?** - It does! But Ubuntu defaults to `dash` rather than `bash`, and the script may fail if you simply run `sh`. Other distros may do the same, so running this script with the `bash` command is important. 68 | * **Why did you remove the build processes for Sage?** - Since each project will have a different build process for its theme, it makes more sense to focus solely on deploying to WP Engine. More info in [this issue](https://github.com/hello-jason/bedrock-sage-deploy-to-wpengine/issues/13). 69 | -------------------------------------------------------------------------------- /wpedeploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Version: 2.2 3 | # Last Update: December 29, 2016 4 | # 5 | # Description: Bash script to deploy a Bedrock WordPress project to WP Engine's hosting platform 6 | # Repository: https://github.com/hello-jason/bedrock-deploy-to-wpengine.git 7 | # README: https://github.com/hello-jason/bedrock-deploy-to-wpengine/blob/master/README.md 8 | # 9 | # Tested Bedrock Version: 1.7.2 10 | # Tested bash version: 4.3.42 11 | # Author: Jason Cross 12 | # Author URL: https://hellojason.net/ 13 | ######################################## 14 | # Usage 15 | ######################################## 16 | # bash wpedeploy.sh nameOfRemote 17 | 18 | ######################################## 19 | # Thanks 20 | ######################################## 21 | # Thanks to [schrapel](https://github.com/schrapel/wpengine-bedrock-build) for 22 | # providing some of the foundation for this script. 23 | # Also thanks to [cmckni3](https://github.com/cmckni3) for guidance and troubleshooting 24 | 25 | ######################################## 26 | # Set variables 27 | ######################################## 28 | # WP Engine remote to deploy to 29 | wpengineRemoteName=$1 30 | # Get current branch user is on 31 | currentLocalGitBranch=`git rev-parse --abbrev-ref HEAD` 32 | # Temporary git branch for building and deploying 33 | tempDeployGitBranch="wpedeployscript/${currentLocalGitBranch}" 34 | 35 | ######################################## 36 | # Perform checks before running script 37 | ######################################## 38 | 39 | # Halt if there are uncommitted files 40 | function check_uncommited_files () { 41 | if [[ -n $(git status -s) ]]; then 42 | echo -e "[\033[31mERROR\e[0m] Found uncommitted files on current branch \"$currentLocalGitBranch\".\n Review and commit changes to continue." 43 | git status 44 | exit 1 45 | fi 46 | } 47 | 48 | # Check if specified remote exists 49 | function check_remote_exists () { 50 | echo "Checking if specified remote exists..." 51 | git ls-remote "$wpengineRemoteName" &> /dev/null 52 | if [ "$?" -ne 0 ]; then 53 | echo -e "[\033[31mERROR\e[0m] Unknown git remote \"$wpengineRemoteName\"\n Visit \033[32mhttps://wpengine.com/git/\e[0m to set this up." 54 | echo "Available remotes:" 55 | git remote -v 56 | exit 1 57 | fi 58 | } 59 | 60 | # Gets current timestamp when called 61 | function timestamp () { 62 | date 63 | } 64 | 65 | ######################################## 66 | # Begin deploy process 67 | ######################################## 68 | function deploy () { 69 | # Checkout new temporary branch 70 | echo -e "Preparing theme on branch ${tempDeployGitBranch}..." 71 | git checkout -b "$tempDeployGitBranch" &> /dev/null 72 | 73 | # Run composer 74 | composer install 75 | # Setup directory structure 76 | mkdir wp-content && mkdir wp-content/themes && mkdir wp-content/plugins && mkdir wp-content/mu-plugins 77 | # Copy meaningful contents of web/app into wp-content 78 | cp -rp web/app/plugins wp-content && cp -rp web/app/themes wp-content && cp -rp web/app/mu-plugins wp-content 79 | 80 | ######################################## 81 | # Push to WP Engine 82 | ######################################## 83 | # WPE-friendly gitignore 84 | echo -e "# Ignore everything\n/*\n\n# Except this...\n!wp-content/\n!wp-content/**/*" > .gitignore 85 | git rm -r --cached . &> /dev/null 86 | # Find and remove nested git repositories 87 | rm -rf $(find wp-content -name ".git") 88 | rm -rf $(find wp-content -name ".github") 89 | 90 | git add --all 91 | git commit -m "Automated deploy of \"$tempDeployGitBranch\" branch on $(timestamp)" 92 | echo "Pushing to WP Engine..." 93 | 94 | # Push to a remote branch with a different name 95 | # git push remoteName localBranch:remoteBranch 96 | git push "$wpengineRemoteName" "$tempDeployGitBranch":master --force 97 | 98 | ######################################## 99 | # Back to a clean slate 100 | ######################################## 101 | git checkout "$currentLocalGitBranch" &> /dev/null 102 | rm -rf wp-content/ &> /dev/null 103 | git branch -D "$tempDeployGitBranch" &> /dev/null 104 | echo -e "[\033[32mDone\e[0m] Deployed \"$tempDeployGitBranch\" to \"$wpengineRemoteName\"" 105 | } 106 | 107 | ######################################## 108 | # Execute 109 | ######################################## 110 | # Checks 111 | check_uncommited_files 112 | check_remote_exists 113 | 114 | # Uncomment the following line for debugging 115 | # set -x 116 | 117 | # Deploy process 118 | deploy 119 | --------------------------------------------------------------------------------