From ea7cc687f2799cda05ee7dc2e2bafcdc802fe71c Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 23 Mar 2020 09:55:25 -0500 Subject: [PATCH 1/3] Add test for multiple `Successsfully built` messages --- test/unit/plugins/providers/docker/driver_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/plugins/providers/docker/driver_test.rb b/test/unit/plugins/providers/docker/driver_test.rb index 7ae6524ef..4acce8eb1 100644 --- a/test/unit/plugins/providers/docker/driver_test.rb +++ b/test/unit/plugins/providers/docker/driver_test.rb @@ -153,7 +153,7 @@ describe VagrantPlugins::DockerProvider::Driver do describe '#build' do - let(:result) { "Successfully built 1a2b3c4d" } + let(:result) { "Successfully built other_package\nSuccessfully built 1a2b3c4d" } let(:buildkit_result) { "writing image sha256:1a2b3c4d done" } let(:cid) { "1a2b3c4d" } From 380c25a7ae5efdc39a8545397264e102c0b2bb98 Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 23 Mar 2020 10:10:19 -0500 Subject: [PATCH 2/3] Get last image id from docker output --- plugins/providers/docker/driver.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/providers/docker/driver.rb b/plugins/providers/docker/driver.rb index 8932c74a2..ba52c9467 100644 --- a/plugins/providers/docker/driver.rb +++ b/plugins/providers/docker/driver.rb @@ -24,13 +24,13 @@ module VagrantPlugins args << dir opts = {with_stderr: true} result = execute('docker', 'build', *args, opts, &block) - matches = result.match(/Successfully built (?.+)$/i) + matches = result.scan(/Successfully built (?.+)$/i).last if !matches # Check for the new output format 'writing image sha256...' # In this case, docker builtkit is enabled. Its format is different # from standard docker @logger.warn("Could not determine docker container ID. Scanning for buildkit output instead") - matches = result.match(/writing image .+:(?[0-9a-z]+) done/i) + matches = result.scan(/writing image .+:(?[0-9a-z]+) done/i).last if !matches # This will cause a stack trace in Vagrant, but it is a bug # if this happens anyways. @@ -39,7 +39,7 @@ module VagrantPlugins end # Return the matched group `id` - matches[:id] + matches[0] end def create(params, **opts, &block) From 324294993e78c4c3df25357bf554b72912ae0b81 Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 23 Mar 2020 13:38:10 -0500 Subject: [PATCH 3/3] Check for docker buildkit output first When buildkit is enabled docker will write out `writing image ` When buildkit is not enables docker will write out `Successfully builld ` It is more likely that searching for the `writing image` will not clash with build output than when searching for `Successfully built`. eg. when installing python packages with pip, it is common to use the verbage `Successfully built`. --- plugins/providers/docker/driver.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugins/providers/docker/driver.rb b/plugins/providers/docker/driver.rb index ba52c9467..9d8c2b0ff 100644 --- a/plugins/providers/docker/driver.rb +++ b/plugins/providers/docker/driver.rb @@ -24,13 +24,12 @@ module VagrantPlugins args << dir opts = {with_stderr: true} result = execute('docker', 'build', *args, opts, &block) - matches = result.scan(/Successfully built (?.+)$/i).last + # Check for the new output format 'writing image sha256...' + # In this case, docker builtkit is enabled. Its format is different + # from standard docker + matches = result.scan(/writing image .+:([0-9a-z]+) done/i).last if !matches - # Check for the new output format 'writing image sha256...' - # In this case, docker builtkit is enabled. Its format is different - # from standard docker - @logger.warn("Could not determine docker container ID. Scanning for buildkit output instead") - matches = result.scan(/writing image .+:(?[0-9a-z]+) done/i).last + matches = result.scan(/Successfully built (.+)$/i).last if !matches # This will cause a stack trace in Vagrant, but it is a bug # if this happens anyways.