Skip to content

Commit

Permalink
Merge branch 'develop' for v4.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mrrobot47 committed May 14, 2024
2 parents adc6bf0 + 873d6c3 commit 4800c61
Show file tree
Hide file tree
Showing 10 changed files with 547 additions and 426 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test_and_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.2', '7.3', '7.4', '8.0', '8.1']
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
steps:
- name: Check out source code
uses: actions/checkout@v3
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
- name: Install docker-compose
run: |
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
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
sudo chmod +x /usr/local/bin/docker-compose
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.6.6
4.7.0
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
"easyengine/admin-tools-command": "v1.1.0",
"easyengine/auth-command": "v1.2.0",
"easyengine/config-command": "v1.0.2",
"easyengine/cron-command": "v2.0.0",
"easyengine/cron-command": "v2.0.2",
"easyengine/log-command": "v1.1.0",
"easyengine/mailhog-command": "v1.0.3",
"easyengine/service-command": "v1.5.0",
"easyengine/service-command": "v1.6.0",
"easyengine/shell-command": "v1.1.1",
"easyengine/site-command": "v3.2.4",
"easyengine/site-type-php": "v1.7.0",
"easyengine/site-type-wp": "v1.7.1",
"easyengine/site-command": "v3.3.0",
"easyengine/site-type-php": "v1.8.0",
"easyengine/site-type-wp": "v1.8.0",
"monolog/monolog": "1.24.0",
"mustache/mustache": "2.14.1",
"rmccue/requests": "1.8.0",
Expand Down
680 changes: 342 additions & 338 deletions composer.lock

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions img-versions.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{
"easyengine/cron": "v4.6.5",
"easyengine/cron": "v4.7.0",
"easyengine/mailhog": "v4.6.5",
"easyengine/mariadb": "v4.6.6",
"easyengine/nginx-proxy": "v4.6.5",
"easyengine/nginx": "v4.6.5",
"easyengine/nginx-proxy": "v4.7.0",
"easyengine/nginx": "v4.7.0",
"easyengine/php": "v4.6.6",
"easyengine/php5.6": "v4.6.6",
"easyengine/php7.0": "v4.6.6",
"easyengine/php7.2": "v4.6.6",
"easyengine/php7.3": "v4.6.6",
"easyengine/php7.4": "v4.6.6",
"easyengine/php8.0": "v4.6.6",
"easyengine/php8.1": "v4.6.6",
"easyengine/postfix": "v4.6.5",
"easyengine/redis": "v4.6.5",
"easyengine/newrelic-daemon": "v4.6.5"
"easyengine/php7.4": "v4.7.0",
"easyengine/php8.0": "v4.7.0",
"easyengine/php8.1": "v4.7.0",
"easyengine/php8.2": "v4.7.0",
"easyengine/php8.3": "v4.7.0",
"easyengine/postfix": "v4.7.0",
"easyengine/redis": "v4.7.0",
"easyengine/newrelic-daemon": "v4.7.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CheckAndUpdateDocker extends Base {
*/
public function up() {

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

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

// If it is Linux, proceed with update.
if ( 'Linux' === PHP_OS ) {
EE::log( 'Updating Docker...' );
EE::debug( 'Updating Docker...' );
EE::launch( 'curl -fsSL https://get.docker.com | sh' );
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace EE\Migration;

use EE;
use EE\Migration\Base;
use Symfony\Component\Filesystem\Filesystem;

class CheckAndUpdateDockerOne extends Base {

public function __construct() {

if ( $this->is_first_execution ) {
$this->skip_this_migration = true;
}
}

/**
* Execute create table query for site and sitemeta table.
*
* @throws EE\ExitException
*/
public function up() {

if ( $this->skip_this_migration ) {
EE::debug( 'Skipping migration as it is not needed.' );

return;
}

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

if ( version_compare( $docker_version, '20.10.10', '<' ) ) {
EE::warning( 'Docker version should be 20.10.10 or above.' );

// If it is MacOS, prompt user to update docker.
if ( 'Darwin' === PHP_OS ) {
EE::confirm( 'Do you want to update Docker?' );
EE::launch( 'open "docker://"' );
}

// If it is Linux, proceed with update.
if ( 'Linux' === PHP_OS ) {
EE::debug( 'Updating Docker...' );
EE::launch( 'curl -fsSL https://get.docker.com | sh' );
}
}

EE::debug( 'Checking docker-compose version' );
$docker_compose_version = trim( EE::launch( 'docker-compose version --short' )->stdout );
$docker_compose_path = EE::launch( 'command -v docker-compose' )->stdout;
$docker_compose_path = trim( $docker_compose_path );
$docker_compose_backup_path = EE_BACKUP_DIR . '/docker-compose.backup';
$docker_compose_new_path = EE_BACKUP_DIR . '/docker-compose';
$fs = new Filesystem();
if ( ! $fs->exists( EE_BACKUP_DIR ) ) {
$fs->mkdir( EE_BACKUP_DIR );
}
$fs->copy( $docker_compose_path, $docker_compose_backup_path );

if ( version_compare( '1.29.2', $docker_compose_version, '!=' ) ) {
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" );
EE::exec( "mv $docker_compose_new_path $docker_compose_path" );
}

// Check the version again post update.
$docker_version = trim( EE::launch( 'docker version --format "{{.Server.Version}}"' )->stdout );
if ( version_compare( $docker_version, '20.10.10', '<' ) ) {
EE::error( 'Docker version should be 20.10.10 or above. Please update Docker and try again.' );
}

$docker_compose_version = trim( EE::launch( 'docker-compose version --short' )->stdout );
if ( version_compare( '1.29.2', $docker_compose_version, '!=' ) ) {
EE::error( 'Docker-compose version should be 1.29.2. Please update Docker-compose and try again.' );
}
}

/**
* Execute drop table query for site and sitemeta table.
*
* @throws EE\ExitException
*/
public function down() {

}
}
118 changes: 83 additions & 35 deletions php/EE/Migration/Containers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use EE\RevertableStepProcessor;
use EE;
use Symfony\Component\Filesystem\Filesystem;

/**
* Upgrade existing containers to new docker-image
Expand Down Expand Up @@ -35,30 +36,35 @@ public static function start_container_migration() {
'easyengine/php7.4',
'easyengine/php8.0',
'easyengine/php8.1',
'easyengine/php8.2',
'easyengine/php8.3',
'easyengine/newrelic-daemon',
];

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

if ( in_array( $img, $skip_download ) ) {
continue;
}
if ( array_key_exists( $img, $current_versions ) ) {
if ( $current_versions[ $img ] !== $version ) {
$updated_images[] = $img;
self::pull_or_error( $img, $version );
if ( ! in_array( $img, $skip_download ) ) {
self::pull_or_error( $img, $version );
}
}
} else {
self::pull_or_error( $img, $version );
if ( ! in_array( $img, $skip_download ) ) {
self::pull_or_error( $img, $version );
}
}
}

if ( empty( $updated_images ) ) {

return;
}

self::migrate_global_containers( $updated_images );
self::migrate_site_containers( $updated_images );
self::maybe_update_docker_compose();
self::save_upgraded_image_versions( $current_versions, $img_versions, $updated_images );

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

/**
* Maybe update docker-compose at the end of migration.
* Need to update to latest docker-compose version for new template changes.
*/
public static function maybe_update_docker_compose() {

self::$rsp->add_step(
'update-compose',
'EE\Migration\Containers::update_docker_compose',
'EE\Migration\Containers::revert_docker_compose',
null,
null
);
}

/**
* Save updated image version in database.
*
Expand Down Expand Up @@ -102,6 +123,42 @@ public static function image_cleanup() {
EE::exec( 'docker image prune -af --filter=label=org.label-schema.vendor="EasyEngine"' );
}

/**
* Update docker-compose to v2.27.0 if lower version is installed.
*/
public static function update_docker_compose() {

$docker_compose_version = EE::launch( 'docker-compose version --short' )->stdout;
$docker_compose_path = EE::launch( 'command -v docker-compose' )->stdout;
$docker_compose_path = trim( $docker_compose_path );
$docker_compose_backup_path = EE_BACKUP_DIR . '/docker-compose.backup';
$docker_compose_new_path = EE_BACKUP_DIR . '/docker-compose';

if ( version_compare( '2.27.0', $docker_compose_version, '>' ) ) {

$fs = new Filesystem();
if ( ! $fs->exists( EE_BACKUP_DIR ) ) {
$fs->mkdir( EE_BACKUP_DIR );
}
$fs->copy( $docker_compose_path, $docker_compose_backup_path );

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" );
EE::exec( "mv $docker_compose_new_path $docker_compose_path" );
}
}

/**
* Revert docker-compose to previous version.
*/
public static function revert_docker_compose() {

$docker_compose_path = EE::launch( 'command -v docker-compose' )->stdout;
$docker_compose_path = trim( $docker_compose_path );
$docker_compose_backup_path = EE_BACKUP_DIR . '/docker-compose.backup';
$fs = new Filesystem();
$fs->copy( $docker_compose_backup_path, $docker_compose_path );
}

/**
* Update database entry of images
*
Expand Down Expand Up @@ -151,16 +208,29 @@ public static function pull_or_error( $image, $version ) {
* @throws \Exception
*/
public static function get_current_docker_images_versions() {
$images = EE::db()
->table( 'options' )
->where( 'key', 'like', 'easyengine/%' )
->all();

$images = array_map( function ( $image ) {
return [ $image['key'] => $image['value'] ];
}, $images );
$dbImages = EE::db()
->table( 'options' )
->where( 'key', 'like', 'easyengine/%' )
->all();

$dbImages = array_column( $dbImages, 'value', 'key' );

$dockerImages = EE::launch( 'docker ps --format "{{.Image}}" | grep "^easyengine/" | sort -u' )->stdout;
$dockerImages = explode( "\n", trim( $dockerImages ) );

$dockerImages = array_reduce( $dockerImages, function ( $result, $image ) {

[ $imageName, $tag ] = explode( ':', $image, 2 ) + [ 1 => null ];
$result[ $imageName ] = $tag;

return $result;
}, [] );

return array_merge( ...$images );
$mergedImages = $dockerImages + $dbImages;
$mergedImages = array_filter( $mergedImages );

return $mergedImages;
}

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

/**
* Create support containers.
*/
self::$rsp->add_step(
'create-support-global-containers',
'EE\Migration\GlobalContainers::enable_support_containers',
'EE\Migration\GlobalContainers::disable_support_containers',
null,
null
);

self::$rsp->add_step(
'stop-global-containers',
'EE\Migration\GlobalContainers::down_global_containers',
Expand Down Expand Up @@ -226,17 +285,6 @@ private static function migrate_global_containers( $updated_images ) {
[ $global_service_name ]
);
}

/**
* Remove support containers.
*/
self::$rsp->add_step(
'remove-support-global-containers',
'EE\Migration\GlobalContainers::disable_support_containers',
'EE\Migration\GlobalContainers::enable_support_containers',
null,
null
);
}

/**
Expand Down
Loading

0 comments on commit 4800c61

Please sign in to comment.