public function setUpEnvironment() { if (null === $this->idx->getCurrentTargetName()) { throw new \Exception("You must specify an environment [--env]"); } $target = $this->idx->getCurrentTarget(); if (!$target->get('deploy.remote_base_dir', false)) { throw new \Exception("No deploy parameters found. Check you configuration."); } $this->symfonyEnv = $target->get('symfony_env', 'dev'); $this->hasToMigrate = $target->get('deploy.migrations', false); $this->localBaseFolder = $target->getFixedPath('deploy.local_base_dir'); $this->remoteBaseFolder = $target->getFixedPath('deploy.remote_base_dir'); $this->releasesFolder = $this->remoteBaseFolder . 'releases/'; $this->sharedFolders = $target->get('deploy.shared_folders', array()); $target->set('deploy.releases_dir', $this->releasesFolder); $target->set('deploy.current_release_dir', $this->getCurrentReleaseFolder()); $target->set('deploy.next_release_dir', $this->getNextReleaseFolder()); $target->set('deploy.dry_run', $this->dryRun); $strategyClass = 'Idephix\\Extension\\Deploy\\Strategy\\' . $target->get('deploy.strategy', 'Copy'); if (!class_exists($strategyClass)) { throw new \Exception(sprintf("No deploy strategy %s found. Check you configuration.", $strategyClass)); } $this->strategy = new $strategyClass($this->idx, $target); }
<?php use Idephix\Idephix; use Idephix\Extension\Deploy\Deploy; use Idephix\Extension\PHPUnit\PHPUnit; $localBaseDir = __DIR__; $sshParams = array('user' => 'ideato'); $targets = array('prod' => array('hosts' => array('127.0.0.1'), 'ssh_params' => $sshParams, 'deploy' => array('local_base_dir' => $localBaseDir, 'remote_base_dir' => "/var/www/myfantasticserver/", 'rsync_exclude_file' => 'rsync_exclude.txt')), 'stage' => array('hosts' => array('127.0.0.1'), 'ssh_params' => $sshParams, 'deploy' => array('local_base_dir' => $localBaseDir, 'remote_base_dir' => "/var/www/myfantasticserver/", 'rsync_exclude_file' => 'rsync_exclude.txt')), 'dev' => array('hosts' => array('127.0.0.1'), 'ssh_params' => array('user' => 'vagrant'), 'deploy' => array('local_base_dir' => $localBaseDir, 'remote_base_dir' => "/var/www/myfantasticserver/", 'rsync_exclude_file' => 'rsync_exclude.txt'))); $idx = new Idephix($targets); $idx->add('project:deploy', function ($go = false) use($idx) { $env = $idx->getCurrentTargetName(); if (!$go) { echo "\nDry Run\n"; } $idx->setDryRun(!$go); $idx->setUpEnvironment(); if (!$idx->isRemoteReady()) { $idx->bootstrap(); } $idx->remotePrepare(); $idx->getStrategy()->deploy(); $idx->remoteLinkSharedFolders(); if ($idx->hasToMigrate()) { $idx->doctrineMigrate(); } $idx->remote('cd ' . $idx->getNextReleaseFolder() . '/app/config && rm -f parameters.yml', !$go); $idx->remote('cd ' . $idx->getNextReleaseFolder() . '/app/config && ln -s parameters.' . $env . '.yml parameters.yml', !$go); $idx->cacheClear(); $idx->switchToTheNextRelease(); $idx->assetic(); $idx->deleteOldReleases(6);