Skip to content

Commit

Permalink
chore(version) added Kong open source version 3.3.1 artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
kikito authored and Tieske committed Jul 11, 2023
1 parent 93ecc25 commit 640a0f3
Show file tree
Hide file tree
Showing 266 changed files with 50,776 additions and 0 deletions.
170 changes: 170 additions & 0 deletions kong-versions/3.3.1/kong/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
OS := $(shell uname | awk '{print tolower($$0)}')
MACHINE := $(shell uname -m)

DEV_ROCKS = "busted 2.1.2" "busted-htest 1.0.0" "luacheck 1.1.0" "lua-llthreads2 0.1.6" "http 0.4" "ldoc 1.4.6" "luacov 0.15.0"
WIN_SCRIPTS = "bin/busted" "bin/kong" "bin/kong-health"
BUSTED_ARGS ?= -v
TEST_CMD ?= bin/busted $(BUSTED_ARGS)

BUILD_NAME ?= kong-dev

ifeq ($(OS), darwin)
OPENSSL_DIR ?= $(shell brew --prefix)/opt/openssl
GRPCURL_OS ?= osx
YAML_DIR ?= $(shell brew --prefix)/opt/libyaml
else
OPENSSL_DIR ?= /usr
GRPCURL_OS ?= $(OS)
YAML_DIR ?= /usr
endif

ifeq ($(MACHINE), aarch64)
GRPCURL_MACHINE ?= arm64
else
GRPCURL_MACHINE ?= $(MACHINE)
endif

ifeq ($(MACHINE), aarch64)
BAZELISK_MACHINE ?= arm64
else ifeq ($(MACHINE), x86_64)
BAZELISK_MACHINE ?= amd64
else
BAZELISK_MACHINE ?= $(MACHINE)
endif

.PHONY: install dev \
lint test test-integration test-plugins test-all \
pdk-phase-check functional-tests \
fix-windows release

ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
KONG_SOURCE_LOCATION ?= $(ROOT_DIR)
GRPCURL_VERSION ?= 1.8.5
BAZLISK_VERSION ?= 1.16.0
BAZEL := $(shell command -v bazel 2> /dev/null)
VENV = /dev/null # backward compatibility when no venv is built

PACKAGE_TYPE ?= deb

bin/bazel:
curl -s -S -L \
https://github.com/bazelbuild/bazelisk/releases/download/v$(BAZLISK_VERSION)/bazelisk-$(OS)-$(BAZELISK_MACHINE) -o bin/bazel
chmod +x bin/bazel

bin/grpcurl:
@curl -s -S -L \
https://github.com/fullstorydev/grpcurl/releases/download/v$(GRPCURL_VERSION)/grpcurl_$(GRPCURL_VERSION)_$(GRPCURL_OS)_$(GRPCURL_MACHINE).tar.gz | tar xz -C bin;
@rm bin/LICENSE

check-bazel: bin/bazel
ifndef BAZEL
$(eval BAZEL := bin/bazel)
endif

build-kong: check-bazel
$(BAZEL) build //build:kong --verbose_failures --action_env=BUILD_NAME=$(BUILD_NAME)

build-venv: check-bazel
$(eval VENV := bazel-bin/build/$(BUILD_NAME)-venv.sh)

@if [ ! -e bazel-bin/build/$(BUILD_NAME)-venv.sh ]; then \
$(BAZEL) build //build:venv --verbose_failures --action_env=BUILD_NAME=$(BUILD_NAME); \
fi

install-dev-rocks: build-venv
@. $(VENV) ;\
for rock in $(DEV_ROCKS) ; do \
if luarocks list --porcelain $$rock | grep -q "installed" ; then \
echo $$rock already installed, skipping ; \
else \
echo $$rock not found, installing via luarocks... ; \
LIBRARY_PREFIX=$$(pwd)/bazel-bin/build/$(BUILD_NAME)/kong ; \
luarocks install $$rock OPENSSL_DIR=$$LIBRARY_PREFIX CRYPTO_DIR=$$LIBRARY_PREFIX YAML_DIR=$(YAML_DIR) || exit 1; \
fi \
done;

dev: build-venv install-dev-rocks bin/grpcurl

build-release: check-bazel
$(BAZEL) build clean --expunge
$(BAZEL) build //build:kong --verbose_failures --config release

package/deb: check-bazel build-release
$(BAZEL) build --config release :kong_deb

package/apk: check-bazel build-release
$(BAZEL) build --config release :kong_apk

