Skip to content

Instantly share code, notes, and snippets.

@josefadamcik
Created August 30, 2011 09:17
Show Gist options
  • Save josefadamcik/1180517 to your computer and use it in GitHub Desktop.
Save josefadamcik/1180517 to your computer and use it in GitHub Desktop.
little tool for deploying git project over ftp
<?php
//ftp deploy helper (git only)
$targetDir = "../webdeploy";
//$lastDeploy = "bd777c31090f9e22aef12e61f7ba64c39f09f5d0";
if (isset($argv[1])) {
$lastDeploy = $argv[1];
}
$cfgWarning = array();
prepareDeployDir($targetDir);
$files = getFileDiff($lastDeploy);
printn("[deploy] copyingfiles: ");
//print_r($files);
foreach($files as $file) {
$dir = dirname($file);
$target =$targetDir . "/" . $file;
$basename = basename($file);
printn("\t[cp]\t" . basename($file). "\tin " . dirname($file) );
if (!file_exists($targetDir . "/" . $dir)) {
mkdir ($targetDir . "/" . $dir, 0777, true);
}
exec("cp $file $target");
//check if we have to upload changed config files
if (strpos($dir, 'config') !== false) {
$cfgWarning[] = $file;
}
}
//config deploy warning
if (count($cfgWarning) > 0) {
printn("[WARN] config files exported, check changes!!");
foreach ($cfgWarning as $wrnFile) {
printn("\t" . $wrnFile);
}
}
//FIXME: handle symlinks
function getFileDiff($lastDeploy) {
$diffOutput = array();
exec("git diff --name-only $lastDeploy HEAD", $diffOutput);
return $diffOutput;
}
function prepareDeployDir($dir) {
if (file_exists($dir)) {
printn("[deploy] removing old target dir $dir");
exec("rm -rf $dir");
}
mkdir($dir, 0777, true);
}
function printn($str = "") {
print $str."\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment