예제 #1
0
 /**
  *@expectedException BuildException 
  */
 function testCantBuildCommand()
 {
     $option = "-avz ";
     $source = "";
     $destination = "pippo@www.ciccio.com:/var/www/pluto/";
     $deploy = new Deploy();
     $deploy->setSource($source);
     $deploy->setDestination($destination);
     $actualCommand = $deploy->buildCommand();
     try {
         $actualCommand = $deploy->buildCommand();
     } catch (BuildException $e) {
         var_dump($e->getMessage());
         $this->assertEquals("Parameters source and destination are required", $e->getMessage());
     }
 }
예제 #2
0
 /**
  * Decodes and validates the data from bitbucket and calls the 
  * deploy constructor to deploy the new code.
  *
  * @param 	string 	$payload 	The JSON encoded payload data.
  */
 function __construct($payload)
 {
     $payload = json_decode(stripslashes($_POST['payload']), true);
     $name = $payload['repository']['name'];
     $this->log($payload['commits'][0]['branch']);
     if (isset(parent::$repos[$name]) && parent::$repos[$name]['branch'] === $payload['commits'][0]['branch']) {
         $data = parent::$repos[$name];
         $data['commit'] = $payload['commits'][0]['node'];
         parent::__construct($name, $data);
     }
 }
예제 #3
0
 /**
  * Decodes and validates the data from github and calls the 
  * deploy constructor to deploy the new code.
  *
  * @param   string  $_payload   The JSON encoded payload data.
  * @param   array   $headers    Array with all the HTTP headers from the current request.
  */
 function __construct($_payload, $headers)
 {
     $payload = json_decode($_payload);
     $name = $payload->repository->name;
     $branch = basename($payload->ref);
     $commit = substr($payload->commits[0]->id, 0, 12);
     if (isset(parent::$repos[$name]) && parent::$repos[$name]['branch'] === $branch) {
         $data = parent::$repos[$name];
         $data['commit'] = $commit;
         parent::__construct($name, $data, $_payload, $headers);
     }
 }
 /**
  * Handle commit hook post from bitbucket or github
  * @return string
  */
 public function commit_hook()
 {
     if (isset($_POST['payload'])) {
         // github and bitbucket use a 'payload' parameter
         $json = $_POST['payload'];
     } else {
         $json = file_get_contents('php://input');
     }
     if (!$json) {
         DTLog::debug('ignored #1');
         return 'ignored';
     }
     $data = $json ? json_decode($json, true) : null;
     if (!$data || !is_array($data['commits'])) {
         DTLog::debug('ignored #2');
         return 'ignored';
     }
     // look through the commits
     $found = false;
     $tags = array();
     foreach ($data['commits'] as $commit) {
         if (preg_match('/\\[deploy(:.+)?\\]/', $commit['message'], $matches)) {
             $found = true;
             if (count($matches) > 1 && $matches[1] != '') {
                 $tags[] = substr($matches[1], 1);
             } else {
                 $tags[] = 'live';
             }
         }
     }
     if (!$found) {
         return 'ignored';
     }
     if (defined('DEPLOY_TAG') && !in_array(DEPLOY_TAG, $tags)) {
         DTLog::debug('ignored #3');
         return 'ignored';
     }
     // create the deployment
     increase_time_limit_to(600);
     $deploy = new Deploy(BASE_PATH, array());
     $deploy->post_deploy = function () use($deploy) {
         global $_FILE_TO_URL_MAPPING;
         // composer install if detected
         if (file_exists(BASE_PATH . DIRECTORY_SEPARATOR . 'composer.json')) {
             if (file_exists('/usr/local/bin/composer')) {
                 // TODO: more flexible composer detection
                 exec('composer install', $output);
                 DTLog::info('Executing composer install...' . implode("\n", $output));
                 //Checking for composer.phar
             } elseif (file_exists('/usr/local/bin/composer.phar')) {
                 exec('/usr/local/bin/composer.phar install', $output);
                 DTLog::info('Executing composer install...' . implode("\n", $output));
             } else {
                 DTLog::info('composer.json detected but unable to locate composer.');
             }
         }
         // clear cache
         DTLog::info('Clearing cache...');
         DeployController::clear_cache();
         // update database
         if (isset($_FILE_TO_URL_MAPPING[BASE_PATH])) {
             exec('php framework/cli-script.php dev/build', $output2);
             DTLog::info('Updating database...' . implode("\n", $output2));
         } else {
             DTLog::info('Database not updated. $_FILE_TO_URL_MAPPING must be set for ' . BASE_PATH);
         }
         //    		SS_ClassLoader::instance()->getManifest()->regenerate();
         //            ob_start();
         //            DatabaseAdmin::create()->doBuild(false, true, false);
         //            DTLog::info('dev/build complete: '.ob_get_contents());
         //            ob_end_clean();
     };
     $deploy->execute();
     return 'ok';
 }
     * Executes the necessary commands to deploy the website.
     */
    public function execute()
    {
        try {
            // Update the local repository
            exec('cd ' . $this->_git_dir . ' && ' . $this->_git_bin_path . ' fetch', $output);
            $this->log('Fetching changes... ' . implode(' ', $output));
            // Checking out to web directory
            exec('cd ' . $this->_git_dir . ' && GIT_WORK_TREE=' . $this->_www_dir . ' ' . $this->_git_bin_path . ' checkout -f', $output);
            $this->log('Checking out changes to www directory... ' . implode(' ', $output));
            if (is_callable($this->post_deploy)) {
                call_user_func($this->post_deploy, $this->_data);
            }
            $this->log('Deployment successful.');
        } catch (Exception $e) {
            $this->log($e, 'ERROR');
        }
    }
}
$deploy = new Deploy($git_serverpath, $www_serverpath);
/*
$deploy->post_deploy = function() use ($deploy) {
  // hit the wp-admin page to update any db changes
   exec('curl http://example.com/wp-admin/upgrade.php?step=upgrade_db');
   $deploy->log('Updating wordpress database... ');
};
*/
if ($_GET[key] === $secret_key) {
    $deploy->execute();
}
예제 #6
0
    {
        try {
            // Make sure we're in the right directory
            chdir($this->_path);
            // Discard any changes to tracked files since our last deploy
            exec('git reset --hard HEAD', $output);
            // Update the local repository
            exec('git pull ' . $this->_remote . ' ' . $this->_branch . ' 2>&1', $output, $return_var);
            if ($return_var != 0) {
                throw new Exception("Git pull failed", 1);
            }
            // Secure the .git directory
            echo exec('chmod -R og-rx .git');
            if (is_callable($this->_post_deploy)) {
                call_user_func($this->_post_deploy);
            }
            $log_msg = "[SHA: {$this->_commit} Deployment of {$this->_name} from branch {$this->_branch} successful" . $this->log($log_msg);
            echo $log_msg;
            if (DEPLOY_FULL_OUTPUT) {
                $this->log($output);
            }
        } catch (Exception $e) {
            $this->log($e, 'ERROR');
            $this->log($output);
        }
    }
}
// Registers all of our repos with the Deploy class
foreach ($repos as $name => $repo) {
    Deploy::register_repo($name, $repo);
}
예제 #7
0
 /**
  * Deploy a new service or update an old one
  * */
 public function deployAction()
 {
     $this->view->title = "Deploy a service";
     // handle the submit if a service is posted
     if ($this->request->isPost()) {
         // check the file is a valid zip
         $fileNameArray = explode(".", $_FILES["service"]["name"]);
         $extensionIsZip = strtolower(end($fileNameArray)) == "zip";
         if (!$extensionIsZip) {
             $this->view->deployingError = "The file is not a valid zip";
             return;
         }
         // check the service zip size is less than 1MB
         if ($_FILES["service"]["size"] > 1048576) {
             $this->view->deployingError = "The file is too big. Our limit is 1 MB";
             return;
         }
         // check for errors
         if ($_FILES["service"]["error"] > 0) {
             $this->view->deployingError = "Unknow errors uploading your service. Please try again";
             return;
         }
         // include and initialice Deploy class
         $deploy = new Deploy();
         // get the zip name and path
         $utils = new Utils();
         $wwwroot = $this->di->get('path')['root'];
         $zipPath = "{$wwwroot}/temp/" . $utils->generateRandomHash() . ".zip";
         $zipName = basename($zipPath);
         // save file
         if (isset($_FILES["service"]["name"])) {
             $zipName = $_FILES["service"]["name"];
         }
         move_uploaded_file($_FILES["service"]["tmp_name"], $zipPath);
         chmod($zipPath, 0777);
         // check if the file was moved correctly
         if (!file_exists($zipPath)) {
             $this->view->deployingError = "There was a problem uploading the file";
             return;
         }
         // get the deploy key
         $deployKey = $this->request->getPost("deploykey");
         // deploy the service
         try {
             $deployResults = $deploy->deployServiceFromZip($zipPath, $deployKey, $zipName);
         } catch (Exception $e) {
             $error = preg_replace("/\r|\n/", "", $e->getMessage());
             $this->view->deployingError = $error;
             return;
         }
         // send email to the user with the deploy key
         $today = date("Y-m-d H:i:s");
         $serviceName = $deployResults["serviceName"];
         $creatorEmail = $deployResults["creatorEmail"];
         $deployKey = $deployResults["deployKey"];
         $email = new Email();
         $email->sendEmail($creatorEmail, "Your service {$serviceName} was deployed", "<h1>Service deployed</h1><p>Your service {$serviceName} was deployed on {$today}. Your Deploy Key is {$deployKey}. Please keep your Deploy Key secured as per you will need it to upgrade or remove your service later on.</p><p>Thank you for using Apretaste</p>");
         // redirect to the upload page with success message
         $this->view->deployingMesssage = "Service deployed successfully. Your new deploy key is {$deployKey}. Please copy your deploy key now and keep it secret. Without your deploy key you will not be able to update your Service later on";
     }
 }
예제 #8
0
<?php

require_once 'lib/base/BaseDeploy.class.php';
require_once 'lib/Deploy.class.php';
require_once 'lib/exceptions/DeployException.class.php';
$deploy = new Deploy(array('project_name' => 'project', 'basedir' => dirname(__FILE__), 'remote_host' => 'www.example.com', 'remote_port' => 22, 'remote_dir' => '/home/user/project', 'remote_user' => 'user', 'rsync_excludes' => 'config/rsync_exclude.txt', 'data_dirs' => array('web/uploads', 'logs'), 'target_specific_files' => array('web/.htaccess', 'config/database.php'), 'target' => 'prod', 'datadir_patcher' => 'lib/deployer/datadir-patcher.php'));
switch ($_SERVER['argv'][1]) {
    case 'deploy':
        $deploy->deploy();
        break;
    case 'rollback':
        $deploy->rollback();
        break;
    case 'cleanup':
        $deploy->cleanup();
        break;
    default:
        echo 'Usage: php deploy.php [deploy|rollback|cleanup]' . PHP_EOL;
}
예제 #9
0
//include lib (tpl smarty in deploy)
include "deploy/deploylib/ext/Smarty-3.1.21/libs/Smarty.class.php";
//include conf deploy
$conf = array();
if (file_exists("deploy/conf.deploy.php")) {
    include "deploy/conf.deploy.php";
}
//include package chain deploy
if (file_exists("deploy/package.chain.deploy.php")) {
    include "deploy/package.chain.deploy.php";
}
//log (not used)
$instanceLog = new Log($conf);
$log = $instanceLog->logselected;
//init deploy class
$instanceDeploy = new Deploy($tabpackagetodeploy, $conflictresolution);
$instanceDeploy->log = $log;
//log init for deploy
//ajax gestion pour deploy
if (isset($_GET['ajax']) && $_GET['ajax'] != "") {
    include "deploy/deployajax/" . $_GET['ajax'] . ".php";
    exit;
}
//steps allowed in $_POST
$tabstep = array();
$tabstep[] = "downloadstep";
//init deploypage
$deploypage = "startdeploy";
$deploypagetpl = $deploypage;
//get deploypage
$cptpackagecour = 0;
예제 #10
0
파일: deploy.php 프로젝트: chris27tina/TODO
    {
        try {
            // Make sure we're in the right directory
            exec('cd ' . $this->_directory, $output);
            $this->log('Changing working directory... ' . implode(' ', $output));
            // Discard any changes to tracked files since our last deploy
            exec('git reset --hard HEAD', $output);
            $this->log('Reseting repository... ' . implode(' ', $output));
            // Update the local repository
            exec('git pull ' . $this->_remote . ' ' . $this->_branch, $output);
            $this->log('Pulling in changes... ' . implode(' ', $output));
            // Secure the .git directory
            exec('chmod -R og-rx .git');
            $this->log('Securing .git directory... ');
            if (is_callable($this->post_deploy)) {
                call_user_func($this->post_deploy, $this->_data);
            }
            $this->log('Deployment successful.');
        } catch (Exception $e) {
            $this->log($e, 'ERROR');
        }
    }
}
// This is just an example
$deploy = new Deploy('/var/www/foobar.com');
$deploy->post_deploy = function () use($deploy) {
    // hit the wp-admin page to update any db changes
    exec('curl http://www.foobar.com/wp-admin/upgrade.php?step=upgrade_db');
    $deploy->log('Updating wordpress database... ');
};
$deploy->execute();