Skip to content

Commit

Permalink
Add php container exsits check and update comments
Browse files Browse the repository at this point in the history
Signed-off-by: Riddhesh Sanghvi <[email protected]>
  • Loading branch information
mrrobot47 committed Aug 30, 2018
1 parent c2a4d54 commit dd6bc13
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/Shell_Command.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

/**
* Executes wp-cli command on a site.
* Brings up a shell to run wp-cli, composer etc.
*
* ## EXAMPLES
*
* # Create simple WordPress site
* $ ee wp test.local plugin list
* # Open shell of example.com
* $ ee shell example.com
*
* @package ee-cli
*/
Expand All @@ -30,13 +30,14 @@ public function __invoke( $args ) {
$args = auto_site_name( $args, 'shell', '' );
$site_name = EE\Utils\remove_trailing_slash( $args[0] );

$site = Site::find( $site_name, [ 'site_enabled', 'site_fs_path' ] );
$site = Site::find( $site_name );

if ( ! $site || ! $site->site_enabled ) {
EE::error( "Site $site_name does not exist or is not enabled." );
}

chdir( $site->site_fs_path );
$this->check_shell_available( 'php', $site );
$this->run( "docker-compose exec --user='www-data' php bash" );
EE\Utils\delem_log( 'ee shell end' );
}
Expand Down Expand Up @@ -64,4 +65,21 @@ private function run( $cmd, $descriptors = null ) {
}
}

/**
* Function to check if container supporting shell is present in docker-compose.yml or not.
*
* @param string $shell_container Container to be checked.
* @param Object $site Contains relevant site info.
*/
private function check_shell_available( $shell_container, $site ) {

$launch = EE::launch( 'docker-compose config --services' );
$services = explode( PHP_EOL, trim( $launch->stdout ) );
if ( ! in_array( $shell_container, $services, true ) ) {
EE::debug( 'Site type: ' . $site->site_type );
EE::debug( 'Site command: ' . $site->app_sub_type );
EE::error( sprintf( '%s site does not have support to launch %s shell.', $shell_container, $site->site_name ) );
}
}

}

0 comments on commit dd6bc13

Please sign in to comment.