Skip to content

Instantly share code, notes, and snippets.

@khoipro
Created June 24, 2019 09:30
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save khoipro/4df13fe0231d37a9bd8ae5493c6d7f97 to your computer and use it in GitHub Desktop.
Save khoipro/4df13fe0231d37a9bd8ae5493c6d7f97 to your computer and use it in GitHub Desktop.
Deploy from GitLab to WPEngine (Tested)
stages:
- deploy_dev
- deploy_staging
- deploy_live
before_script:
- 'which ssh-agent || ( apk add --update openssh )'
- apk add --update bash
- apk add --update git
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY"
- echo "$SSH_PRIVATE_KEY" | ssh-add -
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
Deploy Dev:
stage: deploy_dev
script:
- git remote add dev $WPENGINE_DEV_GIT
- "git checkout -b dev"
- "git push dev HEAD:master --force"
only:
- develop
Deploy Staging:
stage: deploy_staging
script:
- git remote add staging $WPENGINE_STAGING_GIT
- "git checkout -b staging"
- "git push staging HEAD:master --force"
only:
- master
Deploy Live:
stage: deploy_live
when: manual
script:
- git remote add live $WPENGINE_LIVE_GIT
- "git checkout -b live"
- "git push live HEAD:master --force"
only:
- tags
@khoipro
Copy link
Author

khoipro commented Jun 24, 2019

Available parameters to work:

https://gitlab.com/<your-repo-path>/-/settings/ci_cd
  • SSH_PRIVATE_KEY (run pbcopy > ~/.ssh/id_rsa and paste)
  • WPENGINE_DEV_GIT - the full path of Git repo, (for example: git@git.wpengine.com:production/devkhoipro.git)
  • WPENGINE_STAGING_GIT
  • WPENGINE_LIVE_GIT

Deployment Process

Branch | Environment
========================
develop ==> Development
master (pushed, no new tag) => Staging
master (with new tag) => Staging + Live

@peterjudicialwatch
Copy link

Thanks Khoipro It was a good start:

@khoipro
Copy link
Author

khoipro commented Aug 7, 2019

The quick note:

You also need to add a private key to WPEngine to ensure the GitLab CI could be create a new commit or push to WPEngine.

Have a nice day!

@peterjudicialwatch thank you! Hope you enjoy it!

@stalwil
Copy link

stalwil commented Apr 3, 2024

@khoipro - i know this was 5 years ago...but i was wondering...if i create this file and push it to my repo (dev branch) in gitlab...how does it know to only deploy to my dev environment in WPEngine?

Process DEV

  1. Push to dev branch (gitlab.com)
  2. Deploy to dev environment (wpengine)

Process STAGE

  1. Push to stage branch (gitlab.com)
  2. Deploy to stage environment (wpengine)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment