Skip to content

Commit

Permalink
feat: add --with-uploads option to deploy command
Browse files Browse the repository at this point in the history
  • Loading branch information
carlalexander committed Feb 22, 2022
1 parent cd5a0c2 commit d5f309a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/Command/Import/ImportUploadsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ protected function configure()
->setDescription('Import files to the environment uploads directory')
->addArgument('path', InputArgument::REQUIRED, 'The path to the files to import')
->addOption('environment', null, InputOption::VALUE_REQUIRED, 'The environment to upload files to', 'staging')
->addOption('force', null, InputOption::VALUE_NONE, 'Force the import to run')
->addOption('size', null, InputOption::VALUE_REQUIRED, 'The number of files to process at a time', '20');
}

Expand All @@ -114,13 +115,13 @@ protected function perform(InputInterface $input, OutputInterface $output)
throw new InvalidArgumentException('Cannot have a "size" smaller than 1');
}

if (!$output->confirm('Importing files will overwrite any existing file in the environment uploads directory. Do you want to proceed?')) {
if (!$this->getBooleanOption($input, 'force') && !$output->confirm('Importing files will overwrite any existing file in the environment "uploads" directory. Do you want to proceed?')) {
return;
}

$this->tempDirectory = $this->createTempDirectory();

$output->info(sprintf('Starting file import to "<comment>%s</comment>" environment', $environment));
$output->info(sprintf('Starting file import to the "<comment>%s</comment>" environment "uploads" directory', $environment));

$progressBar = new ProgressBar($output);
$progressBar->setFormat("Importing file (<comment>%filename%</comment>)\nTotal files imported: <comment>%total%</comment>\n");
Expand Down Expand Up @@ -156,7 +157,7 @@ protected function perform(InputInterface $input, OutputInterface $output)
$progressBar->advance();
});

$output->info(sprintf('Files imported successfully to "<comment>%s</comment>" environment', $environment));
$output->info(sprintf('Files imported successfully to the "<comment>%s</comment>" environment "uploads" directory', $environment));
}

/**
Expand Down
32 changes: 30 additions & 2 deletions src/Command/Project/DeployProjectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Tightenco\Collect\Support\Collection;
use Ymir\Cli\ApiClient;
use Ymir\Cli\CliConfiguration;
use Ymir\Cli\Command\Import\ImportUploadsCommand;
use Ymir\Cli\Console\OutputInterface;
use Ymir\Cli\ProjectConfiguration\ProjectConfiguration;

class DeployProjectCommand extends AbstractProjectDeploymentCommand
{
Expand All @@ -35,6 +40,23 @@ class DeployProjectCommand extends AbstractProjectDeploymentCommand
*/
public const NAME = 'project:deploy';

/**
* The build "uploads" directory.
*
* @var string
*/
private $uploadsDirectory;

/**
* Constructor.
*/
public function __construct(ApiClient $apiClient, CliConfiguration $cliConfiguration, ProjectConfiguration $projectConfiguration, string $uploadsDirectory, array $deploymentSteps = [])
{
parent::__construct($apiClient, $cliConfiguration, $projectConfiguration, $deploymentSteps);

$this->uploadsDirectory = $uploadsDirectory;
}

/**
* {@inheritdoc}
*/
Expand All @@ -44,7 +66,8 @@ protected function configure()
->setName(self::NAME)
->setDescription('Deploy project to an environment')
->setAliases([self::ALIAS])
->addArgument('environment', InputArgument::OPTIONAL, 'The name of the environment to deploy to', 'staging');
->addArgument('environment', InputArgument::OPTIONAL, 'The name of the environment to deploy to', 'staging')
->addOption('with-uploads', null, InputOption::VALUE_NONE, 'Import the "uploads" directory during the deployment');
}

/**
Expand All @@ -54,9 +77,14 @@ protected function createDeployment(InputInterface $input, OutputInterface $outp
{
$environment = $this->getStringArgument($input, 'environment');
$projectId = $this->projectConfiguration->getProjectId();
$withUploadsOption = $this->getBooleanOption($input, 'with-uploads');

$this->invoke($output, ValidateProjectCommand::NAME, ['environments' => $environment]);
$this->invoke($output, BuildProjectCommand::NAME, ['environment' => $environment]);
$this->invoke($output, BuildProjectCommand::NAME, array_merge(['environment' => $environment], $withUploadsOption ? ['--with-uploads' => null] : []));

if ($withUploadsOption) {
$this->invoke($output, ImportUploadsCommand::NAME, ['path' => $this->uploadsDirectory, '--environment' => $environment, '--force' => null]);
}

$deployment = $this->apiClient->createDeployment($projectId, $environment, $this->projectConfiguration);

Expand Down

0 comments on commit d5f309a

Please sign in to comment.