Skip to content

Commit 4800c61

Browse files
committed
Merge branch 'develop' for v4.7.0
2 parents adc6bf0 + 873d6c3 commit 4800c61

10 files changed

+547
-426
lines changed

.github/workflows/test_and_build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
strategy:
9393
fail-fast: false
9494
matrix:
95-
php: ['7.2', '7.3', '7.4', '8.0', '8.1']
95+
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
9696
steps:
9797
- name: Check out source code
9898
uses: actions/checkout@v3
@@ -127,7 +127,7 @@ jobs:
127127
128128
- name: Install docker-compose
129129
run: |
130-
sudo curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
130+
sudo curl -L https://github.com/docker/compose/releases/download/v2.27.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
131131
sudo chmod +x /usr/local/bin/docker-compose
132132
133133
- name: Install dependencies

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.6.6
1+
4.7.0

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
"easyengine/admin-tools-command": "v1.1.0",
3232
"easyengine/auth-command": "v1.2.0",
3333
"easyengine/config-command": "v1.0.2",
34-
"easyengine/cron-command": "v2.0.0",
34+
"easyengine/cron-command": "v2.0.2",
3535
"easyengine/log-command": "v1.1.0",
3636
"easyengine/mailhog-command": "v1.0.3",
37-
"easyengine/service-command": "v1.5.0",
37+
"easyengine/service-command": "v1.6.0",
3838
"easyengine/shell-command": "v1.1.1",
39-
"easyengine/site-command": "v3.2.4",
40-
"easyengine/site-type-php": "v1.7.0",
41-
"easyengine/site-type-wp": "v1.7.1",
39+
"easyengine/site-command": "v3.3.0",
40+
"easyengine/site-type-php": "v1.8.0",
41+
"easyengine/site-type-wp": "v1.8.0",
4242
"monolog/monolog": "1.24.0",
4343
"mustache/mustache": "2.14.1",
4444
"rmccue/requests": "1.8.0",

composer.lock

Lines changed: 342 additions & 338 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

img-versions.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
{
2-
"easyengine/cron": "v4.6.5",
2+
"easyengine/cron": "v4.7.0",
33
"easyengine/mailhog": "v4.6.5",
44
"easyengine/mariadb": "v4.6.6",
5-
"easyengine/nginx-proxy": "v4.6.5",
6-
"easyengine/nginx": "v4.6.5",
5+
"easyengine/nginx-proxy": "v4.7.0",
6+
"easyengine/nginx": "v4.7.0",
77
"easyengine/php": "v4.6.6",
88
"easyengine/php5.6": "v4.6.6",
99
"easyengine/php7.0": "v4.6.6",
1010
"easyengine/php7.2": "v4.6.6",
1111
"easyengine/php7.3": "v4.6.6",
12-
"easyengine/php7.4": "v4.6.6",
13-
"easyengine/php8.0": "v4.6.6",
14-
"easyengine/php8.1": "v4.6.6",
15-
"easyengine/postfix": "v4.6.5",
16-
"easyengine/redis": "v4.6.5",
17-
"easyengine/newrelic-daemon": "v4.6.5"
12+
"easyengine/php7.4": "v4.7.0",
13+
"easyengine/php8.0": "v4.7.0",
14+
"easyengine/php8.1": "v4.7.0",
15+
"easyengine/php8.2": "v4.7.0",
16+
"easyengine/php8.3": "v4.7.0",
17+
"easyengine/postfix": "v4.7.0",
18+
"easyengine/redis": "v4.7.0",
19+
"easyengine/newrelic-daemon": "v4.7.0"
1820
}

migrations/db/20230312102550_easyengine_check_and_update_docker.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class CheckAndUpdateDocker extends Base {
1414
*/
1515
public function up() {
1616

17-
EE::log( 'Checking Docker version.' );
17+
EE::debug( 'Checking Docker version.' );
1818
$docker_version = EE::launch( 'docker version --format "{{.Server.Version}}"' )->stdout;
1919

2020
if ( version_compare( $docker_version, '20.10.10', '<' ) ) {
@@ -28,7 +28,7 @@ public function up() {
2828

2929
// If it is Linux, proceed with update.
3030
if ( 'Linux' === PHP_OS ) {
31-
EE::log( 'Updating Docker...' );
31+
EE::debug( 'Updating Docker...' );
3232
EE::launch( 'curl -fsSL https://get.docker.com | sh' );
3333
}
3434
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace EE\Migration;
4+
5+
use EE;
6+
use EE\Migration\Base;
7+
use Symfony\Component\Filesystem\Filesystem;
8+
9+
class CheckAndUpdateDockerOne extends Base {
10+
11+
public function __construct() {
12+
13+
if ( $this->is_first_execution ) {
14+
$this->skip_this_migration = true;
15+
}
16+
}
17+
18+
/**
19+
* Execute create table query for site and sitemeta table.
20+
*
21+
* @throws EE\ExitException
22+
*/
23+
public function up() {
24+
25+
if ( $this->skip_this_migration ) {
26+
EE::debug( 'Skipping migration as it is not needed.' );
27+
28+
return;
29+
}
30+
31+
EE::debug( 'Checking Docker version.' );
32+
$docker_version = trim( EE::launch( 'docker version --format "{{.Server.Version}}"' )->stdout );
33+
34+
if ( version_compare( $docker_version, '20.10.10', '<' ) ) {
35+
EE::warning( 'Docker version should be 20.10.10 or above.' );
36+
37+
// If it is MacOS, prompt user to update docker.
38+
if ( 'Darwin' === PHP_OS ) {
39+
EE::confirm( 'Do you want to update Docker?' );
40+
EE::launch( 'open "docker://"' );
41+
}
42+
43+
// If it is Linux, proceed with update.
44+
if ( 'Linux' === PHP_OS ) {
45+
EE::debug( 'Updating Docker...' );
46+
EE::launch( 'curl -fsSL https://get.docker.com | sh' );
47+
}
48+
}
49+
50+
EE::debug( 'Checking docker-compose version' );
51+
$docker_compose_version = trim( EE::launch( 'docker-compose version --short' )->stdout );
52+
$docker_compose_path = EE::launch( 'command -v docker-compose' )->stdout;
53+
$docker_compose_path = trim( $docker_compose_path );
54+
$docker_compose_backup_path = EE_BACKUP_DIR . '/docker-compose.backup';
55+
$docker_compose_new_path = EE_BACKUP_DIR . '/docker-compose';
56+
$fs = new Filesystem();
57+
if ( ! $fs->exists( EE_BACKUP_DIR ) ) {
58+
$fs->mkdir( EE_BACKUP_DIR );
59+
}
60+
$fs->copy( $docker_compose_path, $docker_compose_backup_path );
61+
62+
if ( version_compare( '1.29.2', $docker_compose_version, '!=' ) ) {
63+
EE::exec( "curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m) -o $docker_compose_new_path && chmod +x $docker_compose_new_path" );
64+
EE::exec( "mv $docker_compose_new_path $docker_compose_path" );
65+
}
66+
67+
// Check the version again post update.
68+
$docker_version = trim( EE::launch( 'docker version --format "{{.Server.Version}}"' )->stdout );
69+
if ( version_compare( $docker_version, '20.10.10', '<' ) ) {
70+
EE::error( 'Docker version should be 20.10.10 or above. Please update Docker and try again.' );
71+
}
72+
73+
$docker_compose_version = trim( EE::launch( 'docker-compose version --short' )->stdout );
74+
if ( version_compare( '1.29.2', $docker_compose_version, '!=' ) ) {
75+
EE::error( 'Docker-compose version should be 1.29.2. Please update Docker-compose and try again.' );
76+
}
77+
}
78+
79+
/**
80+
* Execute drop table query for site and sitemeta table.
81+
*
82+
* @throws EE\ExitException
83+
*/
84+
public function down() {
85+
86+
}
87+
}

php/EE/Migration/Containers.php

Lines changed: 83 additions & 35 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,30 +36,35 @@ 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

4144
foreach ( $img_versions as $img => $version ) {
4245

43-
if ( in_array( $img, $skip_download ) ) {
44-
continue;
45-
}
4646
if ( array_key_exists( $img, $current_versions ) ) {
4747
if ( $current_versions[ $img ] !== $version ) {
4848
$updated_images[] = $img;
49-
self::pull_or_error( $img, $version );
49+
if ( ! in_array( $img, $skip_download ) ) {
50+
self::pull_or_error( $img, $version );
51+
}
5052
}
5153
} else {
52-
self::pull_or_error( $img, $version );
54+
if ( ! in_array( $img, $skip_download ) ) {
55+
self::pull_or_error( $img, $version );
56+
}
5357
}
5458
}
5559

5660
if ( empty( $updated_images ) ) {
61+
5762
return;
5863
}
5964

6065
self::migrate_global_containers( $updated_images );
6166
self::migrate_site_containers( $updated_images );
67+
self::maybe_update_docker_compose();
6268
self::save_upgraded_image_versions( $current_versions, $img_versions, $updated_images );
6369

6470
if ( ! self::$rsp->execute() ) {
@@ -68,6 +74,21 @@ public static function start_container_migration() {
6874
EE\Utils\delem_log( 'Container migration completed' );
6975
}
7076

77+
/**
78+
* Maybe update docker-compose at the end of migration.
79+
* Need to update to latest docker-compose version for new template changes.
80+
*/
81+
public static function maybe_update_docker_compose() {
82+
83+
self::$rsp->add_step(
84+
'update-compose',
85+
'EE\Migration\Containers::update_docker_compose',
86+
'EE\Migration\Containers::revert_docker_compose',
87+
null,
88+
null
89+
);
90+
}
91+
7192
/**
7293
* Save updated image version in database.
7394
*
@@ -102,6 +123,42 @@ public static function image_cleanup() {
102123
EE::exec( 'docker image prune -af --filter=label=org.label-schema.vendor="EasyEngine"' );
103124
}
104125

126+
/**
127+
* Update docker-compose to v2.27.0 if lower version is installed.
128+
*/
129+
public static function update_docker_compose() {
130+
131+
$docker_compose_version = EE::launch( 'docker-compose version --short' )->stdout;
132+
$docker_compose_path = EE::launch( 'command -v docker-compose' )->stdout;
133+
$docker_compose_path = trim( $docker_compose_path );
134+
$docker_compose_backup_path = EE_BACKUP_DIR . '/docker-compose.backup';
135+
$docker_compose_new_path = EE_BACKUP_DIR . '/docker-compose';
136+
137+
if ( version_compare( '2.27.0', $docker_compose_version, '>' ) ) {
138+
139+
$fs = new Filesystem();
140+
if ( ! $fs->exists( EE_BACKUP_DIR ) ) {
141+
$fs->mkdir( EE_BACKUP_DIR );
142+
}
143+
$fs->copy( $docker_compose_path, $docker_compose_backup_path );
144+
145+
EE::exec( "curl -L https://github.com/docker/compose/releases/download/v2.27.0/docker-compose-$(uname -s)-$(uname -m) -o $docker_compose_new_path && chmod +x $docker_compose_new_path" );
146+
EE::exec( "mv $docker_compose_new_path $docker_compose_path" );
147+
}
148+
}
149+
150+
/**
151+
* Revert docker-compose to previous version.
152+
*/
153+
public static function revert_docker_compose() {
154+
155+
$docker_compose_path = EE::launch( 'command -v docker-compose' )->stdout;
156+
$docker_compose_path = trim( $docker_compose_path );
157+
$docker_compose_backup_path = EE_BACKUP_DIR . '/docker-compose.backup';
158+
$fs = new Filesystem();
159+
$fs->copy( $docker_compose_backup_path, $docker_compose_path );
160+
}
161+
105162
/**
106163
* Update database entry of images
107164
*
@@ -151,16 +208,29 @@ public static function pull_or_error( $image, $version ) {
151208
* @throws \Exception
152209
*/
153210
public static function get_current_docker_images_versions() {
154-
$images = EE::db()
155-
->table( 'options' )
156-
->where( 'key', 'like', 'easyengine/%' )
157-
->all();
158211

159-
$images = array_map( function ( $image ) {
160-
return [ $image['key'] => $image['value'] ];
161-
}, $images );
212+
$dbImages = EE::db()
213+
->table( 'options' )
214+
->where( 'key', 'like', 'easyengine/%' )
215+
->all();
216+
217+
$dbImages = array_column( $dbImages, 'value', 'key' );
218+
219+
$dockerImages = EE::launch( 'docker ps --format "{{.Image}}" | grep "^easyengine/" | sort -u' )->stdout;
220+
$dockerImages = explode( "\n", trim( $dockerImages ) );
221+
222+
$dockerImages = array_reduce( $dockerImages, function ( $result, $image ) {
223+
224+
[ $imageName, $tag ] = explode( ':', $image, 2 ) + [ 1 => null ];
225+
$result[ $imageName ] = $tag;
226+
227+
return $result;
228+
}, [] );
162229

163-
return array_merge( ...$images );
230+
$mergedImages = $dockerImages + $dbImages;
231+
$mergedImages = array_filter( $mergedImages );
232+
233+
return $mergedImages;
164234
}
165235

166236
/**
@@ -186,17 +256,6 @@ private static function migrate_global_containers( $updated_images ) {
186256
[ $global_compose_file_backup_path, $global_compose_file_path, $updated_global_images ]
187257
);
188258

189-
/**
190-
* Create support containers.
191-
*/
192-
self::$rsp->add_step(
193-
'create-support-global-containers',
194-
'EE\Migration\GlobalContainers::enable_support_containers',
195-
'EE\Migration\GlobalContainers::disable_support_containers',
196-
null,
197-
null
198-
);
199-
200259
self::$rsp->add_step(
201260
'stop-global-containers',
202261
'EE\Migration\GlobalContainers::down_global_containers',
@@ -226,17 +285,6 @@ private static function migrate_global_containers( $updated_images ) {
226285
[ $global_service_name ]
227286
);
228287
}
229-
230-
/**
231-
* Remove support containers.
232-
*/
233-
self::$rsp->add_step(
234-
'remove-support-global-containers',
235-
'EE\Migration\GlobalContainers::disable_support_containers',
236-
'EE\Migration\GlobalContainers::enable_support_containers',
237-
null,
238-
null
239-
);
240288
}
241289

242290
/**

0 commit comments

Comments
 (0)