Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Mashape/kong
Browse files Browse the repository at this point in the history
# By thibaultCha (6) and Ahmad Nassri (1)
# Via thibaultCha (2) and Thibault Charbonnier (1)
* 'master' of github.com:Mashape/kong:
  Use a .luacov instead of relying on the Makefile
  Linting modules
  Debian installation instructions
  README: add coveralls badge
  Revert "adding os declaration"
  adding os declaration
  Linting, coverage, coveralls and dev rocks
  • Loading branch information
rainum committed Mar 2, 2015
2 parents d83d9a6 + c8330ce commit 2e05e88
Show file tree
Hide file tree
Showing 23 changed files with 242 additions and 105 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ bower_components/
out/
config.*/
!config.default/

# luacov
luacov.*
2 changes: 2 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
unused_args = false
globals = {"ngx", "dao", "utils", "app", "configuration"}
48 changes: 48 additions & 0 deletions .luacov
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--- Global configuration file. Copy, customize and store in your
-- project folder as '.luacov' for project specific configuration
-- @class module
-- @name luacov.defaults
return {
-- default filename to load for config options if not provided
-- only has effect in 'luacov.defaults.lua'
['configfile'] = '.luacov',

-- filename to store stats collected
['statsfile'] = 'luacov.stats.out',

-- filename to store report
['reportfile'] = 'luacov.report.out',

-- Run reporter on completion? (won't work for ticks)
runreport = true,

-- Delete stats file after reporting?
deletestats = true,

-- Patterns for files to include when reporting
-- all will be included if nothing is listed
-- (exclude overrules include, do not include
-- the .lua extension)
['include'] = {
'kong'
},

-- Patterns for files to exclude when reporting
-- all will be included if nothing is listed
-- (exclude overrules include, do not include
-- the .lua extension)
['exclude'] = {
'luacov$',
'luacov.reporter$',
'luacov.defaults$',
'luacov.runner$',
'luacov.stats$',
'luacov.tick$',
'ansicolors$',
'copas$',
'coxpcall$',
'mediator$',
'moonscript.*$',
'socket$',
}
}
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ before_install:

install:
- sudo make install
- make dev
- sudo make dev

script: "make run-integration-tests FOLDER=spec"
script: "make run-integration-tests COVERAGE_FLAG=--coverage FOLDER=spec"

after_success:
- luacov-coveralls -i kong
86 changes: 70 additions & 16 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,61 +14,115 @@ Kong can run in [Docker][docker-url]. Image and instructions are on [mashape/doc

#### Linux

> To write
##### Debian

We need Lua 5.1 and luarocks (it's 2.0.0 but it'll do it):

```
apt-get install lua5.1
```

Install luarocks:

```
wget http://luarocks.org/releases/luarocks-2.2.0.tar.gz
tar xzf luarocks-2.2.0.tar.gz
cd luarocks-2.2.0
./configure
make build
sudo make install
```

Install openresty prerequisites:

```
apt-get install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl make
```

Install openresty:

```
wget http://openresty.org/download/ngx_openresty-1.7.7.2.tar.gz
tar xzf ngx_openresty-1.7.7.2.tar.gz
cd ngx_openresty-1.7.7.2/
./configure
make
sudo make install
```

Add nginx to your `$PATH`:

```
export PATH=$PATH:/usr/local/openresty/nginx/sbin
```

If you whish to run Cassandra locally, install it following the [Datastax instructions](http://www.datastax.com/documentation/cassandra/2.0/cassandra/install/installDeb_t.html) or using our [Docker image][docker-kong-url].

Finally, install Kong. Download [the latest release][kong-latest-url] and execute:

```
sudo make install
```

Now follow the "Usage" section of the README to start Kong.

#### OS X

##### With Homebrew

If you don't have Lua 5.1 installed:

```bash
```
brew install lua51
ln /usr/local/bin/lua-5.1 /usr/local/bin/lua # alias lua-5.1 to lua (required for kong scripts)
ln /usr/local/bin/lua5.1 /usr/local/bin/lua # alias lua5.1 to lua (required for kong scripts)
```

We'll need Luarocks for Lua 5.1. The official Luarocks recipe only supports 5.2 now, so we'll use a custom recipe:
We'll need luarocks 2.2.0 for Lua 5.1. The official Luarocks recipe only supports 5.2 now, so we'll use a custom recipe:

```bash
```
brew tap naartjie/luajit
brew install naartjie/luajit/luarocks-luajit --with-lua51
```

Now, let's intall openresty:
Install openresty prerequisites:

```bash
```
brew install pcre openssl
```

Now, let's install openresty (it's 1.7.4.1, a new recipe would be welcomed):

```
brew tap killercup/openresty
brew install ngx_openresty
ln /usr/local/bin/openresty /usr/local/bin/nginx # alias openresty to nginx (required for kong scripts)
```

If you wish to run Cassandra locally (you can also use our [Docker image](https://github.com/Mashape/docker-cassandra)):
If you wish to run Cassandra locally (you can also use our [Docker image][docker-kong-url]):

```bash
```
brew install cassandra
# to start cassandra, just run `cassandra`
```

Other dependencies:
Finally, install Kong. Download [the latest release][kong-latest-url] and execute:

```bash
brew install pcre openssl
```

Finally, install Kong:

```bash
sudo make install
```

Now follow the "Usage" section of the README to start Kong.

##### Raw OS X

> To write
[docker-url]: https://www.docker.com/
[docker-kong-url]: https://github.com/Mashape/docker-kong
[docker-cassandra-url]: https://github.com/Mashape/docker-cassandra
[lua-install-url]: http://www.lua.org/download.html
[luarocks-url]: https://luarocks.org
[cassandra-url]: http://cassandra.apache.org/
[pcre-url]: http://www.pcre.org/
[openssl-url]: https://www.openssl.org/
[kong-latest-url]: https://github.com/Mashape/kong/releases
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ export KONG_CONF ?= $(DIR)/kong.yml
export NGINX_CONF ?= $(DIR)/nginx.conf
export DEV_LUA_LIB ?= lua_package_path \"$(KONG_HOME)/src/?.lua\;\;\"\;
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

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

install:
@echo "Please wait, this process could take some time.."
Expand All @@ -24,6 +25,7 @@ install:
fi

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)
Expand All @@ -34,6 +36,7 @@ dev:
clean:
@rm -rf $(DIR)
@rm -rf $(TESTS_DIR)
@rm -f luacov.*

migrate:
@scripts/db.lua $(SILENT_FLAG) migrate $(KONG_CONF)
Expand All @@ -48,14 +51,21 @@ drop:
@scripts/db.lua $(SILENT_FLAG) drop $(KONG_CONF)

test:
@busted spec/unit
@busted $(COVERAGE_FLAG) spec/unit

coverage:
@rm -f luacov.*
@$(MAKE) test COVERAGE_FLAG=--coverage

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
@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 $(FOLDER) || (bin/kong stop; make drop KONG_CONF=$(TESTS_KONG_CONF) SILENT_FLAG=$(SILENT_FLAG); exit 1)
@busted $(COVERAGE_FLAG) $(FOLDER) || (bin/kong stop; make drop KONG_CONF=$(TESTS_KONG_CONF) SILENT_FLAG=$(SILENT_FLAG); exit 1)
@bin/kong stop
@$(MAKE) reset KONG_CONF=$(TESTS_KONG_CONF)

Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Kong

[![Build Status][travis-image]][travis-url] [![Gitter][gitter-image]][gitter-url]
[![Build Status][travis-badge]][travis-url] [![Coverage Status][coveralls-badge]][coveralls-url] [![Gitter][gitter-badge]][gitter-url]

Kong is a scalable and customizable API Management Layer built on top of nginx.

Expand Down Expand Up @@ -43,7 +43,7 @@ Running Kong for development requires you to run:
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`).
This will install development dependencies and 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:

Expand All @@ -64,12 +64,14 @@ When developing, use the `Makefile` for doing the following operations:
| Name | Description |
| ------------ | --------------------------------------------------------------------------------------------------- |
| `install` | Install the Kong luarock globally |
| `dev` | Setup your development enviroment (creates `config.dev` and `config.tests` configurations) |
| `dev` | Setup your development enviroment (install dev deps and creates `config.dev` and `config.tests`) |
| `clean` | Clean the development environment |
| `migrate` | Migrate your database schema according to the development Kong config inside `config.dev` |
| `reset` | Reset your database schema according to the development Kong config inside `config.dev` |
| `seed` | Seed your database according to the development Kong config inside `config.dev` |
| `drop` | Drop your database according to the development Kong config inside `config.dev` |
| `lint` | Lint Lua in `src/` |
| `coverage` | Run unit tests + coverage report (only unit-tested modules) |
| `test` | Run the unit tests |
| `test-proxy` | Run the proxy integration tests |
| `test-web` | Run the web integration tests |
Expand Down Expand Up @@ -102,6 +104,8 @@ scripts/db.lua drop
```

[travis-url]: https://travis-ci.org/Mashape/kong
[travis-image]: https://img.shields.io/travis/Mashape/kong.svg?style=flat
[travis-badge]: https://img.shields.io/travis/Mashape/kong.svg?style=flat
[coveralls-url]: https://coveralls.io/r/Mashape/kong?branch=master
[coveralls-badge]: https://coveralls.io/repos/Mashape/kong/badge.svg?branch=master
[gitter-url]: https://gitter.im/Mashape/kong?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
[gitter-image]: https://badges.gitter.im/Join%20Chat.svg
[gitter-badge]: https://badges.gitter.im/Join%20Chat.svg
4 changes: 1 addition & 3 deletions kong-0.0.1beta-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ dependencies = {
"stringy ~> 0.2-1",
"inspect ~> 3.0-1",
"luasocket ~> 2.0.2-5",

"busted ~> 2.0.rc6-0",
"lua_cliargs ~> 2.3-3",
"luafilesystem ~> 1.6.2"
}
Expand All @@ -39,7 +37,7 @@ build = {
["kong"] = "src/main.lua",
["classic"] = "src/classic.lua",

["kong.constants"] = "src/constants.lua",
["kong.constants"] = "src/kong/constants.lua",

["kong.tools.utils"] = "src/kong/tools/utils.lua",
["kong.tools.faker"] = "src/kong/tools/faker.lua",
Expand Down
6 changes: 4 additions & 2 deletions scripts/db.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ elseif args.COMMAND == "reset" then

elseif args.COMMAND == "seed" then

local err

-- Drop if exists
local err = dao:drop()
err = dao:drop()
if err then
logger:error(err)
end

local err = dao:prepare()
err = dao:prepare()
if err then
logger:error(err)
end
Expand Down
10 changes: 10 additions & 0 deletions scripts/dev_rocks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

NEEDED_ROCKS="busted luacov luacov-coveralls luacheck"

for rock in ${NEEDED_ROCKS} ; do
if ! command -v ${rock} &> /dev/null ; then
echo ${rock} not found, installing via luarocks...
luarocks install ${rock}
fi
done
2 changes: 1 addition & 1 deletion src/classic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ function Object:__call(...)
end


return Object
return Object
File renamed without changes.
Loading

0 comments on commit 2e05e88

Please sign in to comment.