Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added few functions related to docker-compose to avoid some hard-coded EE::exec calls #1428

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
57 changes: 57 additions & 0 deletions php/class-ee-docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down