Skip to content

Commit d67c517

Browse files
committed
Merge branch 'mrrobot47-update/for-migrations' into develop-v4
2 parents eacfbad + 294a656 commit d67c517

File tree

6 files changed

+63
-14
lines changed

6 files changed

+63
-14
lines changed

php/EE/Migration/SiteContainers.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@ public static function backup_restore( $source, $destination = '', $delete_diffe
182182
}
183183
}
184184

185+
/**
186+
* Function to delete file/directory.
187+
*
188+
* @param string|array $path_to_delete File(s)/Director(y/ies) to be deleted.
189+
*/
190+
public static function delete( $path_to_delete ) {
191+
$fs = new Filesystem();
192+
$fs->remove( $path_to_delete );
193+
}
194+
185195
/**
186196
* Function to reload site's nginx.
187197
*

php/EE/Runner.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,9 @@ private function init_ee() {
7070
private function migrate() {
7171
$rsp = new \EE\RevertableStepProcessor();
7272

73-
$version = Option::where( 'key', 'version' );
74-
if ( ! empty( $version ) ) {
75-
$rsp->add_step( 'ee-custom-container-migrations', 'EE\Migration\CustomContainerMigrations::execute_migrations' );
76-
$rsp->add_step( 'ee-docker-image-migrations', 'EE\Migration\Containers::start_container_migration' );
77-
}
7873
$rsp->add_step( 'ee-db-migrations', 'EE\Migration\Executor::execute_migrations' );
74+
$rsp->add_step( 'ee-custom-container-migrations', 'EE\Migration\CustomContainerMigrations::execute_migrations' );
75+
$rsp->add_step( 'ee-docker-image-migrations', 'EE\Migration\Containers::start_container_migration' );
7976
return $rsp->execute();
8077
}
8178

php/class-ee-docker.php

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

php/class-ee.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static function get_cache() {
9494

9595
if ( ! $cache ) {
9696
$home = Utils\get_home_dir();
97-
$dir = getenv( 'EE_CACHE_DIR' ) ? : '/opt/easyengine/.cache/';
97+
$dir = getenv( 'EE_CACHE_DIR' ) ? : EE_ROOT_DIR . '/.cache/';
9898

9999
// 6 months, 300mb
100100
$cache = new FileCache( $dir, 15552000, 314572800 );

php/commands/src/CLI_Command.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,7 @@ public function self_uninstall( $args, $assoc_args ) {
507507
$fs->remove( $sites_paths );
508508
}
509509

510-
EE::exec( "rm -df $home/ee-sites/" );
511-
EE::exec( "rm -rf /opt/easyengine/" );
510+
EE::exec( "rm -rf " . EE_ROOT_DIR );
512511

513512
if ( Utils\inside_phar() ) {
514513
unlink( realpath( $_SERVER['argv'][0] ) );

php/init-ee.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@
44
define( 'EE', true );
55
define( 'EE_VERSION', trim( file_get_contents( EE_ROOT . '/VERSION' ) ) );
66
define( 'EE_START_MICROTIME', microtime( true ) );
7-
define( 'EE_ROOT_DIR', '/opt/easyengine' );
8-
define( 'EE_BACKUP_DIR', '/opt/easyengine/.backup' );
7+
define( 'IS_DARWIN', 'Darwin' === php_uname( 's' ) );
8+
9+
if ( IS_DARWIN ) {
10+
define( 'EE_ROOT_DIR', rtrim( getenv( 'HOME' ), '/\\' ) . '/easyengine' );
11+
} else {
12+
define( 'EE_ROOT_DIR', '/opt/easyengine' );
13+
}
14+
15+
define( 'EE_BACKUP_DIR', EE_ROOT_DIR . '/.backup' );
16+
define( 'EE_SERVICE_DIR', EE_ROOT_DIR . '/services' );
917
define( 'EE_PROXY_TYPE', 'ee-global-nginx-proxy' );
1018

1119
if ( file_exists( EE_ROOT . '/vendor/autoload.php' ) ) {

0 commit comments

Comments
 (0)