diff --git a/.gitignore b/.gitignore index 4bba038d617..5b86303e722 100644 --- a/.gitignore +++ b/.gitignore @@ -4,10 +4,11 @@ .project # gh-pages +site/ node_modules/ bower_components/ # kong out/ -dev/ -test/ +config.*/ +!config.default/ diff --git a/Makefile b/Makefile index 10dead6f23b..7de9ae33fb5 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,14 @@ KONG_HOME = `pwd` -# Dev environment variables -export DEV_DIR ?= $(KONG_HOME)/dev -export TEST_DIR ?= $(KONG_HOME)/test -export KONG_CONF ?= $(DEV_DIR)/kong-dev.yaml +# Environment variables (default) +export DIR ?= $(KONG_HOME)/config.dev +export KONG_CONF ?= $(DIR)/kong.yaml +export NGINX_CONF ?= $(DIR)/nginx.conf export DEV_LUA_LIB ?= lua_package_path \"$(KONG_HOME)/src/?.lua\;\;\"\; +# Tests variables +TESTS_DIR ?= $(KONG_HOME)/config.tests +TESTS_KONG_CONF ?= $(TESTS_DIR)/kong.yaml +TESTS_NGINX_CONF ?= $(TESTS_DIR)/nginx.conf .PHONY: install dev clean reset seed drop test test-integration test-web test-proxy test-all @@ -12,12 +16,16 @@ install: @luarocks make kong-*.rockspec PCRE_LIBDIR=$(dirname `find / -type f -name "libpcre.so*" -print -quit`) OPENSSL_LIBDIR=$(dirname `find / -type f -name "libssl.so*" -print -quit`) dev: - @mkdir -p $(DEV_DIR) - @sed -e "s@lua_package_path.*;@$(DEV_LUA_LIB)@g" $(KONG_HOME)/conf/nginx.conf > $(DEV_DIR)/nginx-dev.conf - @cp $(KONG_HOME)/conf/kong.yaml $(DEV_DIR)/kong-dev.yaml + @mkdir -p $(DIR) + @sed -e "s@lua_package_path.*;@$(DEV_LUA_LIB)@g" $(KONG_HOME)/config.default/nginx.conf > $(NGINX_CONF) + @cp $(KONG_HOME)/config.default/kong.yaml $(KONG_CONF) + @mkdir -p $(TESTS_DIR) + @sed -e "s@lua_package_path.*;@$(DEV_LUA_LIB)@g" $(KONG_HOME)/config.default/nginx.conf > $(TESTS_NGINX_CONF) + @cp $(KONG_HOME)/config.default/kong.yaml $(TESTS_KONG_CONF) clean: - @rm -rf $(DEV_DIR) + @rm -rf $(DIR) + @rm -rf $(TESTS_DIR) reset: @scripts/migrate reset --conf=$(KONG_CONF) @@ -31,21 +39,19 @@ drop: test: @busted spec/unit -test-integration: - @$(MAKE) dev DEV_DIR=$(TEST_DIR) - @bin/kong -c $(TEST_DIR)/kong-dev.yaml -n $(TEST_DIR)/nginx-dev.conf start > /dev/null - @bin/kong migrate > /dev/null - @$(MAKE) seed > /dev/null - @busted $(FOLDER) || (bin/kong stop > /dev/null;make drop > /dev/null;make clean DEV_DIR=$(TEST_DIR); exit 1) +run-integration-tests: + @bin/kong -c $(TESTS_KONG_CONF) migrate > /dev/null + @bin/kong -c $(TESTS_KONG_CONF) -n $(TESTS_NGINX_CONF) start > /dev/null + @$(MAKE) seed KONG_CONF=$(TESTS_KONG_CONF) > /dev/null + @busted $(FOLDER) || (bin/kong stop > /dev/null; make drop KONG_CONF=$(TESTS_KONG_CONF) > /dev/null; exit 1) @bin/kong stop > /dev/null - @$(MAKE) drop > /dev/null - @$(MAKE) clean DEV_DIR=$(TEST_DIR) + @$(MAKE) reset KONG_CONF=$(TESTS_KONG_CONF) > /dev/null test-web: - @$(MAKE) test-integration FOLDER=spec/web + @$(MAKE) run-integration-tests FOLDER=spec/web test-proxy: - @$(MAKE) test-integration FOLDER=spec/proxy + @$(MAKE) run-integration-tests FOLDER=spec/proxy test-all: - @$(MAKE) test-integration FOLDER=spec/ + @$(MAKE) run-integration-tests FOLDER=spec diff --git a/README.md b/README.md index 6046a975d34..8788fac868d 100644 --- a/README.md +++ b/README.md @@ -45,12 +45,25 @@ Dee all the available options, with `kong -h`. ## Development -Running Kong for development requires two steps: +Running Kong for development requires you to run: -* Execute `make dev`. -* Execute `kong -c dev/kong-dev.conf -n dev/nginx-dev.conf` +``` +make dev +``` + +This will create your environment configuration files (`dev` and `tests`). Setup your database access for each of these enviroments (be careful about keyspaces, since Kong already uses `kong` and unit tests already use `kong_tests`). + +- Run the tests: + +``` +make test-all +``` + +- Run it: -The `make dev` command will create a git-ignored `dev` folder with both a copy of Kong and the nginx configuration. This will prevent to accidentally push to master development configuration files. +``` +kong -c config.dev/kong.yaml -n config.dev/nginx.conf +``` #### Makefile @@ -59,7 +72,7 @@ When developing, use the `Makefile` for doing the following operations: | Name | Description | | ------------ | --------------------------------------------------------------------------------------------------- | | `install` | Install the Kong luarock globally | -| `dev` | Duplicates the default configuration in a .gitignored `dev` folder | +| `dev` | Setup your development enviroment (creates `dev` and `tests` configurations) | | `clean` | Cleans the development environment | | `reset` | Reset your database schema according to the development Kong config inside the `dev` folder | | `seed` | Seed your database according to the development Kong config inside the `dev` folder | @@ -71,7 +84,7 @@ When developing, use the `Makefile` for doing the following operations: #### Scripts -Those script provide handy feature while developing Kong: +Those script provide handy features while developing Kong: | Name | Commands | Description | Arguments | | ---------- | ------------------------ | --------------------------------------------------------------------- | ----------------------------------------------------------- | @@ -88,4 +101,4 @@ Those script provide handy feature while developing Kong: [travis-url]: https://travis-ci.org/Mashape/kong [travis-image]: https://img.shields.io/travis/Mashape/kong.svg?style=flat -[luarocks-url]: https://luarocks.org \ No newline at end of file +[luarocks-url]: https://luarocks.org diff --git a/bin/kong b/bin/kong index 5e39c8b137a..b9c37a7f03e 100755 --- a/bin/kong +++ b/bin/kong @@ -4,11 +4,9 @@ SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" KONG_HOME="$(echo $SCRIPT_DIR | sed -e 's/\/[^\/]*$//')" -NGINX_BIN=/usr/local/openresty/nginx/sbin/nginx - # Properties -export KONG_CONF=$KONG_HOME/conf/kong.yaml -NGINX_CONF=$KONG_HOME/conf/nginx.conf +export KONG_CONF=$KONG_HOME/config.default/kong.yaml +NGINX_CONF=$KONG_HOME/config.default/nginx.conf PID=$KONG_HOME/out/nginx.pid DEV_LUA_LIB="lua_package_path \"$KONG_HOME/src/?.lua\;\;\"\;" @@ -31,9 +29,9 @@ function check_file_exists { function show_help { printf "Usage: kong [OPTION]... {start|stop|restart|migrate}\n \t-c specify the path to a custom Kong configuration file -\t default is: '$KONG_HOME/conf/kong.yaml' +\t default is: '$KONG_HOME/config.default/kong.yaml' \t-n specify the path to a custom Nginx configuration file. -\t default is: '$KONG_HOME/conf/nginx.conf' +\t default is: '$KONG_HOME/config.default/nginx.conf' \t-v output version information and exit \t-h show the help \nCommands available:\n @@ -55,7 +53,7 @@ function start { mkdir -p $KONG_HOME/out/logs touch $KONG_HOME/out/logs/error.log touch $KONG_HOME/out/logs/access.log - $NGINX_BIN -p $KONG_HOME/out -c $NGINX_CONF + nginx -p $KONG_HOME/out -c $NGINX_CONF if [ $? -eq 0 ]; then printf "$(tput setaf 2) [OK]\n$(tput sgr 0)" @@ -104,11 +102,9 @@ while getopts "h?vc:n:" opt; do show_help exit 0 ;; - v) show_version exit 0 ;; - c) KONG_CONF=`realpath "$OPTARG"` ;; @@ -129,22 +125,18 @@ case "$@" in start) start ;; - stop) stop ;; - migrate) migrate ;; - restart) restart ;; - *) show_help esac -# End of file \ No newline at end of file +# End of file diff --git a/conf/kong.yaml b/config.default/kong.yaml similarity index 100% rename from conf/kong.yaml rename to config.default/kong.yaml diff --git a/conf/nginx.conf b/config.default/nginx.conf similarity index 100% rename from conf/nginx.conf rename to config.default/nginx.conf