Extract versions that contains dashes

The version extraction assumed that the version is everything after the
last `-` in the container name. This doesn't work if you deploy a
non-MRSK generated version that contains a `-`.

To fix we'll generate the non version prefix and strip it off. In some
places for this to work we need to make sure to pass the role through.

Fixes: https://github.com/mrsked/mrsk/issues/402
This commit is contained in:
Donal McBreen
2023-08-08 14:07:09 +01:00
parent aa89ededde
commit 4dd8208290
5 changed files with 25 additions and 16 deletions

View File

@@ -97,7 +97,7 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
say "Get most recent version available as an image...", :magenta unless options[:version]
using_version(version_or_latest) do |version|
say "Launching interactive command with version #{version} via SSH from new container on #{MRSK.primary_host}...", :magenta
run_locally { exec MRSK.app.execute_in_new_container_over_ssh(cmd, host: MRSK.primary_host) }
run_locally { exec MRSK.app(role: MRSK.primary_host.roles.first).execute_in_new_container_over_ssh(cmd, host: MRSK.primary_host) }
end
when options[:reuse]
@@ -249,7 +249,10 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
desc "version", "Show app version currently running on servers"
def version
on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.current_running_version).strip }
on(MRSK.hosts) do |host|
role = MRSK.roles_on(host).first
puts_by_host host, capture_with_info(*MRSK.app(role: role).current_running_version).strip
end
end
private
@@ -269,7 +272,10 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
def current_running_version(host: MRSK.primary_host)
version = nil
on(host) { version = capture_with_info(*MRSK.app.current_running_version).strip }
on(host) do
role = MRSK.roles_on(host).first
version = capture_with_info(*MRSK.app(role: role).current_running_version).strip
end
version.presence
end

View File

@@ -112,8 +112,7 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
def list_versions(*docker_args, statuses: nil)
pipe \
docker(:ps, *filter_args(statuses: statuses), *docker_args, "--format", '"{{.Names}}"'),
%(grep -oE "\\-[^-]+$"), # Extract SHA from "service-role-dest-SHA"
%(cut -c 2-)
%(while read line; do echo ${line##{service_role_dest}-}; done) # Extract SHA from "service-role-dest-SHA"
end
def list_containers
@@ -160,6 +159,10 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
argumentize "--filter", filters(statuses: statuses)
end
def service_role_dest
[config.service, role, config.destination].compact.join("-")
end
def filters(statuses: nil)
[ "label=service=#{config.service}" ].tap do |filters|
filters << "label=destination=#{config.destination}" if config.destination