package/rpm: check-bazel build-release
$(BAZEL) build --config release :kong_el8 --action_env=RPM_SIGNING_KEY_FILE --action_env=NFPM_RPM_PASSPHRASE
$(BAZEL) build --config release :kong_el7 --action_env=RPM_SIGNING_KEY_FILE --action_env=NFPM_RPM_PASSPHRASE
$(BAZEL) build --config release :kong_aws2 --action_env=RPM_SIGNING_KEY_FILE --action_env=NFPM_RPM_PASSPHRASE
$(BAZEL) build --config release :kong_aws2022 --action_env=RPM_SIGNING_KEY_FILE --action_env=NFPM_RPM_PASSPHRASE

functional-tests: dev test

install: dev
@$(VENV) luarocks make

clean: check-bazel
$(BAZEL) clean

expunge: check-bazel
$(BAZEL) clean --expunge

lint: dev
@$(VENV) luacheck -q .
@!(grep -R -E -I -n -w '#only|#o' spec && echo "#only or #o tag detected") >&2
@!(grep -R -E -I -n -- '---\s+ONLY' t && echo "--- ONLY block detected") >&2

test: dev
@$(VENV) $(TEST_CMD) spec/01-unit

test-integration: dev
@$(VENV) $(TEST_CMD) spec/02-integration

test-plugins: dev
@$(VENV) $(TEST_CMD) spec/03-plugins

test-all: dev
@$(VENV) $(TEST_CMD) spec/

