Kong / kong-build-tools

Build tools to package and release Kong
Apache License 2.0
83 stars 72 forks source link

brew install kong/kong/openresty@1.21.4.1 fails #635

Closed orelmaliach closed 1 year ago

orelmaliach commented 1 year ago

I'm trying to run brew install kong/kong/kong (latest version is 3.1.1 at this time). It installs successfully libyaml, coreutils, gmp, pkg-config, rust, openssl@1.1, but fails when installing openresty@1.21.4.1.

I'm running on an M1 Mac (arm64 arch), running OS13.1. I asked my colleague to try installing the same (using M1, with Monterey OS), and kong was installed successfully for him.

There's a warning during the installation attempt (I don't think it's related since my colleague had it as well): /opt/homebrew/Library/Taps/kong/homebrew-kong/Formula/openresty@1.21.4.1.rb:58: warning: conflicting chdir during another chdir block

I've already tried:

  1. Reinstalling/removing all dependencies.
  2. Cleaning homebrew cache.
  3. Installing openresty from openresty/brew - it was successful, but later when trying to install kong, it asked me to remove it: Error: openresty@1.21.4.1 is already installed from openresty/brew! Please brew uninstall openresty@1.21.4.1 first."
  4. Editing the formula to use KONG_BUILD_TOOLS_VERSION 4.40.1 (as looks to be required by https://github.com/Kong/kong/blob/3.1.1/.requirements).
  5. Running with/without VPN.

None of these worked.

In terminal, this is the output: ➜ ~ brew install openresty@1.21.4.1 ==> Fetching kong/kong/openresty@1.21.4.1 ==> Downloading https://github.com/Kong/kong-build-tools/archive/4.33.22.tar.gz Already downloaded: /Users/oelmaliach/Library/Caches/Homebrew/downloads/8c26686f439ddceab9e9adaebceacf2b41b9a360a9c5d531755d9e9a05506837--kong-build-tools-4.33.22.tar.gz ==> Installing openresty@1.21.4.1 from kong/kong /opt/homebrew/Library/Taps/kong/homebrew-kong/Formula/openresty@1.21.4.1.rb:58: warning: conflicting chdir during another chdir block ==> ./kong-ngx-build --prefix /opt/homebrew/Cellar/openresty@1.21.4.1/1.21.4.1 --openresty 1.21.4.1 --openssl 1.1.1q --luarocks 3.9.1 --pcre 8.45 --ssl-provider openssl --atc-router 1.0.1 --resty-events 0.1.3 --resty-lmdb 1.0.0 --resty-websocket 0 Last 15 lines from /Users/oelmaliach/Library/Logs/Homebrew/openresty@1.21.4.1/01.kong-ngx-build: 2023-01-15 16:34:17 +0000

./kong-ngx-build --prefix /opt/homebrew/Cellar/openresty@1.21.4.1/1.21.4.1 --openresty 1.21.4.1 --openssl 1.1.1q --luarocks 3.9.1 --pcre 8.45 --ssl-provider openssl --atc-router 1.0.1 --resty-events 0.1.3 --resty-lmdb 1.0.0 --resty-websocket 0.3.0 -j 10

Do not report this issue to Homebrew/brew or Homebrew/core!

There was no further information in the log file: https://pastebin.com/z4gWxAHq

After further investigation, and running brew install openresty@1.21.4.1 --debug --verbose, I managed to isolate the issue to this script that fails during invocation of canon_path function, on multiple occasions. One example was with the following line: DOWNLOAD_CACHE=`canon_path $DOWNLOAD_CACHE` It failed due to the directory passed as argument (work) not existing, making both realpath and readlink fail.

I've managed to bypass the issue with a naive fix to check if the directory exists and/or is a relative/absolute path. A formal fix would be appreciated.

mikehf7 commented 1 year ago

brew install kong ==> Fetching dependencies for kong/kong/kong: kong/kong/openresty@1.21.4.1 ==> Fetching kong/kong/openresty@1.21.4.1 ==> Downloading https://github.com/Kong/kong-build-tools/archive/4.33.22.tar.gz Already downloaded: /Users/mike/Library/Caches/Homebrew/downloads/8c26686f439ddceab9e9adaebceacf2b41b9a360a9c5d531755d9e9a05506837--kong-build-tools-4.33.22.tar.gz ==> Fetching kong/kong/kong ==> Downloading https://download.konghq.com/gateway-src/kong-3.1.1.tar.gz Already downloaded: /Users/mike/Library/Caches/Homebrew/downloads/24f9c15fcaa7dc824f8f88da62583c91f053625d4f80d25158cc18fee2fb56f9--kong-3.1.1.tar.gz ==> Installing kong from kong/kong ==> Installing dependencies for kong/kong/kong: kong/kong/openresty@1.21.4.1 ==> Installing kong/kong/kong dependency: kong/kong/openresty@1.21.4.1 /opt/homebrew/Library/Taps/kong/homebrew-kong/Formula/openresty@1.21.4.1.rb:58: warning: conflicting chdir during another chdir block ==> ./kong-ngx-build --prefix /opt/homebrew/Cellar/openresty@1.21.4.1/1.21.4.1 --openresty 1.21.4.1 --openssl 1.1.1q --luarocks 3.9.1 --pcre 8.45 --ssl-provider openssl --atc-router 1.0.1 --resty-events 0.1.3 --res Last 15 lines from /Users/mike/Library/Logs/Homebrew/openresty@1.21.4.1/01.kong-ngx-build: 2023-02-01 06:19:12 +0000

./kong-ngx-build --prefix /opt/homebrew/Cellar/openresty@1.21.4.1/1.21.4.1 --openresty 1.21.4.1 --openssl 1.1.1q --luarocks 3.9.1 --pcre 8.45 --ssl-provider openssl --atc-router 1.0.1 --resty-events 0.1.3 --resty-lmdb 1.0.0 --resty-websocket 0.3.0 -j 10

Do not report this issue to Homebrew/brew or Homebrew/core!

mikehf7 commented 1 year ago

Same error

masondelro commented 1 year ago

I've managed to bypass the issue with a naive fix to check if the directory exists and/or is a relative/absolute path. A formal fix would be appreciated.

I am also experiencing this error when running brew install --verbose kong. @orelmaliach -- can you explain your workaround in more detail? I.e., how did you change the canon_path function?

Also AFAICT, the openresty-build-tools repo containing ./kong-ngx-build gets pulled and extracted into a directory contained within private/tmp. With that in mind, how did you make changes that were reflected when you called brew install kong or brew install openresty@1.21.4.1?

orelmaliach commented 1 year ago

Several more of my colleagues faced the exact same issue (all of them running with Mac OS 13.1, not necessarily M1, though). My workaround fixed the problem for all of them, so I decided to share it.

To work around the problem(s), you need to perform the following:

  1. Run brew install kong/kong/kong --debug
  2. When you fail, due to the debug flag, you will get an interactive prompt. You should choose option 5 to open a shell.
  3. Run vi ./kong-ngx-build
  4. REPLACE the canon_path function with the following implementation: canon_path() { if realpath -m -- $1 2>/dev/null >&2; then realpath -m -- $1 elif [[ -f $1 ]]; then readlink -f -- $1 elif [[ $1 = /* ]]; then echo $1 else echo $PWD/$1 fi }
  5. Rerun the SAME command that the brew formula failed on. It should be something like the following (remove backslashes): ./kong-ngx-build --prefix /opt/homebrew/Cellar/openresty@1.21.4.1/1.21.4.1 --openresty 1.21.4.1 --openssl 1.1.1q --luarocks 3.9.1 --pcre 8.45 --ssl-provider openssl --atc-router 1.0.1 --resty-events 0.1.3 --resty-lmdb 1.0.0 --resty-websocket 0.3.0 -j 10
  6. Once the command finished successfully, we need to exit the shell with a return code 0, to indicate to the brew debug mode that we want to continue. To do this, simply run exit 0
  7. You will return to the interactive prompt options. This time, choose option 2 to ignore (since we already ran the command manually). The brew formula will continue running.

IF you encounter another issue later running patch command, it's because of a different issue: https://github.com/Kong/homebrew-kong/issues/209 You can ignore it (option 2), but once the installation finishes successfully, you will need to run the following:

  1. vi $(which kong)
  2. Overwrite the contents of the file with the following: #!/usr/bin/env resty setmetatable(_G, nil) pcall(require, "luarocks.loader") package.cpath = (os.getenv("KONG_LUA_CPATH_OVERRIDE") or "") .. "/opt/homebrew/lib/lua/5.1/?.so;" .. package.cpath package.path = (os.getenv("KONG_LUA_PATH_OVERRIDE") or "") .. "./?.lua;./?/init.lua;" .. "/opt/homebrew/share/lua/5.1/?.lua;/opt/homebrew/share/lua/5.1/?/init.lua;" .. package.path require("kong.cmd.init")(arg)

If this fix worked for you, please give a thumbs up, or reply with any additional/different steps you needed to make.

carlwangx commented 1 year ago

Mac M1 Max: https://github.com/Kong/homebrew-kong/issues/215#issuecomment-1426989955

fffonion commented 1 year ago

kong-build-tools is no longer maintained, we are updating our docs on building Kong from source and also update homebrew tap. please hold for updates : )