Last active
September 13, 2017 07:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | |
}); | |
}; |
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
Codeship test and deploy settings
Test
Deployment using custom script
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)