Pull latest image tag, so we can identity it
`docker image ls` doesn't tell us what the latest deployed image is (e.g if we've rolled back). Pull the latest image tag through to the server so we can use it instead.
This commit is contained in:
@@ -2,7 +2,7 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
|
|||||||
desc "boot", "Boot app on servers (or reboot app if already running)"
|
desc "boot", "Boot app on servers (or reboot app if already running)"
|
||||||
def boot
|
def boot
|
||||||
say "Get most recent version available as an image...", :magenta unless options[:version]
|
say "Get most recent version available as an image...", :magenta unless options[:version]
|
||||||
using_version(options[:version] || most_recent_version_available) do |version|
|
using_version(version_or_latest) do |version|
|
||||||
say "Start container with version #{version} using a #{MRSK.config.readiness_delay}s readiness delay (or reboot if already running)...", :magenta
|
say "Start container with version #{version} using a #{MRSK.config.readiness_delay}s readiness delay (or reboot if already running)...", :magenta
|
||||||
|
|
||||||
cli = self
|
cli = self
|
||||||
@@ -70,7 +70,7 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
|
|||||||
|
|
||||||
when options[:interactive]
|
when options[:interactive]
|
||||||
say "Get most recent version available as an image...", :magenta unless options[:version]
|
say "Get most recent version available as an image...", :magenta unless options[:version]
|
||||||
using_version(options[:version] || most_recent_version_available) do |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
|
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.execute_in_new_container_over_ssh(cmd, host: MRSK.primary_host) }
|
||||||
end
|
end
|
||||||
@@ -88,7 +88,7 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
|
|||||||
|
|
||||||
else
|
else
|
||||||
say "Get most recent version available as an image...", :magenta unless options[:version]
|
say "Get most recent version available as an image...", :magenta unless options[:version]
|
||||||
using_version(options[:version] || most_recent_version_available) do |version|
|
using_version(version_or_latest) do |version|
|
||||||
say "Launching command with version #{version} from new container...", :magenta
|
say "Launching command with version #{version} from new container...", :magenta
|
||||||
on(MRSK.hosts) do |host|
|
on(MRSK.hosts) do |host|
|
||||||
execute *MRSK.auditor.record("Executed cmd '#{cmd}' on app version #{version}"), verbosity: :debug
|
execute *MRSK.auditor.record("Executed cmd '#{cmd}' on app version #{version}"), verbosity: :debug
|
||||||
@@ -189,20 +189,13 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def most_recent_version_available(host: MRSK.primary_host)
|
|
||||||
version = nil
|
|
||||||
on(host) { version = capture_with_info(*MRSK.app.most_recent_version_from_available_images).strip }
|
|
||||||
|
|
||||||
if version == "<none>"
|
|
||||||
raise "Most recent image available was not tagged with a version (returned <none>)"
|
|
||||||
else
|
|
||||||
version.presence
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def current_running_version(host: MRSK.primary_host)
|
def current_running_version(host: MRSK.primary_host)
|
||||||
version = nil
|
version = nil
|
||||||
on(host) { version = capture_with_info(*MRSK.app.current_running_version).strip }
|
on(host) { version = capture_with_info(*MRSK.app.current_running_version).strip }
|
||||||
version.presence
|
version.presence
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def version_or_latest
|
||||||
|
options[:version] || "latest"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -87,19 +87,6 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
|||||||
"tail -n 1"
|
"tail -n 1"
|
||||||
end
|
end
|
||||||
|
|
||||||
def most_recent_version_from_available_images
|
|
||||||
pipe \
|
|
||||||
docker(:image, :ls, "--format", '"{{.Tag}}"', config.repository),
|
|
||||||
"head -n 1"
|
|
||||||
end
|
|
||||||
|
|
||||||
def all_versions_from_available_containers
|
|
||||||
pipe \
|
|
||||||
docker(:image, :ls, "--format", '"{{.Tag}}"', config.repository),
|
|
||||||
"head -n 1"
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def list_containers
|
def list_containers
|
||||||
docker :container, :ls, "--all", *filter_args
|
docker :container, :ls, "--all", *filter_args
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class Mrsk::Commands::Builder::Base < Mrsk::Commands::Base
|
|||||||
|
|
||||||
def pull
|
def pull
|
||||||
docker :pull, config.absolute_image
|
docker :pull, config.absolute_image
|
||||||
|
docker :pull, config.latest_image
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_options
|
def build_options
|
||||||
|
|||||||
@@ -28,9 +28,8 @@ class CliAppTest < CliTestCase
|
|||||||
.returns([ :docker, :run ])
|
.returns([ :docker, :run ])
|
||||||
|
|
||||||
run_command("boot").tap do |output|
|
run_command("boot").tap do |output|
|
||||||
assert_match "Rebooting container with same version 999 already deployed", output # Can't start what's already running
|
assert_match "Rebooting container with same version latest already deployed", output # Can't start what's already running
|
||||||
assert_match "docker container ls --all --filter name=app-999 --quiet | xargs docker container rm", output # Stop old running
|
assert_match "docker container ls --all --filter name=app-latest --quiet | xargs docker container rm", output # Remove old container
|
||||||
assert_match "docker container ls --all --filter name=app-999 --quiet | xargs docker container rm", output # Remove old container
|
|
||||||
assert_match "docker run", output # Start new container
|
assert_match "docker run", output # Start new container
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class CliBuildTest < CliTestCase
|
|||||||
test "pull" do
|
test "pull" do
|
||||||
run_command("pull").tap do |output|
|
run_command("pull").tap do |output|
|
||||||
assert_match /docker image rm --force dhh\/app:999/, output
|
assert_match /docker image rm --force dhh\/app:999/, output
|
||||||
assert_match /docker pull dhh\/app:999/, output
|
assert_match /docker pull dhh\/app:latest/, output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -189,12 +189,6 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
new_command.current_running_version.join(" ")
|
new_command.current_running_version.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "most_recent_version_from_available_images" do
|
|
||||||
assert_equal \
|
|
||||||
"docker image ls --format \"{{.Tag}}\" dhh/app | head -n 1",
|
|
||||||
new_command.most_recent_version_from_available_images.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "list_containers" do
|
test "list_containers" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker container ls --all --filter label=service=app",
|
"docker container ls --all --filter label=service=app",
|
||||||
|
|||||||
Reference in New Issue
Block a user