Skip to content

Commit

Permalink
Add --ignore-composer option to deploy command
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Dargham committed Dec 10, 2021
1 parent 3bd7508 commit dbf8822
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/BuildTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

trait BuildTrait
{
public function build($environment = 'development', $root = \RoboFile::ROOT, $ignore_assets = false)
public function build($environment = 'development', $root = \RoboFile::ROOT, $ignore_assets = false, $ignore_composer = false)
{
$this->buildComposer($environment, $root);
if(!$ignore_composer) {
$this->buildComposer($environment, $root);
}
$this->buildConfig($environment, $root);
$this->buildHtaccess($environment, $root);

Expand Down
20 changes: 13 additions & 7 deletions src/DeployTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

trait DeployTrait
{
public function deploy($environment, $gitRevision, $options = ['ignore-assets' => false])
public function deploy($environment, $gitRevision, $options = ['ignore-assets' => false, 'ignore-composer' => false])
{
$this->io()->title('Deploy version ' . $gitRevision . ' to ' . $environment);

Expand All @@ -21,18 +21,18 @@ public function deploy($environment, $gitRevision, $options = ['ignore-assets' =

$this->gitExtractArchive($gitRevision, $buildDirectory);

$this->build($environment, $buildDirectory, $options['ignore-assets']);
$this->build($environment, $buildDirectory, $options['ignore-assets'], $options['ignore-composer']);

$this->deployWriteState(self::trailingslashit($buildDirectory) . 'deploy', $gitRevision);

// 1. Dry Run
$this->rsyncDeploy($buildDirectory, $config['REMOTE_HOSTNAME'], $config['REMOTE_USERNAME'], $config['REMOTE_PATH'], $config['REMOTE_PORT'], $options['ignore-assets'], true);
$this->rsyncDeploy($buildDirectory, $config['REMOTE_HOSTNAME'], $config['REMOTE_USERNAME'], $config['REMOTE_PATH'], $config['REMOTE_PORT'], $options['ignore-assets'], true, true, $options['ignore-composer']);

$deployed = false;

if ($this->io()->confirm('Do you want to run ?', false)) {
// 2. Run
$this->rsyncDeploy($buildDirectory, $config['REMOTE_HOSTNAME'], $config['REMOTE_USERNAME'], $config['REMOTE_PATH'], $config['REMOTE_PORT'], $options['ignore-assets'], false);
$this->rsyncDeploy($buildDirectory, $config['REMOTE_HOSTNAME'], $config['REMOTE_USERNAME'], $config['REMOTE_PATH'], $config['REMOTE_PORT'], $options['ignore-assets'], false, true, $options['ignore-composer']);

$deployed = true;
}
Expand All @@ -42,12 +42,12 @@ public function deploy($environment, $gitRevision, $options = ['ignore-assets' =
return $deployed;
}

protected function rsyncDeploy($fromPath, $toHost, $toUser, $toPath, $remotePort, $ignoreAssets, $dryRun, $verbose = true)
protected function rsyncDeploy($fromPath, $toHost, $toUser, $toPath, $remotePort, $ignoreAssets, $dryRun, $verbose = true, $ignore_composer = false)
{
$chmod = 'Du=rwx,Dgo=rx,Fu=rw,Fgo=r';
$excludeFrom = self::trailingslashit($fromPath) . '.rsyncignore';
$delete = true;
$this->rsync(null, null, $fromPath, $toHost, $toUser, $toPath, $remotePort, $delete, $chmod, $excludeFrom, $ignoreAssets, $dryRun, $verbose);
$this->rsync(null, null, $fromPath, $toHost, $toUser, $toPath, $remotePort, $delete, $chmod, $excludeFrom, $ignoreAssets, $dryRun, $verbose, $ignore_composer);
}

protected function deployWriteState($directory, $gitRevision)
Expand Down Expand Up @@ -183,7 +183,7 @@ protected function rsyncMedia($fromHost, $fromUser, $fromPath, $toHost, $toUser,
$this->rsync($fromHost, $fromUser, $fromPath, $toHost, $toUser, $toPath, $remotePort, $delete, $chmod, $excludeFrom, $ignoreAssets, $dryRun);
}

protected function rsync($fromHost, $fromUser, $fromPath, $toHost, $toUser, $toPath, $remotePort, $delete, $chmod, $excludeFrom, $ignoreAssets, $dryRun, $verbose = true)
protected function rsync($fromHost, $fromUser, $fromPath, $toHost, $toUser, $toPath, $remotePort, $delete, $chmod, $excludeFrom, $ignoreAssets, $dryRun, $verbose = true, $ignore_composer = false)
{
$cmd = $this->taskRsync()
->fromHost($fromHost)
Expand Down Expand Up @@ -214,6 +214,12 @@ protected function rsync($fromHost, $fromUser, $fromPath, $toHost, $toUser, $toP
}
}

if($ignore_composer) {
foreach (\RoboFile::PATH_VENDORS as $vendorPath) {
$cmd->exclude($vendorPath);
}
}

if (false !== $excludeFrom && file_exists($excludeFrom)) {
$cmd->excludeFrom($excludeFrom);
} else {
Expand Down

0 comments on commit dbf8822

Please sign in to comment.