Skip to content

Commit

Permalink
Merge pull request #649 from 3scale/ensure-correct-deps-development-d…
Browse files Browse the repository at this point in the history
…ocker

Dockerized dev env: ensure correct dependencies are used
  • Loading branch information
davidor committed Mar 12, 2018
2 parents 2affe4e + 565906b commit 388eabd
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Avoid `nameserver` repetion from `RESOLVER` variable and `resolv.conf` file [PR #636](https://github.com/3scale/apicast/pull/636)
- Bug in URL rewriting policy that ignored the `commands` attribute in the policy manifest [PR #641](https://github.com/3scale/apicast/pull/641)
- Skip comentaries after `search` values in resolv.conf [PR #635](https://github.com/3scale/apicast/pull/635)
- Bug that prevented using `CONFIGURATION_CACHE_LOADER=boot` without specifying `APICAST_CONFIGURATION_CACHE` in staging [PR #651](https://github.com/3scale/apicast/pull/651).

## [3.2.0-beta1] - 2018-02-20

Expand Down
2 changes: 2 additions & 0 deletions Dockerfile-development
Expand Up @@ -25,6 +25,8 @@ COPY Makefile ${USER_HOME}
WORKDIR ${USER_HOME}

RUN make dependencies
RUN mv lua_modules /tmp/lua_modules

RUN cpanm --installdeps ./gateway

COPY . ${USER_HOME}
Expand Down
20 changes: 20 additions & 0 deletions README.md
Expand Up @@ -161,6 +161,26 @@ To see additional test targets (such as testing produced Docker images) use:
make help
```

## Development using Docker

This option requires a single step:

```shell
make development
```

That will create a Docker container and run bash inside it. This command will
take care of installing all dependencies.

The project's source code will be available in the container and sync'ed with
your local `apicast` directory, so you can edit files in your preferred
environment and still be able to run whatever you need inside the Docker container.

To run the tests inside the container, just run:
```shell
script/test
```

# Contributing
For details on how to contribute to this repo see [CONTRIBUTING](.github/CONTRIBUTING.md)

Expand Down
2 changes: 1 addition & 1 deletion gateway/config/staging.lua
Expand Up @@ -2,5 +2,5 @@ return {
master_process = 'on',
lua_code_cache = 'on',
configuration_loader = 'lazy',
configuration_cache = 0,
configuration_cache = os.getenv('APICAST_CONFIGURATION_CACHE'),
}
7 changes: 6 additions & 1 deletion gateway/src/apicast/cli/command/start.lua
Expand Up @@ -110,10 +110,15 @@ local function openresty_binary(candidates)
end

local function build_env(options, config, context)
local configuration_cache = options.cache or context.configuration_cache
if configuration_cache then -- Avoid calling tostring() on nil, would return "nil".
configuration_cache = tostring(configuration_cache)
end

return {
APICAST_CONFIGURATION = options.configuration or context.configuration,
APICAST_CONFIGURATION_LOADER = tostring(options.configuration_loader or context.configuration_loader or 'lazy'),
APICAST_CONFIGURATION_CACHE = tostring(options.cache or context.configuration_cache or 0),
APICAST_CONFIGURATION_CACHE = configuration_cache,
THREESCALE_DEPLOYMENT_ENV = context.configuration_channel or options.channel or config.name,
APICAST_POLICY_LOAD_PATH = concat(options.policy_load_path or context.policy_load_path, ':'),
}
Expand Down
4 changes: 2 additions & 2 deletions gateway/src/apicast/configuration_loader.lua
Expand Up @@ -60,7 +60,7 @@ end
_M.mock = mock_loader.save

local function ttl()
return tonumber(env.get('APICAST_CONFIGURATION_CACHE'), 10)
return tonumber(env.get('APICAST_CONFIGURATION_CACHE') or 0, 10)
end

function _M.global(contents)
Expand Down Expand Up @@ -121,7 +121,7 @@ end

local boot = {
rewrite = noop,
ttl = function() return tonumber(env.get('APICAST_CONFIGURATION_CACHE'), 10) end
ttl = function() return tonumber(env.get('APICAST_CONFIGURATION_CACHE')) end
}

function boot.init(configuration)
Expand Down
4 changes: 4 additions & 0 deletions script/test
Expand Up @@ -5,12 +5,16 @@ PROJECT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
ROVER="/usr/local/openresty/luajit/bin/rover"

function run_busted_tests {
sudo cp -R /tmp/lua_modules .

cd "${PROJECT_PATH}" || exit; ${ROVER} exec ./bin/busted
}

function run_nginx_unit_tests {
cd "${PROJECT_PATH}" || exit

sudo cp -R /tmp/lua_modules .

sudo TEST_NGINX_APICAST_PATH="${PROJECT_PATH}/gateway" \
TEST_NGINX_BINARY=openresty \
TEST_NGINX_REDIS_HOST=redis \
Expand Down
11 changes: 10 additions & 1 deletion spec/configuration_loader_spec.lua
@@ -1,3 +1,5 @@
local env = require 'resty.env'

insulate('Configuration object', function()

insulate('.mock', function()
Expand Down Expand Up @@ -92,7 +94,14 @@ insulate('Configuration object', function()
local configuration_store = require('apicast.configuration_store')
local loader

before_each(function() loader = _M.new('lazy') end)
before_each(function()
loader = _M.new('lazy')

-- By default, the config is reloaded on every rewrite(), because
-- APICAST_CONFIGURATION_CACHE is set to 0. To be sure that it does not
-- change and we can compare it, we need to set the env.
env.set('APICAST_CONFIGURATION_CACHE', 120)
end)

it('does not crash on rewrite', function()
local configuration = configuration_store.new()
Expand Down

0 comments on commit 388eabd

Please sign in to comment.