Skip to content

Commit

Permalink
Merge pull request #13475 from hashicorp/container-id-matching
Browse files Browse the repository at this point in the history
Properly match container ID when trailing content exists
  • Loading branch information
chrisroberts committed Jul 11, 2024
2 parents b875d84 + 12df089 commit 22aad2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/providers/docker/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/unit/plugins/providers/docker/driver_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 22aad2b

Please sign in to comment.