Merge pull request #11356 from jackorp/vagrant-podman-container-build
Docker provider: catch container name when using podman.
This commit is contained in:
commit
0ca53d9e6e
@ -29,7 +29,16 @@ module VagrantPlugins
|
||||
# from standard docker
|
||||
matches = result.scan(/writing image .+:([0-9a-z]+) done/i).last
|
||||
if !matches
|
||||
matches = result.scan(/Successfully built (.+)$/i).last
|
||||
if podman?
|
||||
# Check for podman format when it is emulating docker CLI.
|
||||
# Podman outputs the full hash of the container on
|
||||
# the last line after a successful build.
|
||||
match = result.split.select { |str| str.match?(/[0-9a-z]{64}/) }.last
|
||||
return match[0..7] unless match.nil?
|
||||
else
|
||||
matches = result.scan(/Successfully built (.+)$/i).last
|
||||
end
|
||||
|
||||
if !matches
|
||||
# This will cause a stack trace in Vagrant, but it is a bug
|
||||
# if this happens anyways.
|
||||
@ -41,6 +50,13 @@ module VagrantPlugins
|
||||
matches[0]
|
||||
end
|
||||
|
||||
# Check if podman emulating docker CLI is enabled.
|
||||
#
|
||||
# @return [Bool]
|
||||
def podman?
|
||||
execute('docker', '--version').include?("podman")
|
||||
end
|
||||
|
||||
def create(params, **opts, &block)
|
||||
image = params.fetch(:image)
|
||||
links = params.fetch(:links)
|
||||
|
||||
@ -155,6 +155,7 @@ describe VagrantPlugins::DockerProvider::Driver do
|
||||
describe '#build' do
|
||||
let(:result) { "Successfully built other_package\nSuccessfully built 1a2b3c4d" }
|
||||
let(:buildkit_result) { "writing image sha256:1a2b3c4d done" }
|
||||
let(:podman_result) { "1a2b3c4d5e6f7g8h9i10j11k12l13m14n16o17p18q19r20s21t22u23v24w25x2" }
|
||||
let(:cid) { "1a2b3c4d" }
|
||||
|
||||
it "builds a container with standard docker" do
|
||||
@ -172,6 +173,32 @@ describe VagrantPlugins::DockerProvider::Driver do
|
||||
|
||||
expect(container_id).to eq(cid)
|
||||
end
|
||||
|
||||
it "builds a container with podman emulating docker CLI" do
|
||||
allow(subject).to receive(:execute).and_return(podman_result)
|
||||
allow(subject).to receive(:podman?).and_return(true)
|
||||
|
||||
container_id = subject.build("/tmp/fakedir")
|
||||
|
||||
expect(container_id).to eq(cid)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#podman?' do
|
||||
let(:emulating_docker_output) { "podman version 1.7.1-dev" }
|
||||
let(:real_docker_output) { "Docker version 1.8.1, build d12ea79" }
|
||||
|
||||
it 'returns false when docker is used' do
|
||||
allow(subject).to receive(:execute).and_return(real_docker_output)
|
||||
|
||||
expect(subject.podman?).to be false
|
||||
end
|
||||
|
||||
it 'returns true when podman is used' do
|
||||
allow(subject).to receive(:execute).and_return(emulating_docker_output)
|
||||
|
||||
expect(subject.podman?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#create' do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user