Skip to content

Commit

Permalink
Unified nginx and kong configurations
Browse files Browse the repository at this point in the history
kong/yml now contains the nginx configuration as a string, and bin/kong
is responsible for extracting it before running nginx.

config.lua handles anything related to configuration files (creating new
config for environments or extracting the nginx config).
  • Loading branch information
thibaultcha committed Mar 4, 2015
1 parent 9eea522 commit f321e20
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 209 deletions.
47 changes: 19 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
KONG_HOME = `pwd`

# Environment variables (default)
export DIR ?= $(KONG_HOME)/config.dev
export KONG_CONF ?= $(DIR)/kong.yml
export NGINX_CONF ?= $(DIR)/nginx.conf
export DEV_LUA_LIB ?= lua_package_path \"$(KONG_HOME)/src/?.lua\;\;\"\;
export CONF ?= kong.yml
export SILENT_FLAG ?=
export COVERAGE_FLAG ?=

# Tests variables
TESTS_DIR ?= $(KONG_HOME)/config.tests
TESTS_KONG_CONF ?= $(TESTS_DIR)/kong.yml
TESTS_NGINX_CONF ?= $(TESTS_DIR)/nginx.conf
TESTS_CONF ?= kong_TEST.yml
DEVELOPMENT_CONF ?= kong_DEVELOPMENT.yml

.PHONY: install dev clean migrate reset seed drop test coverage run-integration-tests test-web test-proxy test-all

Expand All @@ -25,29 +21,21 @@ install:

dev:
@scripts/dev_rocks.sh
@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.yml $(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.yml $(TESTS_KONG_CONF)

clean:
@rm -rf $(DIR)
@rm -rf $(TESTS_DIR)
@rm -f luacov.*
@scripts/config.lua -k $(KONG_HOME) -e TEST create
@scripts/config.lua -k $(KONG_HOME) -e DEVELOPMENT create
@scripts/db.lua migrate $(DEVELOPMENT_CONF)

migrate:
@scripts/db.lua $(SILENT_FLAG) migrate $(KONG_CONF)
@scripts/db.lua $(SILENT_FLAG) migrate $(CONF)

reset:
@scripts/db.lua $(SILENT_FLAG) reset $(KONG_CONF)
@scripts/db.lua $(SILENT_FLAG) reset $(CONF)

seed:
@scripts/db.lua $(SILENT_FLAG) seed $(KONG_CONF)
@scripts/db.lua $(SILENT_FLAG) seed $(CONF)

drop:
@scripts/db.lua $(SILENT_FLAG) drop $(KONG_CONF)
@scripts/db.lua $(SILENT_FLAG) drop $(CONF)

test:
@busted $(COVERAGE_FLAG) spec/unit
Expand All @@ -56,17 +44,20 @@ coverage:
@rm -f luacov.*
@$(MAKE) test COVERAGE_FLAG=--coverage

clean:
@rm -f luacov.*

lint:
@luacheck kong*.rockspec

run-integration-tests:
@$(MAKE) migrate KONG_CONF=$(TESTS_KONG_CONF)
@bin/kong -c $(TESTS_KONG_CONF) -n $(TESTS_NGINX_CONF) start
@$(MAKE) migrate CONF=$(TESTS_CONF)
@bin/kong -c $(TESTS_CONF) start
@while ! [ `ps aux | grep nginx | grep -c -v grep` -gt 0 ]; do sleep 1; done # Wait until nginx starts
@$(MAKE) seed KONG_CONF=$(TESTS_KONG_CONF)
@busted $(COVERAGE_FLAG) $(FOLDER) || (bin/kong stop; make drop KONG_CONF=$(TESTS_KONG_CONF) SILENT_FLAG=$(SILENT_FLAG); exit 1)
@$(MAKE) seed CONF=$(TESTS_CONF)
@busted $(COVERAGE_FLAG) $(FOLDER) || (bin/kong stop; make drop CONF=$(TESTS_CONF) SILENT_FLAG=$(SILENT_FLAG); exit 1)
@bin/kong stop
@$(MAKE) reset KONG_CONF=$(TESTS_KONG_CONF)
@$(MAKE) reset CONF=$(TESTS_CONF)

test-web:
@$(MAKE) run-integration-tests FOLDER=spec/web SILENT_FLAG=-s
Expand Down
23 changes: 8 additions & 15 deletions bin/kong
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
export KONG_HOME="$(echo $SCRIPT_DIR | sed -e 's/\/[^\/]*$//')"

# Properties
export KONG_CONF=$KONG_HOME/config.default/kong.yml
NGINX_CONF=$KONG_HOME/config.default/nginx.conf
export KONG_CONF=$KONG_HOME/kong.yml
PID=$KONG_HOME/out/nginx.pid

DEV_LUA_LIB="lua_package_path \"$KONG_HOME/src/?.lua\;\;\"\;"

######################
# Utility function #
######################
Expand All @@ -34,16 +31,14 @@ function real_path_func {
fi
}

######################
# Operations #
######################
##############
# Operations #
##############

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/config.default/kong.yml'
\t-n specify the path to a custom Nginx configuration file.
\t default is: '$KONG_HOME/config.default/nginx.conf'
\t default is: '$KONG_HOME/kong.yml'
\t-v output version information and exit
\t-h show the help
\nCommands available:\n
Expand All @@ -65,7 +60,9 @@ function start {
mkdir -p $KONG_HOME/out/logs
touch $KONG_HOME/out/logs/error.log
touch $KONG_HOME/out/logs/access.log
nginx -p $KONG_HOME/out -c $NGINX_CONF
$KONG_HOME/scripts/config.lua -c $KONG_CONF -o $KONG_HOME/out/ nginx
nginx -p $KONG_HOME/out -c $KONG_HOME/out/nginx.conf


if [ $? -eq 0 ]; then
printf "$(tput setaf 2) [OK]\n$(tput sgr 0)"
Expand Down Expand Up @@ -120,9 +117,6 @@ while getopts "h?vc:n:" opt; do
c)
KONG_CONF=$(real_path_func $OPTARG)
;;
n)
NGINX_CONF=$(real_path_func $OPTARG)
;;
esac
done

Expand All @@ -131,7 +125,6 @@ shift $((OPTIND-1))
[ "$1" = "--" ] && shift

check_file_exists $KONG_CONF
check_file_exists $NGINX_CONF

case "$@" in
start)
Expand Down
22 changes: 0 additions & 22 deletions config.default/kong.yml

This file was deleted.

121 changes: 0 additions & 121 deletions config.default/nginx.conf

This file was deleted.

1 change: 1 addition & 0 deletions kong-0.0.1beta-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies = {
"inspect ~> 3.0-1",
"luasocket ~> 2.0.2-5",
"lua_cliargs ~> 2.3-3",
"lua-path ~> 0.2.3-1",
"luafilesystem ~> 1.6.2"
}
build = {
Expand Down
Loading

0 comments on commit f321e20

Please sign in to comment.