diff --git a/plugins/providers/docker/driver.rb b/plugins/providers/docker/driver.rb index a8ccc47b72e..a994b7d13a5 100644 --- a/plugins/providers/docker/driver.rb +++ b/plugins/providers/docker/driver.rb @@ -36,7 +36,7 @@ def build(dir, **opts, &block) # 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 + 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 diff --git a/test/unit/plugins/providers/docker/driver_test.rb b/test/unit/plugins/providers/docker/driver_test.rb index ce03e584ac0..3c1c7dd9251 100644 --- a/test/unit/plugins/providers/docker/driver_test.rb +++ b/test/unit/plugins/providers/docker/driver_test.rb @@ -217,6 +217,17 @@ expect(container_id).to eq(cid) end + + context "if output contains extra trailing information" do + let(:stdout) { "1a2b3c4d5e6f7g8h9i10j11k12l13m14n16o17p18q19r20s21t22u23v24w25x2\nextra content\n" } + it "builds a container with podman emulating docker CLI" do + allow(subject).to receive(:podman?).and_return(true) + + container_id = subject.build("/tmp/fakedir") + + expect(container_id).to eq(cid) + end + end end end