Skip to content

Instantly share code, notes, and snippets.

@pixelwatt
Created May 2, 2021 10:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixelwatt/16742298eb62f68a2f1064b535172f3b to your computer and use it in GitHub Desktop.
Save pixelwatt/16742298eb62f68a2f1064b535172f3b to your computer and use it in GitHub Desktop.
GitLab CI Deployment Script for WPEngine
stages:
- deploy
deploy_production:
stage: deploy
image: tetraweb/php:7.1
when: manual
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- apt-get install rsync
- npm install --global gulp-cli
script:
##
## If the theme being deployed does not allready exist on the target installation, you must use sftp to make an empty folder for the theme prior to running this deployment process. Otherwise, the script will fail midway through.
##
- npm install --save-dev
- gulp styles scripts
- ssh -p22 myinstall@myinstall.ssh.wpengine.net "wp maintenance-mode activate"
- ssh -p22 myinstall@myinstall.ssh.wpengine.net "mkdir -p /home/wpe-user/sites/myinstall/wp-content/themes/_tmp"
- rsync -rav -e ssh --exclude='.git/' --exclude='assets/css/bootstrap/' --exclude='node_modules/' --exclude='package-lock.json' --exclude='package.json' --exclude='.gitlab-ci.yml' --exclude='README.md' --delete-excluded ./ myinstall@myinstall.ssh.wpengine.net:/home/wpe-user/sites/myinstall/wp-content/themes/_tmp
- ssh -p22 myinstall@myinstall.ssh.wpengine.net "mv /home/wpe-user/sites/myinstall/wp-content/themes/mytheme /home/wpe-user/sites/myinstall/wp-content/themes/_old && mv /home/wpe-user/sites/myinstall/wp-content/themes/_tmp /home/wpe-user/sites/myinstall/wp-content/themes/mytheme"
- ssh -p22 myinstall@myinstall.ssh.wpengine.net "rm -rf /home/wpe-user/sites/myinstall/wp-content/themes/_old"
- ssh -p22 myinstall@myinstall.ssh.wpengine.net "wp maintenance-mode deactivate"
environment:
name: production
url: http://myinstall.wpengine.com/
only:
- master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment