Commit dfc64dae authored by Mikke Schirén's avatar Mikke Schirén

better multi deploys, missing file and nicer message on drupal version check

parent 33257c37
<?php
namespace Dropcat\Command;
use Dropcat\Lib\DropcatCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Exception;
use phpseclib\Crypt\RSA;
use phpseclib\Net\SSH2;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use GuzzleHttp\Client;
/**
*
*/
class DeployNoteCommand extends DropcatCommand
{
/**
*
*/
protected function configure()
{
$HelpText = 'The <info>%command.name%</info> send payload of deploy to endpoint.';
$this->setName("deploy:note")
->setDescription("Send payload of deploy to endpoint")
->setDefinition(
[
new InputOption(
'server',
's',
InputOption::VALUE_OPTIONAL,
'Server',
$this->configuration->remoteEnvironmentServerName()
),
new InputOption(
'user',
'u',
InputOption::VALUE_OPTIONAL,
'User (ssh)',
$this->configuration->remoteEnvironmentSshUser()
),
new InputOption(
'ssh_port',
'p',
InputOption::VALUE_OPTIONAL,
'SSH port',
$this->configuration->remoteEnvironmentSshPort()
),
new InputOption(
'ssh_key_password',
'skp',
InputOption::VALUE_OPTIONAL,
'SSH key password',
$this->configuration->localEnvironmentSshKeyPassword()
),
new InputOption(
'identity_file',
'i',
InputOption::VALUE_OPTIONAL,
'Identify file',
$this->configuration->remoteEnvironmentIdentifyFile()
)
]
)
->setHelp($HelpText);
}
/**
*
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$server = $input->getOption('server');
$user = $input->getOption('user');
$ssh_port = $input->getOption('ssh_port');
$identity_file = $input->getOption('identity_file');
$identity_file_content = file_get_contents($identity_file);
$ssh_key_password = $input->getOption('ssh_key_password');
//define('NET_SSH2_LOGGING', 2);
$ssh = new SSH2($server, $ssh_port);
if ($output->isVerbose()) {
$output->writeln("<info>using server $server and port $ssh_port</info>");
}
$auth = new RSA();
if (isset($ssh_key_password)) {
$auth->setPassword($ssh_key_password);
if ($output->isVerbose()) {
$output->writeln("<info>using $ssh_key_password as password</info>");
}
}
if ($output->isVerbose()) {
$output->writeln("<info>loading key $identity_file</info>");
}
$auth->loadKey($identity_file_content);
if (!$ssh->login($user, $auth)) {
$output->writeln($ssh->getLog());
$output->writeln($ssh->getErrors());
$output->writeln("<info>Login Failed</info>");
exit(1);
}
$ssh->login($user, $auth);
if ($output->isVerbose()) {
$output->writeln("<info>logging in with user $user</info>");
}
$hostname = $ssh->exec('cat /etc/hostname');
echo $hostname;
try {
if (!isset($hostname)) {
throw new Exception('could not get hostname');
}
} catch (\Exception $e) {
echo 'error ' . $e->getMessage();
}
$deploy_url_endpoint = getenv('DEPLOY_URL_ENDPOINT');
echo $deploy_url_endpoint;
$output->writeln('<info>' . $this->mark .
' %command.name% finished</info>');
}
}
......@@ -211,11 +211,16 @@ To override config in dropcat.yml, using options:
}
$sites_folder = "$deploy_path/sites/";
$old_sites = "$temp_folder/old_sites";
$number_of_folders_original = $ssh->exec("ls -l $sites_folder | grep -c ^d");
$output->writeln("<info>Number of sites in sites folder including default before deploy: $number_of_folders_original</info>");
$ssh->exec("rsync -av --progress $sites_folder /tmp/$app_name-sites-$deploy_folder --exclude=default");
# $ssh->exec("rsync -av --progress $sites_folder /tmp/$app_name-sites-$deploy_folder --exclude=default");
$ssh->exec("mv $sites_folder $old_sites");
$status = $ssh->getExitStatus();
if ($status !== 0) {
echo "could not copy sites folder, error code $status\n";
echo "could not move sites folder, error code $status\n";
exit($status);
}
if (!($keeptar)) {
......@@ -249,27 +254,24 @@ To override config in dropcat.yml, using options:
if ($output->isVerbose()) {
$output->writeln("<info>$this->mark alias to deployed folder are: $web_root/$alias</info>");
}
$ssh->exec("cp -Rf /tmp/$app_name-sites-$deploy_folder/* $sites_folder");
$status = $ssh->getExitStatus();
$temp_sites = "$temp_folder/$build_id-sites";
$new_build_old_sites = "$deploy_path/sites";
$ssh->exec("mv $sites_folder $temp_sites && mv $old_sites $new_build_old_sites");
if ($status !== 0) {
echo "Could not move sites folder in place, error code $status\n";
exit($status);
}
$number_of_folders_new = $ssh->exec("ls -l $sites_folder | grep -c ^d");
$output->writeln("Number of sites in sites folder including default: $number_of_folders_new");
if ($number_of_folders_original !== $number_of_folders_new) {
$output->writeln("<error>Number of sites in sites folder does not match original. Aborted.</error>");
exit(1);
}
if ($output->isVerbose()) {
$output->writeln("<info>$this->mark sites folder moved in place</info>");
}
$ssh->exec("chmod 777 -R /tmp/$app_name-sites-$deploy_folder");
$ssh->exec("rm -rf /tmp/$app_name-sites-$deploy_folder");
// Commented out this check for now
$status = $ssh->getExitStatus();
if ($status !== 0) {
echo "Could not delete old sites folder, error code $status\n";
}
if ($output->isVerbose() && $status == 0) {
$output->writeln("<info>$this->mark old sites folder deleted</info>");
}
$ssh->disconnect();
$output->writeln("<info>$this->heart multi:move finished</info>");
......
......@@ -141,7 +141,7 @@ class SecurityDrupalCommand extends DropcatCommand
if (in_array($status, $ok)) {
if ($status === 'deprecated') {
$output->writeln("<info>$this->mark drupal version $version is deprecated</info>");
$output->writeln("<error>THIS VERSION ($version) CAN'T BE DEPLOYED TO PRODUCTION!</error>");
$output->writeln("<error>THIS VERSION ($version) SHOULD NOT BE DEPLOYED TO PRODUCTION!</error>");
} else {
$output->writeln("<info>$this->heart drupal version $version is ok</info>");
}
......@@ -152,7 +152,7 @@ class SecurityDrupalCommand extends DropcatCommand
exit(1);
} else {
$output->writeln("<info>$this->error drupal version $version is not secure</info>");
$output->writeln("<error>ERROR!!!</error>");
$output->writeln("<error>ERROR!!! CAN NOT BE DEPLOYED TO PRODUCTION!</error>");
exit(1);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment