Exemplo n.º 1
0
 /**
  * @large
  */
 public function testStuff()
 {
     $host = new Host('127.0.0.1', 22, new KeyCredential('jordon', null, '/home/jordon/.ssh/jordon.pem'));
     //$host = new Host('54.206.100.211', 22, new KeyCredential('ec2-user', null, '/home/jordon/.ssh/test-sydney.pem'));
     //$host = new Host('54.79.108.44', 22, new KeyCredential('ec2-user', null, '/home/jordon/.ssh/test-sydney.pem'));
     $logger_bake = new FileLogger("/tmp/bakery_bake.log", false, true);
     $logger_callback = new FileLogger("/tmp/bakery_callback.log", false, true);
     $logger_out = new FileLogger("/tmp/bakery_out.log", false, true);
     $logger_bake->debug("\n\n\n---");
     $logger_callback->debug("\n\n\n---");
     $logger_out->debug("\n\n\n---");
     $callback = function (Phase $phase, $progress, $total, $msg) use($logger_callback) {
         $logger_callback->info($phase->value() . ' ' . $progress . ' / ' . $total . ': ' . $msg);
     };
     $bakery = new Bakery($host, $logger_out, $callback);
     $bakery->setLogger($logger_bake);
     $repo = new Repository();
     $repo->setRepositoryType(RepositoryType::GIT());
     $repo->setCheckoutPath('/tmp/test-repo');
     $repo->setUri('git@github.com:jordonsc/hyperion_dbal.git');
     $repo->setPrivateKey(file_get_contents(__DIR__ . '/Resources/test-key.pem'));
     $repo->setPassword('password');
     $repo->setTag('c38a0835235003a08d3f5f851f57ba5914cff98e');
     $repo->setTag('0.0.4-beta');
     $repo->setHostFingerprint('16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48');
     $standards = new Repository();
     $standards->setRepositoryType(RepositoryType::GIT());
     $standards->setUri('https://github.com/bravo3/standards.git');
     $standards->setTag('1.0.0');
     $standards->setCheckoutPath('/tmp/bravo3/standards');
     $standards->setProxy(new SocksProxy('localhost', 5501));
     $schema = new Schema(PackagerType::YUM());
     $schema->addOperation(new EnvironmentOperation(['env' => 'bake', 'action' => '1234']))->addOperation(new CodeCheckoutOperation($standards));
     $bakery->bake($schema);
 }
Exemplo n.º 2
0
 /**
  * Bake the host
  *
  * @param Schema $schema
  * @param int    $terminal_width
  */
 public function bake(Schema $schema, $terminal_width = 180)
 {
     // Connect to host
     $con = $this->connect();
     if (!$con) {
         throw new ConnectionException("Unable to connect to bakery host");
     }
     // Get an SSH stream
     $this->status(Phase::ENVIRONMENT(), 0, 0, 'Configuring environment');
     $shell = $con->getShell(new Terminal($terminal_width, 25, TerminalUnit::CHARACTERS));
     $shell->setSmartConsole();
     // Traverse operations
     $total = $schema->getOperationCount();
     /** @var OperationInterface $operation */
     foreach ($schema as $pos => $operation) {
         $this->status(Phase::OPERATION(), $pos + 1, $total, 'Executing ' . $this->getOperationName($operation));
         $operation->setLogger($this->output);
         $operation->setCallback($this->status_callback);
         $operation->setPackagerType($schema->getPackagerType());
         $operation->setShell($shell);
         $operation->setConnection($con);
         try {
             $operation->execute();
         } catch (\Exception $e) {
             $this->status(Phase::ERROR(), $pos + 1, $total, 'Operation failed (' . $e->getMessage() . ')');
             $con->disconnectChain();
             throw $e;
         }
     }
     $con->disconnectChain();
 }