Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Service_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public function refresh( $args, $assoc_args ) {
foreach ( $running_services as $service ) {
if ( ! empty( $service['state'] ) ) {
EE::exec( \EE_DOCKER::docker_compose_with_custom() . " up -d global-${service['name']}", true, true );
\EE\Service\Utils\record_global_image_version( 'services_global-' . $service['name'] . '_1' );
}
}

Expand Down
30 changes: 30 additions & 0 deletions src/helper/service-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function nginx_proxy_check() {
if ( ! \EE_DOCKER::docker_compose_up( EE_SERVICE_DIR . '', [ 'global-nginx-proxy' ] ) ) {
EE::error( "There was some error in starting $proxy_type container. Please check logs." );
}
record_global_image_version( $proxy_type );

$certs_dir = EE_ROOT_DIR . '/services/nginx-proxy/certs';
$key_path = $certs_dir . '/default.key';
Expand Down Expand Up @@ -105,12 +106,41 @@ function init_global_container( $service, $container = '', $recreate = false ) {
} else {
\EE_DOCKER::boot_container( $container, $up );
}
record_global_image_version( $container );
return true;
} else {
return false;
}
}

/**
* Records the tag a global service container runs in its image's `options` row, which the image migration reads.
* `up -d` can move a stopped service to the compose file's new tag, which the migration left unrecorded.
*
* @param string $container Global container name.
*/
function record_global_image_version( $container ) {

$image = array_search( $container, EE\Migration\GlobalContainers::get_all_global_images_with_service_name(), true );
$recorded = false === $image ? false : Option::get( $image );
if ( false === $recorded ) {
return;
}

$launch = EE::launch( sprintf( "docker inspect --format '{{.Config.Image}}' %s", escapeshellarg( $container ) ) );
$running = trim( $launch->stdout );
// A custom compose file may run another image: then there is nothing to record.
if ( 0 !== $launch->return_code || 0 !== strpos( $running, "$image:" ) ) {
return;
}

// A `tag@digest` reference records only the tag.
$tag = explode( '@', (string) substr( $running, strlen( $image ) + 1 ), 2 )[0];
if ( '' !== $tag && $recorded !== $tag ) {
Option::set( $image, $tag );
}
}

/**
* Ensures that frontend and backend networks are initialized.
*
Expand Down
Loading