Skip to content

Commit acaf008

Browse files
committed
Update fetching existing img versions
Signed-off-by: Riddhesh Sanghvi <[email protected]>
1 parent 43d00ee commit acaf008

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

php/EE/Migration/Containers.php

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,17 @@ public static function start_container_migration() {
4040

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

43-
if ( in_array( $img, $skip_download ) ) {
44-
continue;
45-
}
4643
if ( array_key_exists( $img, $current_versions ) ) {
4744
if ( $current_versions[ $img ] !== $version ) {
4845
$updated_images[] = $img;
49-
self::pull_or_error( $img, $version );
46+
if ( ! in_array( $img, $skip_download ) ) {
47+
self::pull_or_error( $img, $version );
48+
}
5049
}
5150
} else {
52-
self::pull_or_error( $img, $version );
51+
if ( ! in_array( $img, $skip_download ) ) {
52+
self::pull_or_error( $img, $version );
53+
}
5354
}
5455
}
5556

@@ -151,16 +152,29 @@ public static function pull_or_error( $image, $version ) {
151152
* @throws \Exception
152153
*/
153154
public static function get_current_docker_images_versions() {
154-
$images = EE::db()
155-
->table( 'options' )
156-
->where( 'key', 'like', 'easyengine/%' )
157-
->all();
158155

159-
$images = array_map( function ( $image ) {
160-
return [ $image['key'] => $image['value'] ];
161-
}, $images );
156+
$dbImages = EE::db()
157+
->table( 'options' )
158+
->where( 'key', 'like', 'easyengine/%' )
159+
->all();
160+
161+
$dbImages = array_column( $dbImages, 'value', 'key' );
162+
163+
$dockerImages = EE::launch( 'docker ps --format "{{.Image}}" | grep "^easyengine/" | sort -u' )->stdout;
164+
$dockerImages = explode( "\n", trim( $dockerImages ) );
165+
166+
$dockerImages = array_reduce( $dockerImages, function ( $result, $image ) {
167+
168+
[ $imageName, $tag ] = explode( ':', $image, 2 ) + [ 1 => null ];
169+
$result[ $imageName ] = $tag;
170+
171+
return $result;
172+
}, [] );
173+
174+
$mergedImages = $dockerImages + $dbImages;
175+
$mergedImages = array_filter( $mergedImages );
162176

163-
return array_merge( ...$images );
177+
return $mergedImages;
164178
}
165179

166180
/**

0 commit comments

Comments
 (0)