Skip to content

Commit

Permalink
Isolate environment configurations (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed Feb 19, 2015
1 parent 50cef89 commit a71529e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 42 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
.project

# gh-pages
site/
node_modules/
bower_components/

# kong
out/
dev/
test/
config.*/
!config.default/
44 changes: 25 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
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

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)
Expand All @@ -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
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 |
Expand All @@ -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 |
| ---------- | ------------------------ | --------------------------------------------------------------------- | ----------------------------------------------------------- |
Expand All @@ -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
[luarocks-url]: https://luarocks.org
20 changes: 6 additions & 14 deletions bin/kong
Original file line number Diff line number Diff line change
Expand Up @@ -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\;\;\"\;"
Expand All @@ -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
Expand All @@ -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)"
Expand Down Expand Up @@ -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"`
;;
Expand All @@ -129,22 +125,18 @@ case "$@" in
start)
start
;;

stop)
stop
;;

migrate)
migrate
;;

restart)
restart
;;

*)
show_help

esac

# End of file
# End of file
File renamed without changes.
File renamed without changes.

0 comments on commit a71529e

Please sign in to comment.