Skip to content

Commit

Permalink
Make sure all commands return their exit codes (#85) (#86)
Browse files Browse the repository at this point in the history
* make sure all commands return their exit codes

* add error message for failed docker-compose up
  • Loading branch information
github-actions[bot] authored and roborourke committed Nov 26, 2019
1 parent baa6d00 commit 4147289
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions inc/composer/class-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected function execute( InputInterface $input, OutputInterface $output ) {
}

$output->writeln( '<error>' . $subcommand . ' command not found.</>' );
return 1;
}

protected function start( InputInterface $input, OutputInterface $output ) {
Expand All @@ -83,10 +84,15 @@ protected function start( InputInterface $input, OutputInterface $output ) {
$proxy = new Process( 'docker-compose -f proxy.yml up -d', 'vendor/altis/local-server/docker' );
$proxy->setTimeout( 0 );
$proxy->setTty( true );
$proxy->run( function ( $type, $buffer ) {
$proxy_failed = $proxy->run( function ( $type, $buffer ) {
echo $buffer;
} );

if ( $proxy_failed ) {
$output->writeln( '<error>Could not start traefik proxy.</>' );
return $proxy_failed;
}

$env = [
'VOLUME' => getcwd(),
'COMPOSE_PROJECT_NAME' => $this->get_project_subdomain(),
Expand All @@ -106,7 +112,8 @@ protected function start( InputInterface $input, OutputInterface $output ) {
} );

if ( $failed ) {
return;
$output->writeln( '<error>Services failed to start successfully.</>' );
return $failed;
}

$cli = $this->getApplication()->find( 'local-server' );
Expand All @@ -122,7 +129,7 @@ protected function start( InputInterface $input, OutputInterface $output ) {
] ), $output ) === 0;

if ( ! $is_installed ) {
$cli->run( new ArrayInput( [
$install_failed = $cli->run( new ArrayInput( [
'subcommand' => 'cli',
'options' => [
'core',
Expand All @@ -135,8 +142,14 @@ protected function start( InputInterface $input, OutputInterface $output ) {
'--skip-config',
'--quiet',
],
] ), $output );

// Check install was successful.
if ( $install_failed ) {
$output->writeln( '<error>WordPress install failed.</>' );
return $install_failed;
}

] ), $output ) === 0;
$output->writeln( '<info>Installed database.</>' );
$output->writeln( '<info>WP Username:</> <comment>admin</>' );
$output->writeln( '<info>WP Password:</> <comment>admin</>' );
Expand Down Expand Up @@ -180,11 +193,17 @@ protected function stop( InputInterface $input, OutputInterface $output ) {
'VOLUME' => getcwd(),
'COMPOSE_PROJECT_NAME' => $this->get_project_subdomain(),
] );
$compose->run( function ( $type, $buffer ) {
$return_val = $compose->run( function ( $type, $buffer ) {
echo $buffer;
} );

$output->writeln( '<info>Stopped.</>' );
if ( $return_val === 0 ) {
$output->writeln( '<info>Stopped.</>' );
} else {
$output->writeln( '<error>Failed to stop services.</>' );
}

return $return_val;
}

protected function destroy( InputInterface $input, OutputInterface $output ) {
Expand All @@ -197,16 +216,22 @@ protected function destroy( InputInterface $input, OutputInterface $output ) {
'VOLUME' => getcwd(),
'COMPOSE_PROJECT_NAME' => $this->get_project_subdomain(),
] );
$compose->run( function ( $type, $buffer ) {
$return_val = $compose->run( function ( $type, $buffer ) {
echo $buffer;
} );

$output->writeln( '<error>Destroyed.</>' );
if ( $return_val === 0 ) {
$output->writeln( '<error>Destroyed.</>' );
} else {
$output->writeln( '<error>Failed to destroy services.</>' );
}

return $return_val;
}

protected function restart( InputInterface $input, OutputInterface $output ) {
$this->stop( $input, $output );
$this->start( $input, $output );
return $this->start( $input, $output );
}

protected function exec( InputInterface $input, OutputInterface $output, ?string $program = null ) {
Expand Down Expand Up @@ -242,7 +267,8 @@ protected function exec( InputInterface $input, OutputInterface $output, ?string

$container_id = exec( sprintf( 'docker ps --filter name=%s_php_1 -q', $this->get_project_subdomain() ) );
if ( ! $container_id ) {
return $output->writeln( '<error>PHP container not found to run command.</>' );
$output->writeln( '<error>PHP container not found to run command.</>' );
return 1;
}

$columns = exec( 'tput cols' );
Expand All @@ -268,7 +294,7 @@ protected function status( InputInterface $input, OutputInterface $output ) {
'VOLUME' => getcwd(),
'COMPOSE_PROJECT_NAME' => $this->get_project_subdomain(),
] );
$compose->run( function ( $type, $buffer ) {
return $compose->run( function ( $type, $buffer ) {
echo $buffer;
} );
}
Expand All @@ -280,7 +306,7 @@ protected function logs( InputInterface $input, OutputInterface $output ) {
'COMPOSE_PROJECT_NAME' => $this->get_project_subdomain(),
] );
$compose->setTimeout( 0 );
$compose->run( function ( $type, $buffer ) {
return $compose->run( function ( $type, $buffer ) {
echo $buffer;
} );
}
Expand Down

0 comments on commit 4147289

Please sign in to comment.