Last active
August 29, 2015 14:05
-
-
Save dtateii/241e9d60ee839146bc27 to your computer and use it in GitHub Desktop.
Simple Webhook for use on Rackspace Cloud Sites with Dploy, when deployment includes code outside webroot, and webroot directory to be deployed has name other than 'content'.
This file contains hidden or 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
#!/bin/sh | |
# Post deployment routine | |
# | |
# Syncs files from webroot deployed with source-controlled | |
# dir name to Rackspace Cloud Sites webroot dir, 'content' | |
mount="/mnt/stor{***}/{******}/{******}" | |
domain="sub.domain.com" | |
webroot_source="web" # Webroot according to source-control | |
webroot_apache="content" # Webroot Apache will be serving | |
rsync -av $mount/$domain/web/$webroot_source/ $mount/$domain/web/$webroot_apache/ | |
echo "Sync complete." |
This file contains hidden or 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
<?php | |
/** | |
* Private webhook, runs pre/post deployment routines | |
*/ | |
// Configuration | |
$apikey = "{************}"; | |
$script_post = "../../dploy-{post/pre}.sh"; | |
// Authorization | |
$keypassed = filter_input(INPUT_GET, 'apikey', FILTER_SANITIZE_STRING); | |
if ($apikey !== $keypassed) { | |
header("HTTP/1.0 403 Forbidden"); | |
exit; | |
} | |
// Execution | |
$hook = filter_input(INPUT_GET, 'hook', FILTER_SANITIZE_STRING); | |
switch (strtolower($hook)) { | |
case 'post': | |
deploy_post(); | |
break; | |
case 'pre': | |
// deploy_pre(); | |
error_out(400, "Bad Request"); | |
break; | |
default: | |
error_out(400, "Bad Request"); | |
break; | |
} | |
// Deployment Hooks | |
function deploy_post() | |
{ | |
global $script_post; | |
$output = shell_exec('sh ' . $script_post); | |
if ($output) { | |
header("HTTP/1.0 200 OK"); | |
echo "Sync complete."; | |
exit; | |
} else { | |
error_out(500, "Internal Server Error"); | |
} | |
} | |
// Helpers | |
function error_out($code, $msg) | |
{ | |
header("HTTP/1.0 $code $msg"); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment