public function run(Context $context, Environment $environment, ConnectionInterface $connection = null) { // Make sure releases directory exists $connection->execute("mkdir -p {$environment->remote->path}/{$environment->remote->releaseDir}"); // Create a new release $release = date('YmdHis'); if (($branch = $context->getArgument(['b', 'branch'])) === null) { $branch = $environment->code->branch; } if (($commit = $context->getArgument(['c', 'commit'])) === null) { $commit = null; } // What SCM command? switch (strtolower($environment->code->scm)) { case 'git': if ($commit) { $command = "git clone {$environment->code->repo} --branch={$branch} {$release}&&cd {$release}&&git checkout {$commit}"; } else { $command = "git clone {$environment->code->repo} --depth=1 --branch={$branch} {$release}"; } break; case 'svn': $command = "svn checkout {$environment->code->repo} {$release}"; break; default: throw new \Exception("Unsupported SCM: {$environment->code->scm} should be one of GIT or SVN"); } // Execute release $connection->execute("cd {$environment->remote->deployTo}&&{$command}"); // Remove old symlink $connection->execute("rm -f {$environment->remote->currentRelease}"); // Create new symlink $connection->execute("cd {$environment->remote->path}&&ln -s -r {$environment->remote->releaseDir}/{$release} {$environment->remote->symlink}"); }
public function run(Context $context) { // Check for required environment param if (($env = $context->getArgument(['e', 'environment'])) === null) { throw new \Exception("No environment specified"); } // Get the environment config if (($environment = $context->config->getEnvironment($env)) == false) { throw new \Exception("No environment config found for \"{$env}\"."); } if ($environment->preDeploy) { $connection = new LocalConnection(); foreach ($environment->preDeploy as $task) { Task::run($task, $context, $environment, $connection); } } // loop through servers and implement strategy on each foreach ($environment->servers as $server) { if (empty($server->strategy)) { throw new \Exception("No strategy defined! Please define a global, environmental, or per-server strategy. See the manual for defining strategies."); } $connection = new RemoteConnection($server, $environment->authentication); foreach ($server->strategy as $task) { Task::run($task, $context, $environment, $connection); } $connection->close(); } if ($environment->postDeploy) { $connection = new LocalConnection(); foreach ($environment->postDeploy as $task) { Task::run($task, $context, $environment, $connection); } } }
public function run(Context $context) { // Check for required environment param if (($env = $context->getArgument(['e', 'environment'])) === null) { throw new \Exception("No environment specified"); } // Get the environment config if (($environment = $context->config->getEnvironment($env)) == false) { throw new \Exception("No environment config found for \"{$env}\"."); } // Specific release to roll back to? $specificRelease = $context->getArgument(['r', 'release']); foreach ($environment->servers as $server) { $connection = new RemoteConnection($server, $environment->authentication); // get the current releases $releases = $connection->execute("ls {$environment->remote->path}/releases"); $releases = explode("\n", trim($releases)); $release = null; // Specific release to rollback to if ($specificRelease) { foreach ($releases as $r) { if ($specificRelease == $r) { $release = $r; } } if (!$release) { throw new \Exception("Release {$specificRelease} not found"); } } elseif (count($releases) > 1) { $release = $releases[count($releases) - 2]; } else { throw new \Exception("No previous release available"); } // Do the rollback $connection->execute("cd {$environment->remote->path}&&rm -f current&&ln -s -r releases/{$release} current"); } }
public function run(Context $context) { // Get environment argument if (($env = $context->getArgument(['e', 'environment'])) === null) { throw new \Exception("No environment specified"); } // Get task argument if (($task = $context->nextNamedArgument()) == null) { throw new \Exception("No task specified. Specify a task with either -t or --task argument."); } // Get the environment config if (($environment = $context->config->getEnvironment($env)) == false) { throw new \Exception("No environment config found for \"{$env}\"."); } // loop through servers and run task foreach ($environment->servers as $server) { $connection = new RemoteConnection($server, $environment->authentication); Task::run($task, $context, $environment, $connection); $connection->close(); } }