@@ -153,8 +153,8 @@ public static function disconnect_site_network_from( $site_name, $from_container
153153 /**
154154 * Function to boot the containers.
155155 *
156- * @param String $dir Path to docker-compose.yml.
157- * @param array $services Services to bring up.
156+ * @param String $dir Path to docker-compose.yml.
157+ * @param array $services Services to bring up.
158158 *
159159 * @return bool success.
160160 */
@@ -187,7 +187,7 @@ public static function docker_network_exists( string $network ) {
187187 /**
188188 * Function to destroy the containers.
189189 *
190- * @param String $dir Path to docker-compose.yml.
190+ * @param String $dir Path to docker-compose.yml.
191191 *
192192 * @return bool success.
193193 */
@@ -234,7 +234,10 @@ public static function get_docker_style_prefix( $site_url ) {
234234 * @param string $prefix Prefix by volumes have to be created.
235235 * @param array $volumes The volumes to be created.
236236 * $volumes[$key]['name'] => specifies the name of volume to be created.
237- * $volumes[$key]['path_to_symlink'] => specifies the path to symlink the created volume.
237+ * $volumes[$key]['path_to_symlink'] => specifies the path to symlink the
238+ * created volume.
239+ * $volumes[$key]['skip_volume'] => if set to `true` will skip volume creation
240+ * for that entry.
238241 * @param bool $update_to_docker_prefix Update the prefix in dockerized style.
239242 */
240243 public static function create_volumes ( $ prefix , $ volumes , $ update_to_docker_prefix = true ) {
@@ -247,6 +250,9 @@ public static function create_volumes( $prefix, $volumes, $update_to_docker_pref
247250 $ docker_root_dir = trim ( $ launch ->stdout );
248251
249252 foreach ( $ volumes as $ volume ) {
253+ if ( ! empty ( $ volume ['skip_volume ' ] ) && true === $ volume ['skip_volume ' ] ) {
254+ continue ;
255+ }
250256 $ fs ->mkdir ( dirname ( $ volume ['path_to_symlink ' ] ) );
251257 EE ::exec (
252258 sprintf (
@@ -275,4 +281,33 @@ public static function get_volumes_by_label( $label ) {
275281
276282 return array_filter ( explode ( PHP_EOL , trim ( $ launch ->stdout ) ), 'trim ' );
277283 }
284+
285+ /**
286+ * Function to return minimal docker-compose `host:container` volume mounting array.
287+ *
288+ * @param array $extended_vols :
289+ * $extended_vols['name'] - Host path for docker-compose generation in linux
290+ * $extended_vols['path_to_symlink'] - Host path for docker-compose generation in
291+ * darwin.
292+ * $extended_vols['container_path'] - Path inside container, common for linux and
293+ * darwin.
294+ * $extended_vols['skip_darwin'] - if set to true skips that volume for darwin.
295+ * $extended_vols['skip_linux'] - if set to true skips that volume for linux.
296+ *
297+ * @return array having docker-compose `host:container` volume mounting.
298+ */
299+ public static function get_mounting_volume_array ( $ extended_vols ) {
300+
301+ $ volume_gen_key = IS_DARWIN ? 'path_to_symlink ' : 'name ' ;
302+ $ skip_key = IS_DARWIN ? 'skip_darwin ' : 'skip_linux ' ;
303+ $ final_mount_volumes = [];
304+ foreach ( $ extended_vols as $ extended_vol ) {
305+ if ( ! empty ( $ extended_vol [ $ skip_key ] ) && true === $ extended_vol [ $ skip_key ] ) {
306+ continue ;
307+ }
308+ $ final_mount_volumes [] = $ extended_vol [ $ volume_gen_key ] . ': ' . $ extended_vol ['container_path ' ];
309+ }
310+
311+ return $ final_mount_volumes ;
312+ }
278313}
0 commit comments