Skip to content

Commit

Permalink
Detect new Virtualization framework under macOS (#801)
Browse files Browse the repository at this point in the history
Check com.docker.virtualization process name in .docker_for_mac? for new Virtualization framework
  • Loading branch information
chloerei authored May 6, 2022
1 parent 4610fe9 commit 84fe0b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/docker-sync/dependencies/docker_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ module Driver
def self.docker_for_mac?
return false unless Environment.mac?
return @docker_for_mac if defined? @docker_for_mac
@docker_for_mac = Environment.system('pgrep -q com.docker.hyperkit')

# com.docker.hyperkit for old virtualization engine
# com.docker.virtualization for new virtualization engine
# see https://docs.docker.com/desktop/mac/#enable-the-new-apple-virtualization-framework
@docker_for_mac = Environment.system('pgrep -q com.docker.hyperkit') || Environment.system('pgrep -q com.docker.virtualization')
end

def self.docker_toolbox?
Expand Down
9 changes: 9 additions & 0 deletions spec/lib/docker-sync/dependencies/docker_driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
expect(DockerSync::Environment).to have_received(:system).with('pgrep -q com.docker.hyperkit')
end

it 'checks if Docker is running in Virtualization' do
allow(DockerSync::Environment).to receive(:system).with('pgrep -q com.docker.hyperkit').and_return(false)
allow(DockerSync::Environment).to receive(:system).with('pgrep -q com.docker.virtualization').and_return(true)

is_expected.to be true
expect(DockerSync::Environment).to have_received(:system).with('pgrep -q com.docker.hyperkit')
expect(DockerSync::Environment).to have_received(:system).with('pgrep -q com.docker.virtualization')
end

it 'is memoized' do
expect { 1.times { described_class.docker_for_mac? } }.to change { described_class.instance_variable_defined?(:@docker_for_mac) }

Expand Down

0 comments on commit 84fe0b8

Please sign in to comment.