Skip to content

Instantly share code, notes, and snippets.

@urre
Last active September 13, 2017 07:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urre/1b14a118edd762a0b1127d28d2053725 to your computer and use it in GitHub Desktop.
Save urre/1b14a118edd762a0b1127d28d2053725 to your computer and use it in GitHub Desktop.
Deploy a Bedrock based WordPress site using Shipit.js via Codeship CI/CD to a Cloudways server
const path = require('path');
require('dotenv').config();
const deployPath = '/home/master/applications/xxxxxxxxx/public_html';
module.exports = function (shipit) {
require('shipit-deploy')(shipit);
shipit.initConfig({
default: {
workspace: '/tmp/reponame',
repositoryUrl: 'git@github.com:githubuser/reponame.git',
branch: 'dev',
ignores: ['.git', 'node_modules', '.env', '.htaccess', 'uploads'],
keepReleases: 2,
rsync: ['--del'],
deleteOnRollback: false,
key: process.env.WP_ENV === 'development' ? '~/.ssh/id_rsa' : '',
shallowClone: true
},
staging: {
servers: 'user@IP',
deployTo: deployPath
}
});
shipit.blTask('composer', function () {
return shipit.remote(`cd ${deployPath}/current && composer install`);
});
shipit.blTask('npm', function () {
return shipit.remote(`cd ${deployPath}/current/web/app/themes/themename && npm install`);
});
shipit.blTask('assets', function () {
return shipit.remote(`cd ${deployPath}/current/web/app/themes/themename && npm run build`);
});
shipit.on('published', function () {
shipit.start(['composer', 'npm','assets']);
});
};
@urre
Copy link
Author

urre commented Jun 14, 2017

Codeship test and deploy settings

Test

nvm install 6.11.0
nvm use 6.11.0
npm install

Deployment using custom script

npm run deploy

Note: You will need a package.json in your project root with the following devDependencies and npm scripts. (run the rollback command from your local machine when you need)

  "scripts": {
    "deploy": "shipit staging deploy",
    "rollback": "shipit staging rollback"
  },
  "devDependencies": {
    "dotenv": "^4.0.0",
    "shipit-cli": "^3.0.0",
    "shipit-deploy": "^2.4.0"
  }

@urre
Copy link
Author

urre commented Jun 14, 2017

Protip

Purge Varnish and restart Memcached on your Cloudways server. You can use this as another custom script in the deployment chain on Codeship.

Get your Cloudways API key here

#!/bin/bash
EMAIL="your@email.com"
API_KEY="XXXXXXXXXXXXXXXX"
API_BASEURL="https://api.cloudways.com/api/v1"
SERVER_ID="XXXXX"

# Get Access token, valid for 1h (3600)
ACCESS_TOKEN=$(curl --silent --data "email=$EMAIL&api_key=$API_KEY" $API_BASEURL/oauth/access_token | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["'access_token'"]')

# Purge Varnish
curl --data "server_id=$SERVER_ID&action=purge" "$API_BASEURL/service/varnish" -H "Authorization: Bearer $ACCESS_TOKEN" &>/dev/null

# Restart Memcache
curl "$API_BASEURL/service?server_id=$SERVER_ID&service=memcached&state=restart" -H "Authorization: Bearer $ACCESS_TOKEN" &>/dev/null

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