Categories
Tips and Trick

DevOps: Deploy from GitLab to WPEngine


Warning: preg_match(): Delimiter must not be alphanumeric or backslash in /home/khoipro/public_html/wp-includes/class-wp-embed.php on line 172

GitLab CI/CD is configured by a file called .gitlab-ci.yml placed at the repository’s root. The scripts set in this file are executed by the GitLab Runner.

We received a project from a client last week. The client is using WPEngine for their existing code and would to create some more new templates for this website.

The trouble comes soon. Their code base is written without using any Version Control, such like Git or SVN. So we need to add Version Tracking to all existing codes (haha, don’t worry, at least I never add wp-config.php to my repository).

After that, we don’t want to push directly to WPEngine, because we will miss some assets which are compiled after running “webpack build” command.

Then we decide to create a small script which run in GitLab CI/CD to do our two things:

  • Compile source (JS, CSS) and minify everything. Save it as a new commit which stores in GitLab Runner’s Docker only.
  • Push recent changes, certainly, including process commit, to WPEngine.

The second issue we wish to resolve is: WPEngine provides multiple environments, such like Production, Development and Staging. The client wish to see some changes in Development and Staging before releasing to Production.

So our script will also need to handle this goal.

OK, too much talk, we will try to show you how to do that by code. You will still to add some settings to Settings | CI/CD in each project, including:

  • SSH_PRIVATE_KEY
  • WPENGINE_DEV_GIT
  • WPENGINE_STAGING_GIT
  • WPENGINE_LIVE_GIT
https://gist.github.com/khoipro/4df13fe0231d37a9bd8ae5493c6d7f97

Leave a Reply

Your email address will not be published. Required fields are marked *