Пример #1
0
 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);
         }
     }
 }
Пример #2
0
 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}");
 }
Пример #3
0
 public function run(Context $context, Environment $environment, ConnectionInterface $connection = null)
 {
     if ($connection->execute("if [ -d \"{$environment->remote->deployTo}\" ]; then echo 1; fi")) {
         $releases = $connection->execute("ls {$environment->remote->deployTo}");
         $releases = explode("\n", trim($releases));
         if (($trim = count($releases) - $environment->remote->keepReleases) > 0) {
             $releases = array_slice($releases, 0, $trim);
             foreach ($releases as $release) {
                 $context->say("\tPruning {$release}...");
                 $connection->execute("rm -Rf {$environment->remote->deployTo}/{$release}");
             }
         }
     }
 }
Пример #4
0
 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();
     }
 }
Пример #5
0
 public function run(Context $context, Environment $environment, ConnectionInterface $connection = null)
 {
     $currentRelease = $environment->remote->currentRelease;
     // Make directories
     $context->say("\tCreating required directories...");
     $connection->execute("mkdir -p {$currentRelease}/bootstrap/cache");
     $connection->execute("mkdir -p {$currentRelease}/storage/app/public");
     $connection->execute("mkdir -p {$currentRelease}/storage/framework/cache");
     $connection->execute("mkdir -p {$currentRelease}/storage/framework/sessions");
     $connection->execute("mkdir -p {$currentRelease}/storage/framework/views");
     $connection->execute("mkdir -p {$currentRelease}/storage/logs");
     // Change ownership
     $context->say("\tChanging ownership....");
     $connection->execute("sudo chown fedora.apache {$currentRelease}/storage -R");
     $connection->execute("sudo chown fedora.apache {$currentRelease}/bootstrap/cache -R");
     // Change permissions
     $context->say("\tChanging permissions...");
     $connection->execute("sudo chmod 770 {$currentRelease}/storage -R");
     $connection->execute("sudo chmod 770 {$currentRelease}/bootstrap/cache -R");
     // Link up the environment
     $context->say("\tLinking environment config...");
     $connection->execute("cd {$currentRelease}&&ln -s .env.{$environment->name} .env");
 }
Пример #6
0
 public function run(Context $context)
 {
     if (($type = $context->nextNamedArgument()) == null) {
         throw new \Exception('Missing the thing to make');
     }
     $name = $context->nextNamedArgument();
     switch (strtolower($type)) {
         case 'command':
             if (empty($name)) {
                 throw new \Exception("Name required");
             }
             $name = ucfirst(strtolower($name));
             $filename = "{$name}Command.php";
             $path = "commands";
             if (file_exists($path) == false) {
                 throw new \Exception('Commands directory not found. Have you run "minion init" yet?');
             }
             $context->say("Creating <bold>{$name}</bold> command");
             if (file_exists("{$path}/{$filename}")) {
                 throw new \Exception("File \"{$path}/{$filename}\" already exists");
             }
             $command = file_get_contents(__DIR__ . '/../src/templates/Command.php.tpl');
             $command = preg_replace('/\\:CommandName/', "{$name}Command", $command);
             file_put_contents("{$path}/{$filename}", $command);
             break;
         case 'task':
             if (empty($name)) {
                 throw new \Exception("Name required");
             }
             $name = ucfirst(strtolower($name));
             $filename = "{$name}Task.php";
             $path = "tasks";
             if (file_exists($path) == false) {
                 throw new \Exception('Tasks directory not found. Have you run "minion init" yet?');
             }
             $context->say("Creating <bold>{$name}</bold> task");
             if (file_exists("{$path}/{$filename}")) {
                 throw new \Exception("File \"{$path}/{$filename}\" already exists");
             }
             $command = file_get_contents(__DIR__ . '/../src/templates/Task.php.tpl');
             $command = preg_replace('/\\:TaskName/', "{$name}Task", $command);
             file_put_contents("{$path}/{$filename}", $command);
             break;
         case 'config':
             $context->say("Creating new default config file");
             if (!$name) {
                 $name = 'minion.yml';
             }
             if (file_exists($name)) {
                 throw new \Exception("Config file \"{$name}\" already exists");
             }
             copy(__DIR__ . '/../src/templates/config.yml.tpl', $name);
             break;
         default:
             throw new \Exception('Unsupported type');
     }
 }
Пример #7
0
 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");
     }
 }