Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions php/EE/Migration/GlobalContainers.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function revert_global_containers( $source_path, $dest_path, $upda

chdir( EE_ROOT_DIR . '/services' );

if ( ! EE::exec( 'docker-compose up -d ' . $services_to_regenerate ) ) {
if ( ! EE::exec( \EE_DOCKER::docker_compose_with_custom() . ' up -d ' . $services_to_regenerate ) ) {
throw new \Exception( 'Unable to downgrade global containers. Please check logs for more details.' );
}
EE::debug( 'Complete restoring global docker-compose.yml file from backup' );
Expand All @@ -81,7 +81,7 @@ public static function down_global_containers( $updated_images ) {
EE::debug( "Removing $global_container_name" );

if ( false !== \EE_DOCKER::container_status( $global_container_name ) ) {
if ( ! EE::exec( "docker-compose stop $global_service_name && docker-compose rm -f $global_service_name" ) ) {
if ( ! EE::exec( \EE_DOCKER::docker_compose_with_custom() . " stop $global_service_name && ". \EE_DOCKER::docker_compose_with_custom() . " rm -f $global_service_name" ) ) {
throw new \Exception( "Unable to stop $global_container_name container" );
}
}
Expand Down Expand Up @@ -115,7 +115,7 @@ public static function global_service_down( $service_name ) {
EE::debug( 'Start ' . $service_name . ' container removing' );
chdir( EE_ROOT_DIR . '/services' );

if ( ! EE::exec( "docker-compose stop $service_name && docker-compose rm -f $service_name" ) ) {
if ( ! EE::exec( \EE_DOCKER::docker_compose_with_custom() . " stop $service_name && ". \EE_DOCKER::docker_compose_with_custom() . " rm -f $service_name" ) ) {
throw new \Exception( sprintf( 'Unable to remove %1$s container', $service_name ) );
}
EE::debug( 'Complete ' . $service_name . ' container removing' );
Expand Down Expand Up @@ -149,7 +149,7 @@ public static function enable_support_containers() {
throw new \Exception( sprintf( '%s path does not exist', EE_SERVICE_DIR ) );
}

$command = 'docker-compose --project-name=ee up -d global-db global-redis';
$command = \EE_DOCKER::docker_compose_with_custom() . ' --project-name=ee up -d global-db global-redis';
if ( ! EE::exec( $command ) ) {
throw new \Exception( 'Unable to create support container.' );
}
Expand All @@ -163,7 +163,7 @@ public static function disable_support_containers() {
throw new \Exception( sprintf( '%s path does not exist', EE_SERVICE_DIR ) );
}

$command = 'docker-compose --project-name=ee down';
$command = \EE_DOCKER::docker_compose_with_custom() . ' --project-name=ee down';
if ( ! EE::exec( $command ) ) {
throw new \Exception( 'Unable to remove support container.' );
}
Expand Down
3 changes: 2 additions & 1 deletion php/EE/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private function init_ee() {

define( 'DB', EE_ROOT_DIR . '/db/ee.sqlite' );
define( 'LOCALHOST_IP', '127.0.0.1' );
define( 'SITE_CUSTOM_DOCKER_COMPOSE', 'docker-compose-custom.yml' );

$db_dir = dirname( DB );
if ( ! is_dir( $db_dir ) ) {
Expand Down Expand Up @@ -472,7 +473,7 @@ private function generate_ssh_command( $bits, $ee_command ) {
}

if ( 'docker-compose' === $bits['scheme'] ) {
$command = 'docker-compose exec %s%s%s sh -c %s';
$command = \EE_DOCKER::docker_compose_with_custom() . ' exec %s%s%s sh -c %s';

$escaped_command = sprintf(
$command,
Expand Down
33 changes: 29 additions & 4 deletions php/class-ee-docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@

class EE_DOCKER {

/**
* Function to return docker-compose command with custom docker-compose files
*
* @param array $files_before_custom Files to be included before custom compose file is included
* @return string
*/
public static function docker_compose_with_custom( array $files_before_custom = [] ) : string {
$fs = new Filesystem();

$command = 'docker-compose -f docker-compose.yml';

foreach ( $files_before_custom as $file ) {
if ( $fs->exists( $file ) ) {
$command .= ' -f ' . $file ;
}
}

if ( $fs->exists( SITE_CUSTOM_DOCKER_COMPOSE ) ) {
$command .= ' -f ' . SITE_CUSTOM_DOCKER_COMPOSE ;
}

return $command;
}

/**
* Check and Start or create container if not running.
*
Expand Down Expand Up @@ -159,14 +183,15 @@ public static function disconnect_site_network_from( $site_name, $from_container
* @return bool success.
*/
public static function docker_compose_up( $dir, $services = [] ) {
$fs = new Filesystem();
$chdir_return_code = chdir( $dir );
if ( $chdir_return_code ) {
if ( empty( $services ) ) {
return EE::exec( 'docker-compose up -d' );
return EE::exec( \EE_DOCKER::docker_compose_with_custom() . ' up -d' );
} else {
$all_services = implode( ' ', $services );

return EE::exec( "docker-compose up -d $all_services" );
return EE::exec( \EE_DOCKER::docker_compose_with_custom() . ' up -d '. $all_services );
}
}

Expand Down Expand Up @@ -195,7 +220,7 @@ public static function docker_compose_down( $dir ) {
$chdir_return_code = chdir( $dir );
if ( $chdir_return_code ) {

return EE::exec( 'docker-compose down' );
return EE::exec( \EE_DOCKER::docker_compose_with_custom() . ' down' );
}

return false;
Expand All @@ -211,7 +236,7 @@ public static function docker_compose_down( $dir ) {
*/
public static function service_exists( $service, $site_fs_path ) {
chdir( $site_fs_path );
$launch = EE::launch( 'docker-compose config --services' );
$launch = EE::launch( \EE_DOCKER::docker_compose_with_custom() . ' config --services' );
$services = explode( PHP_EOL, trim( $launch->stdout ) );

return in_array( $service, $services, true );
Expand Down
2 changes: 2 additions & 0 deletions php/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use EE;
use EE\Iterators\Transform;
use Mustangostang\Spyc;
use Symfony\Component\Filesystem\Filesystem;

const PHAR_STREAM_PREFIX = 'phar://';

Expand Down Expand Up @@ -1794,3 +1795,4 @@ function sanitize_file_folder_name( $input_name, $strict = true, $remove_forward
// Remove starting and ending hyphens as a starting hyphen in string might be considered as parameter in bash file/folder creation.
return trim( $output, '-' );
}