sous-chefs / homebrew

Development repository for the homebrew cookbook
https://supermarket.chef.io/cookbooks/homebrew
Apache License 2.0
151 stars 136 forks source link

Could not find the "brew" executable in /usr/local/bin or anywhere on the path for arm64(M1) #156

Closed chadjiang closed 2 years ago

chadjiang commented 2 years ago

:speaking_head: Foreword

Tried the latest version 5.3.0 which support arm64 install, but got path issue for brew

:ghost: Brief Description

Tried the latest version 5.3.0 which support arm64 install, but got path issue for brew

:pancakes: Cookbook version

5.3.0

:woman_cook: Chef-Infra Version

17.7.29

:tophat: Platform details

macOS Monterey Version 12.1
Mac mini(M1, 2020)

Steps To Reproduce

just tried the example in the cookbook:

homebrew_cask 'google-chrome'

homebrew_cask "Let's remove google-chrome" do cask_name 'google-chrome' install_cask false action :remove end

:police_car: Expected behavior

got this Error: Running handlers: [2021-12-22T20:34:33-08:00] ERROR: Running exception handlers Running handlers complete [2021-12-22T20:34:33-08:00] ERROR: Exception handlers complete Infra Phase failed. 1 resources updated in 11 seconds [2021-12-22T20:34:34-08:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out [2021-12-22T20:34:34-08:00] FATAL: --------------------------------------------------------------------------------------- [2021-12-22T20:34:34-08:00] FATAL: PLEASE PROVIDE THE CONTENTS OF THE stacktrace.out FILE (above) IF YOU FILE A BUG REPORT [2021-12-22T20:34:34-08:00] FATAL: --------------------------------------------------------------------------------------- [2021-12-22T20:34:34-08:00] FATAL: Chef::Exceptions::CannotDetermineHomebrewOwner: Could not find the "brew" executable in /usr/local/bin or anywhere on the path.

:heavy_plus_sign: Additional context

Add any other context about the problem here. e.g. related issues or existing pull requests.

chadjiang commented 2 years ago

this issue is related to chef client 17.9.18

RockLobster commented 2 years ago

@chadjiang so how did you resolve the issue? Running into it myself using chef client 17.9.26

phirk commented 2 years ago

We're experiencing the same issue, using Chef client 17.9.26, though its release notes mention that it fixes exactly this issue (present in 17.9.18).

The release notes thank @jweyer8 for fixing it. What might we be doing wrong, Jared?

jweyer8 commented 2 years ago

@RockLobster @chadjiang

Running Chef client 17.9.26 seems to have fixed the issue for us.

The homebrew_tap resource was trying to reference the 'full' property which was removed in v17.9.18 #12346. Below is the line that was causing the issue:

shell_out!("#{new_resource.homebrew_path} tap #{new_resource.full ? "--full" : ""} #{new_resource.tap_name} #{new_resource.url || ""}",

The fix was as simple as removing the reference to 'new_resource.full' which was causing the no method error due to the fact that the property was removed (The full property was removed by Chef because the --full option was depreciated by Homebrew).

chadjiang commented 2 years ago

@RockLobster @jweyer8 @phirk

Chef client 17.9.26 fixed --full issue. but the issue i got before I cannot do brew installl package for ARM64 (m1) machine, the brew installation path in the node is /opt/homebrew,

in the node , /opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.26/lib/chef:

resource/homebrew_tap.rb resource/homebrew_cask.rb mixin/homebrew_user.rb. provider/package/homebrew.rb

those file use /usr/local/Homebrew for brew. I have to update them in the node to make installation work.

jweyer8 commented 2 years ago

@chadjiang

Have you tried specifying the install path with the homebrew_path property?

To use your example, would the following fix your issue:

homebrew_cask 'Install Chrome' do cask_name 'google-chrome' homebrew_path '/opt/homebrew/bin/brew' end

chadjiang commented 2 years ago

@jweyer8
ha, good to know. I did not realize this :homebrew_path parameter. Thanks a lot!

jweyer8 commented 2 years ago

@chadjiang No problem!

RockLobster commented 2 years ago

oh, that looks interesting, will try on Monday if that solved our issue!

RockLobster commented 2 years ago

I needed to apply two changes:

  1. even though homebrew got installed, it didn't get added to the path, leading homebrew_user.rb to fail. I fixed it by adding the following lines to my default.rb:
    include_recipe 'homebrew'
    ENV['PATH']="#{ENV['PATH']}:/opt/homebrew/bin:/opt/homebrew/sbin"
  2. Even though it's now part of the path, all homebrew_cask, homebrew_tap require setting homebrew_path.

Note: Just doing 2.) is not enough because homebrew_user.rb will still fail.

RockLobster commented 2 years ago

Weirdly enough, homebrew_package / package does not have a homebrew_path and is working just fine