-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cli) kong prepare cli command to prepare prefix #2706
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,39 @@ | ||
local prefix_handler = require "kong.cmd.utils.prefix_handler" | ||
local conf_loader = require "kong.conf_loader" | ||
|
||
|
||
local function execute(args) | ||
local conf = assert(conf_loader(args.conf, { | ||
prefix = args.prefix | ||
})) | ||
|
||
local ok, err = prefix_handler.prepare_prefix(conf, args.nginx_conf) | ||
if not ok then | ||
error("could not prepare Kong prefix at " .. conf.prefix .. ": " .. err) | ||
end | ||
end | ||
|
||
|
||
local lapp = [[ | ||
Usage: kong prepare [OPTIONS] | ||
|
||
Prepare the Kong prefix in the configured prefix directory. This command can | ||
be used to start Kong from the nginx binary without using the 'kong start' | ||
command. | ||
|
||
Example usage: | ||
kong migrations up | ||
kong prepare -p /usr/local/kong -c kong.conf | ||
nginx -p /usr/local/kong -c /usr/local/kong/nginx.conf | ||
|
||
Options: | ||
-c,--conf (optional string) configuration file | ||
-p,--prefix (optional string) override prefix directory | ||
--nginx-conf (optional string) custom Nginx configuration template | ||
]] | ||
|
||
|
||
return { | ||
lapp = lapp, | ||
execute = execute, | ||
} |
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,49 @@ | ||
local helpers = require "spec.helpers" | ||
|
||
|
||
local TEST_PREFIX = "servroot_prepared_test" | ||
|
||
|
||
describe("kong prepare", function() | ||
setup(function() | ||
pcall(helpers.dir.rmtree, TEST_PREFIX) | ||
end) | ||
|
||
after_each(function() | ||
pcall(helpers.dir.rmtree, TEST_PREFIX) | ||
end) | ||
|
||
it("prepares a prefix", function() | ||
assert(helpers.kong_exec("prepare -c " .. helpers.test_conf_path, { | ||
prefix = TEST_PREFIX | ||
})) | ||
assert.truthy(helpers.path.exists(TEST_PREFIX)) | ||
|
||
local admin_access_log_path = helpers.path.join(TEST_PREFIX, helpers.test_conf.admin_access_log) | ||
local admin_error_log_path = helpers.path.join(TEST_PREFIX, helpers.test_conf.admin_error_log) | ||
|
||
assert.truthy(helpers.path.exists(admin_access_log_path)) | ||
assert.truthy(helpers.path.exists(admin_error_log_path)) | ||
end) | ||
|
||
it("prepares a prefix from CLI arg option", function() | ||
assert(helpers.kong_exec("prepare -c " .. helpers.test_conf_path .. | ||
" -p " .. TEST_PREFIX)) | ||
assert.truthy(helpers.path.exists(TEST_PREFIX)) | ||
|
||
local admin_access_log_path = helpers.path.join(TEST_PREFIX, helpers.test_conf.admin_access_log) | ||
local admin_error_log_path = helpers.path.join(TEST_PREFIX, helpers.test_conf.admin_error_log) | ||
|
||
assert.truthy(helpers.path.exists(admin_access_log_path)) | ||
assert.truthy(helpers.path.exists(admin_error_log_path)) | ||
end) | ||
|
||
describe("errors", function() | ||
it("on inexistent Kong conf file", function() | ||
local ok, stderr = helpers.kong_exec "prepare --conf foobar.conf" | ||
assert.False(ok) | ||
assert.is_string(stderr) | ||
assert.matches("Error: no file at: foobar.conf", stderr, nil, true) | ||
end) | ||
end) | ||
end) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are missing this
nginx-conf
argument from the command's options?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in last commit.