Merge pull request #11461 from soapy1/get-docker-image-id

Get correct docker image from build output
This commit is contained in:
Sophia Castellarin 2020-03-24 09:27:20 -05:00 committed by GitHub
commit 2dadeb3ee5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 8 deletions

View File

@ -24,13 +24,12 @@ module VagrantPlugins
args << dir
opts = {with_stderr: true}
result = execute('docker', 'build', *args, opts, &block)
matches = result.match(/Successfully built (?<id>.+)$/i)
# 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.match(/writing image .+:(?<id>[0-9a-z]+) done/i)
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.
@ -39,7 +38,7 @@ module VagrantPlugins
end
# Return the matched group `id`
matches[:id]
matches[0]
end
def create(params, **opts, &block)

View File

@ -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" }