Skip to content

Commit a17b969

Browse files
authored
Merge pull request #1829 from mrrobot47/update/docker-migration
docker and docker-compose update migration
2 parents fb40793 + 2e7b4cb commit a17b969

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace EE\Migration;
4+
5+
use EE;
6+
use EE\Migration\Base;
7+
8+
class CheckAndUpdateDockerOne extends Base {
9+
10+
/**
11+
* Execute create table query for site and sitemeta table.
12+
*
13+
* @throws EE\ExitException
14+
*/
15+
public function up() {
16+
17+
EE::log( 'Checking Docker version.' );
18+
$docker_version = EE::launch( 'docker version --format "{{.Server.Version}}"' )->stdout;
19+
20+
if ( version_compare( $docker_version, '20.10.10', '<' ) ) {
21+
EE::warning( 'Docker version should be 20.10.10 or above.' );
22+
23+
// If it is MacOS, prompt user to update docker.
24+
if ( 'Darwin' === PHP_OS ) {
25+
EE::confirm( 'Do you want to update Docker?' );
26+
EE::launch( 'open "docker://"' );
27+
}
28+
29+
// If it is Linux, proceed with update.
30+
if ( 'Linux' === PHP_OS ) {
31+
EE::log( 'Updating Docker...' );
32+
EE::launch( 'curl -fsSL https://get.docker.com | sh' );
33+
}
34+
}
35+
36+
// Check the version again post update.
37+
$docker_version = EE::launch( 'docker version --format "{{.Server.Version}}"' )->stdout;
38+
if ( version_compare( $docker_version, '20.10.10', '<' ) ) {
39+
EE::error( 'Docker version should be 20.10.10 or above. Please update Docker and try again.' );
40+
}
41+
}
42+
43+
/**
44+
* Execute drop table query for site and sitemeta table.
45+
*
46+
* @throws EE\ExitException
47+
*/
48+
public function down() {
49+
50+
}
51+
}

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
*

php/EE/Runner.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ public function check_requirements( $show_error = true ) {
105105
$error[] = 'EasyEngine requires docker-compose.';
106106
}
107107

108+
$docker_compose_version = EE::launch( 'docker-compose version --short' )->stdout;
109+
if ( version_compare( $docker_compose_version, '2.26.0', '<' ) ) {
110+
if ( $show_error ) {
111+
EE::warning( 'EasyEngine requires docker-compose version 2.26.0 or greater.' );
112+
EE::warning( 'You can get the updated version of docker-compose from assets in https://github.com/docker/compose/releases/tag/v2.26.1' );
113+
}
114+
}
115+
108116
if ( version_compare( PHP_VERSION, '7.2.0' ) < 0 ) {
109117
$status = false;
110118
$error[] = 'EasyEngine requires minimum PHP 7.2.0 to run.';

0 commit comments

Comments
 (0)