From e2fd050148059ef0c0661d913bbab382d4ca42c8 Mon Sep 17 00:00:00 2001 From: Hrishikesh Barman Date: Sat, 13 Jul 2019 19:16:09 +0530 Subject: [PATCH] Added few functions related to docker-compose to avoid hard-coded exec calls Added these methods to EE_DOCKER class: * docker_compose_restart( $dir, $containers ) * docker_compose_stop( $dir, $containers ) * docker_compose_forcerm( $dir, $containers ) * docker_compose_exec( $dir, $container, $exec_command ) Signed-off-by: Hrishikesh Barman --- php/class-ee-docker.php | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/php/class-ee-docker.php b/php/class-ee-docker.php index 8c0be97b2..c446da45c 100644 --- a/php/class-ee-docker.php +++ b/php/class-ee-docker.php @@ -201,6 +201,63 @@ public static function docker_compose_down( $dir ) { return false; } + /** + * Function to restart the containers. + * + * @param String $dir Path to docker-compose.yml. + * + * @return bool success. + */ + public static function docker_compose_restart( $dir, $containers ) { + if ( chdir( $dir ) ) { + return EE::exec( "docker-compose restart $containers", true, true ); + } + throw new \Exception( "Could not resolve $dir" ); + } + + /** + * Function to stop the containers. + * + * @param String $dir Path to docker-compose.yml. + * + * @return bool success. + */ + public static function docker_compose_stop( $dir, $containers ) { + if ( chdir( $dir ) ) { + return EE::exec( "docker-compose stop $containers", true, true ); + } + throw new \Exception( "Could not resolve $dir" ); + } + + /** + * Function to force remove the containers. + * + * @param String $dir Path to docker-compose.yml. + * + * @return bool success. + */ + public static function docker_compose_forcerm( $dir, $containers ) { + if ( chdir( $dir ) ) { + return EE::exec( "docker-compose rm -f $containers", true, true ); + } + throw new \Exception( "Could not resolve $dir" ); + } + + /** + * Function to exec command in a running container. + * + * @param String $dir Path to docker-compose.yml. + * + * @return bool success. + */ + public static function docker_compose_exec( $dir, $container, $exec_command ) { + if ( chdir( $dir ) ) { + EE::log( "Executing: [$container]: $exec_command" ); + return EE::exec( "docker-compose exec $container $exec_command", true, true ); + } + throw new \Exception( "Could not resolve $dir" ); + } + /** * Check if a particular service exists in given docker-compose.yml. *