Skip to content

Commit 8f708b7

Browse files
committed
Update docker-compose version at end of migration
Signed-off-by: Riddhesh Sanghvi <[email protected]>
1 parent 9f75712 commit 8f708b7

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

php/EE/Migration/Containers.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use EE\RevertableStepProcessor;
66
use EE;
7+
use Symfony\Component\Filesystem\Filesystem;
78

89
/**
910
* Upgrade existing containers to new docker-image
@@ -35,6 +36,8 @@ public static function start_container_migration() {
3536
'easyengine/php7.4',
3637
'easyengine/php8.0',
3738
'easyengine/php8.1',
39+
'easyengine/php8.2',
40+
'easyengine/php8.3',
3841
'easyengine/newrelic-daemon',
3942
];
4043

@@ -60,6 +63,7 @@ public static function start_container_migration() {
6063

6164
self::migrate_global_containers( $updated_images );
6265
self::migrate_site_containers( $updated_images );
66+
self::maybe_update_docker_compose();
6367
self::save_upgraded_image_versions( $current_versions, $img_versions, $updated_images );
6468

6569
if ( ! self::$rsp->execute() ) {
@@ -69,6 +73,21 @@ public static function start_container_migration() {
6973
EE\Utils\delem_log( 'Container migration completed' );
7074
}
7175

76+
/**
77+
* Maybe update docker-compose at the end of migration.
78+
* Need to update to latest docker-compose version for new template changes.
79+
*/
80+
public static function maybe_update_docker_compose() {
81+
82+
self::$rsp->add_step(
83+
'update-compose',
84+
'EE\Migration\Containers::update_docker_compose',
85+
'EE\Migration\Containers::revert_docker_compose',
86+
null,
87+
null
88+
);
89+
}
90+
7291
/**
7392
* Save updated image version in database.
7493
*
@@ -103,6 +122,38 @@ public static function image_cleanup() {
103122
EE::exec( 'docker image prune -af --filter=label=org.label-schema.vendor="EasyEngine"' );
104123
}
105124

125+
/**
126+
* Update docker-compose to v2.26.1 if lower version is installed.
127+
*/
128+
public static function update_docker_compose() {
129+
130+
$docker_compose_version = EE::launch( 'docker-compose version --short' )->stdout;
131+
$docker_compose_path = EE::launch( 'command -v docker-compose' )->stdout;
132+
$docker_compose_path = trim( $docker_compose_path );
133+
$docker_compose_backup_path = EE_BACKUP_DIR . '/docker-compose.backup';
134+
$fs = new Filesystem();
135+
if ( ! $fs->exists( EE_BACKUP_DIR ) ) {
136+
$fs->mkdir( EE_BACKUP_DIR );
137+
}
138+
$fs->copy( $docker_compose_path, $docker_compose_backup_path );
139+
140+
if ( version_compare( '2.26.1', $docker_compose_version, '>' ) ) {
141+
EE::exec( "curl -L https://github.com/docker/compose/releases/download/v2.26.1/docker-compose-$(uname -s)-$(uname -m) -o $docker_compose_path && chmod +x $docker_compose_path" );
142+
}
143+
}
144+
145+
/**
146+
* Revert docker-compose to previous version.
147+
*/
148+
public static function revert_docker_compose() {
149+
150+
$docker_compose_path = EE::launch( 'command -v docker-compose' )->stdout;
151+
$docker_compose_path = trim( $docker_compose_path );
152+
$docker_compose_backup_path = EE_BACKUP_DIR . '/docker-compose.backup';
153+
$fs = new Filesystem();
154+
$fs->copy( $docker_compose_backup_path, $docker_compose_path );
155+
}
156+
106157
/**
107158
* Update database entry of images
108159
*

0 commit comments

Comments
 (0)