pdk-phase-checks: dev
rm -f t/phase_checks.stats
rm -f t/phase_checks.report
PDK_PHASE_CHECKS_LUACOV=1 prove -I. t/01*/*/00-phase*.t
luacov -c t/phase_checks.luacov
grep "ngx\\." t/phase_checks.report
grep "check_" t/phase_checks.report

fix-windows:
@for script in $(WIN_SCRIPTS) ; do \
echo Converting Windows file $$script ; \
mv $$script $$script.win ; \
tr -d '\015' <$$script.win >$$script ; \
rm $$script.win ; \
chmod 0755 $$script ; \
done;

# the following targets are kept for backwards compatibility
# dev is renamed to dev-legacy
remove:
$(warning 'remove' target is deprecated, please use `make dev` instead)
-@luarocks remove kong

dependencies: bin/grpcurl
$(warning 'dependencies' target is deprecated, this is now not needed when using `make dev`, but are kept for installation that are not built by Bazel)

for rock in $(DEV_ROCKS) ; do \
if luarocks list --porcelain $$rock | grep -q "installed" ; then \
echo $$rock already installed, skipping ; \
else \
echo $$rock not found, installing via luarocks... ; \
luarocks install $$rock OPENSSL_DIR=$(OPENSSL_DIR) CRYPTO_DIR=$(OPENSSL_DIR) YAML_DIR=$(YAML_DIR) || exit 1; \
fi \
done;

install-legacy:
@luarocks make OPENSSL_DIR=$(OPENSSL_DIR) CRYPTO_DIR=$(OPENSSL_DIR) YAML_DIR=$(YAML_DIR)

dev-legacy: remove install-legacy dependencies
65 changes: 65 additions & 0 deletions kong-versions/3.3.1/kong/bin/busted
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env resty

setmetatable(_G, nil)

local pl_path = require("pl.path")

local cert_path = pl_path.abspath("spec/fixtures/kong_spec.crt")

local DEFAULT_RESTY_FLAGS=string.format(" -c 4096 --http-conf 'lua_ssl_trusted_certificate %s;' ", cert_path)

if not os.getenv("KONG_BUSTED_RESPAWNED") then
-- initial run, so go update the environment
local script = {}
for line in io.popen("set"):lines() do
local ktvar, val = line:match("^KONG_TEST_([^=]*)=(.*)")
if ktvar then
-- reinserted KONG_TEST_xxx as KONG_xxx; append
table.insert(script, "export KONG_" .. ktvar .. "=" ..val)
end

local var = line:match("^(KONG_[^=]*)")
local var_for_spec = line:match("^(KONG_SPEC_[^=]*)")
if var and not var_for_spec then
-- remove existing KONG_xxx and KONG_TEST_xxx variables; prepend
table.insert(script, 1, "unset " .. var)
end
end
-- add cli recursion detection
table.insert(script, "export KONG_BUSTED_RESPAWNED=1")

-- rebuild the invoked commandline, while inserting extra resty-flags
local resty_flags = DEFAULT_RESTY_FLAGS
local cmd = { "exec", "/usr/bin/env", "resty" }
local cmd_prefix_count = #cmd
for i = 0, #arg do
if arg[i]:sub(1, 12) == "RESTY_FLAGS=" then
resty_flags = arg[i]:sub(13, -1)

else
table.insert(cmd, "'" .. arg[i] .. "'")
end
end

if resty_flags then
table.insert(cmd, cmd_prefix_count+1, resty_flags)
end

table.insert(script, table.concat(cmd, " "))

-- recurse cli command, with proper variables (un)set for clean testing
local _, _, rc = os.execute(table.concat(script, "; "))
os.exit(rc)
end

pcall(require, "luarocks.loader")

require("kong.globalpatches")({
cli = true,
rbusted = true
})

-- Busted command-line runner
require 'busted.runner'({ standalone = false })

-- vim: set ft=lua ts=2 sw=2 sts=2 et :
11 changes: 11 additions & 0 deletions kong-versions/3.3.1/kong/bin/kong
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env resty

setmetatable(_G, nil)

pcall(require, "luarocks.loader")

package.path = (os.getenv("KONG_LUA_PATH_OVERRIDE") or "") .. "./?.lua;./?/init.lua;" .. package.path

require("kong.cmd.init")(arg)

-- vim: set ft=lua ts=2 sw=2 sts=2 et :
79 changes: 79 additions & 0 deletions kong-versions/3.3.1/kong/bin/kong-health
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env resty

setmetatable(_G, nil)
package.path = (os.getenv("KONG_LUA_PATH_OVERRIDE") or "") .. "./?.lua;./?/init.lua;" .. package.path

local kill = require "kong.cmd.utils.kill"
local kong_default_conf = require "kong.templates.kong_defaults"
local pl_app = require "pl.lapp"
local pl_config = require "pl.config"
local pl_path = require "pl.path"
local pl_stringio = require "pl.stringio"

local KONG_DEFAULT_PREFIX = "/usr/local/kong"


local function get_kong_prefix()
local prefix = os.getenv("KONG_PREFIX")

if not prefix then
local s = pl_stringio.open(kong_default_conf)
local defaults = pl_config.read(s, {
smart = false,
list_delim = "_blank_" -- mandatory but we want to ignore it
})
s:close()
if defaults then
prefix = defaults.prefix
end

end

return prefix or KONG_DEFAULT_PREFIX
end


local function execute(args)
local prefix = args.prefix or get_kong_prefix(args)
assert(pl_path.exists(prefix), "no such prefix: " .. prefix)

local kong_env = pl_path.join(prefix, ".kong_env")
assert(pl_path.exists(kong_env), "Kong is not running at " .. prefix)

print("")
local pid_file = pl_path.join(prefix, "pids", "nginx.pid")
kill.is_running(pid_file)
assert(kill.is_running(pid_file), "Kong is not running at " .. prefix)
print("Kong is healthy at ", prefix)
end


local lapp = [[
Usage: kong-health [OPTIONS]
Check if the necessary services are running for this node.
Options:
-p,--prefix (optional string) prefix at which Kong should be running
--v verbose
--vv debug
]]

local function run(args)
args = pl_app(lapp)
xpcall(function() execute(args) end, function(err)
if not (args.v or args.vv) then
err = err:match "^.-:.-:.(.*)$"
io.stderr:write("Error: " .. err .. "\n")
io.stderr:write("\n Run with --v (verbose) or --vv (debug) for more details\n")
else
local trace = debug.traceback(err, 2)
io.stderr:write("Error: \n")
io.stderr:write(trace .. "\n")
end
pl_app.quit(nil, true)
end)
end


run(arg)

-- vim: set ft=lua ts=2 sw=2 sts=2 et :
31 changes: 31 additions & 0 deletions kong-versions/3.3.1/kong/spec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Test helpers for Kong (integration) tests
=========================================

To generate the documentation run the following command in the Kong source tree:

```
# install ldoc using LuaRocks
luarocks install ldoc
# generate and open the docs
cd spec && ldoc . && open docs/index.html && cd ..
```

## Environment variables

When testing, Kong will ignore the `KONG_xxx` environment variables that are
usually used to configure it. This is to make sure that the tests run deterministically.
If this behaviour needs to be overridden, the `KONG_TEST_xxx`
version of the variable can be used, which will be respected by the Kong test
instance.

To prevent the test helpers from cleaning the Kong working directory, the
variable `KONG_TEST_DONT_CLEAN` can be set.
This comes in handy when inspecting the logs after the tests complete.

When testing with Redis, the environment variable `KONG_SPEC_TEST_REDIS_HOST` can be
used to specify where the Redis server can be found. If not specified, it will default
to `127.0.0.1`. This setting is available to tests via `helpers.redis_host`.

The configuration file to be used can be set with `KONG_SPEC_TEST_CONF_PATH`. It can be
accessed via helpers as `helpers.test_conf_path`.
11 changes: 11 additions & 0 deletions kong-versions/3.3.1/kong/spec/config.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
project='Kong test helpers'
title='Kong test framework'
description='Test helper functions for Kong (integration) testing'
format='markdown'
file={'./helpers.lua','./helpers'}
dir='docs'
readme='README.md'
sort=true
sort_modules=true
style='./'
no_space_before_args=true
Loading

0 comments on commit 640a0f3

Please sign in to comment.