@@ -59,31 +59,24 @@ def self.context_rm(name, user, group)
5959 end
6060
6161 # buildkits
62- def self . buildx_ls ( home )
63- # Currently the output of `docker buildx ls --format ls` is essentially
64- # unparseable in an automated way. Work is being done to remedy this but
65- # doesn't seem like it will land anytime soon, so instead look where the
66- # config files are stored in ~/.docker/buildx
67- # https://github.com/docker/buildx/pull/830
68- buildx_instances_path = ::File . join ( home , '.docker/buildx/instances' )
69- config_map = { }
70- return config_map unless Dir . exist? ( buildx_instances_path )
71- Dir . foreach ( buildx_instances_path ) do |filename |
72- next if [ '.' , '..' ] . include? ( filename )
73-
74- file_path = ::File . join ( buildx_instances_path , filename )
75- if ::File . file? ( file_path )
76- begin
77- json_content = ::File . read ( file_path )
78- config_map [ filename ] = JSON . parse ( json_content )
79- rescue JSON ::ParserError => e
80- puts "Error parsing JSON in file #{ filename } : #{ e . message } "
81- rescue StandardError => e
82- puts "Error reading file #{ filename } : #{ e . message } "
83- end
84- end
62+ def self . buildx_ls ( user , group )
63+ # https://github.com/docker/buildx/pull/1787
64+ # https://github.com/docker/buildx/pull/2138
65+ cmd = Mixlib ::ShellOut . new (
66+ 'docker buildx ls --no-trunc --format json' ,
67+ login : true ,
68+ user : user ,
69+ group : group ,
70+ ) . run_command
71+ cmd . error!
72+ builder_instances = [ ]
73+ # `docker buildx ls` outputs multiple JSON objects, each on a new line.
74+ # So we need to parse the output line by line and store each in an array
75+ cmd . stdout . each_line do |line |
76+ builder_instance = JSON . parse ( line )
77+ builder_instances . push ( builder_instance )
8578 end
86- config_map
79+ builder_instances
8780 end
8881
8982 def self . buildx_create_command ( name , config )
0 commit comments