-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(conf) allow user-specified OpenResty install path (#8412)
Kong detects and decides which nginx binary to use by searching a couple hard-coded paths: * /usr/local/openresty/nginx/sbin * /opt/openresty/nginx/sbin ...before finally exec-ing out to check PATH for a found nginx executable. Therefore, if OpenResty is installed at one of the hard-coded paths, it is always used, leaving the operator no means of specifying any alternative. In most workflows, this is not a problem at all, but during local development and testing it can be limiting. Changing the behavior to search PATH first is one possible way of addressing this, but it is backwards-incompatible in ways that will likely cause headaches for operators, developers, package maintainers, and CI pipeline owners. Therefore, this development quality-of-life-inspired change introduces a new config option (`openresty_path`) that short-circuits the aforementioned behavior. When this value is set, Kong uses it exclusively for locating the nginx binary. Using `openresty_path` instead of something like `nginx_bin` allows us to expand its usage later on (i.e. potentially having a cascading effect on LUA_PATH/LUA_CPATH).
- Loading branch information
Showing
4 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
local signals = require "kong.cmd.utils.nginx_signals" | ||
local pl_path = require "pl.path" | ||
local pl_file = require "pl.file" | ||
local pl_dir = require "pl.dir" | ||
|
||
describe("kong cli utils", function() | ||
|
||
describe("nginx_signals", function() | ||
|
||
describe("find_nginx_bin()", function() | ||
local tmpdir | ||
before_each(function() | ||
tmpdir = pl_path.tmpname() | ||
assert(os.remove(tmpdir)) | ||
end) | ||
|
||
after_each(function() | ||
pcall(pl_dir.rmtree, tmpdir) | ||
end) | ||
|
||
local function fake_nginx_binary(version) | ||
local bin_dir = pl_path.join(tmpdir, "nginx/sbin") | ||
pl_dir.makepath(bin_dir) | ||
|
||
local nginx = pl_path.join(bin_dir, "nginx") | ||
pl_file.write(nginx, string.format( | ||
[[#!/bin/sh | ||
echo 'nginx version: openresty/%s' >&2]], version | ||
)) | ||
|
||
assert(os.execute("chmod +x " .. nginx)) | ||
|
||
return nginx | ||
end | ||
|
||
|
||
it("works with empty/unset input", function() | ||
local bin, err = signals.find_nginx_bin() | ||
assert.is_nil(err) | ||
assert.matches("sbin/nginx", bin) | ||
assert.truthy(pl_path.exists(bin)) | ||
end) | ||
|
||
it("works when openresty_path is unset", function() | ||
local bin, err = signals.find_nginx_bin({}) | ||
assert.is_nil(err) | ||
assert.matches("sbin/nginx", bin) | ||
assert.truthy(pl_path.exists(bin)) | ||
end) | ||
|
||
it("prefers `openresty_path` when supplied", function() | ||
local meta = require "kong.meta" | ||
local version = meta._DEPENDENCIES.nginx[1] | ||
|
||
local nginx = fake_nginx_binary(version) | ||
|
||
local bin, err = signals.find_nginx_bin({ openresty_path = tmpdir }) | ||
|
||
assert.is_nil(err) | ||
assert.equals(nginx, bin) | ||
end) | ||
|
||
it("returns nil+error if a compatible nginx bin is not found in `openresty_path`", function() | ||
fake_nginx_binary("1.0.1") | ||
local bin, err = signals.find_nginx_bin({ openresty_path = tmpdir }) | ||
assert.is_nil(bin) | ||
assert.not_nil(err) | ||
assert.matches("could not find OpenResty", err) | ||
end) | ||
|
||
end) | ||
|
||
end) | ||
|
||
end) |