@@ -183,7 +183,7 @@ public static function disconnect_site_network_from( $site_name, $from_container
183183 * @return bool success.
184184 */
185185 public static function docker_compose_up ( $ dir , $ services = [] ) {
186- $ fs = new Filesystem ();
186+
187187 $ chdir_return_code = chdir ( $ dir );
188188 if ( $ chdir_return_code ) {
189189 if ( empty ( $ services ) ) {
@@ -198,6 +198,51 @@ public static function docker_compose_up( $dir, $services = [] ) {
198198 return false ;
199199 }
200200
201+ /**
202+ * Function to exec and run commands into the containers.
203+ *
204+ * @param string $command Command to exec.
205+ * @param string $service Service to exec command into.
206+ * @param string $shell Shell in which exec command will be executed.
207+ * @param string $user User to execute command into.
208+ * @param String $dir Path to docker-compose.yml.
209+ * @param bool $shell_wrapper If shell wrapper should be enabled or not.
210+ * @param bool $exit_on_error To exit or not on error.
211+ * @param array $exec_obfuscate Data to be obfuscated from log.
212+ * @param bool $echo_stdout Output stdout of exec if true.
213+ * @param bool $echo_stderr Output stderr of exec if true.
214+ *
215+ * @return bool success.
216+ */
217+ public static function docker_compose_exec ( $ command = '' , $ service = '' , $ shell = 'sh ' , $ user = '' , $ dir = '' , $ shell_wrapper = false , $ exit_on_error = false , $ exec_obfuscate = [], $ echo_stdout = false , $ echo_stderr = false ) {
218+
219+ if ( ! empty ( $ dir ) ) {
220+ $ chdir_return_code = chdir ( $ dir );
221+ } else {
222+ $ chdir_return_code = true ;
223+ }
224+
225+ $ skip_tty = \EE ::get_runner ()->config ['skip-tty ' ];
226+ $ tty = empty ( $ skip_tty ) ? '' : '-T ' ;
227+
228+ if ( $ chdir_return_code ) {
229+
230+ $ user_string = '' ;
231+ if ( $ user ) {
232+ $ user_string = empty ( $ user ) ? '' : "--user=' $ user' " ;
233+ }
234+
235+ if ( $ shell_wrapper ) {
236+ return EE ::exec ( \EE_DOCKER ::docker_compose_with_custom () . " exec $ tty $ user_string $ service $ shell -c \"$ command \"" , $ echo_stdout , $ echo_stderr , $ exec_obfuscate , $ exit_on_error );
237+ } else {
238+ return EE ::exec ( \EE_DOCKER ::docker_compose_with_custom () . " exec $ tty $ user_string $ service $ command " , $ echo_stdout , $ echo_stderr , $ exec_obfuscate , $ exit_on_error );
239+ }
240+
241+ }
242+
243+ return false ;
244+ }
245+
201246 /**
202247 * Function to check if a network exists
203248 *
0 commit comments