Skip to content

Commit

Permalink
Merge pull request #460 from 3scale/rover
Browse files Browse the repository at this point in the history
use new s2i-openresty with rover integration
  • Loading branch information
mikz authored Oct 25, 2017
2 parents ce691a7 + 336270b commit dcf4498
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 50 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
environment:
S2I_VERSION: "1.1.7-226afa1"
DOCKER_COMPOSE_VERSION: "1.16.1"
OPENRESTY_VERSION: "1.11.2.5-1"
OPENRESTY_VERSION: "1.11.2.5-1-rover"
steps:
- run: apk update && apk add wget make bash curl py-pip git openssh-client
- run: |
Expand Down Expand Up @@ -37,7 +37,7 @@ jobs:
- run: make prove-docker
build:
docker:
- image: quay.io/3scale/s2i-openresty-centos7:1.11.2.5-2
- image: quay.io/3scale/s2i-openresty-centos7:1.11.2.5-1-rover
environment:
TEST_NGINX_BINARY: openresty
LUA_BIN_PATH: /opt/app-root/bin
Expand All @@ -48,12 +48,12 @@ jobs:
- run: rm -rf lua_modules
- restore_cache:
keys:
- apicast-rocks-{{ arch }}-{{ checksum "Roverfile.lock" }}
- apicast-rocks-{{ arch }}-{{ checksum "apicast/Roverfile.lock" }}
- apicast-rocks-{{ arch }}-{{ .Branch }}
- apicast-rocks-{{ arch }}-master
- run: make dependencies
- save_cache:
key: apicast-rocks-{{ arch }}-{{ checksum "Roverfile.lock" }}
key: apicast-rocks-{{ arch }}-{{ checksum "apicast/Roverfile.lock" }}
paths:
- lua_modules
- run: mkdir -p tmp/junit
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ before_install:
- travis/install-s2i.sh
- export PATH="${PATH}:${HOME}/openresty/bin:${HOME}/openresty/luajit/bin:${HOME}/openresty/nginx/sbin:${HOME}/bin:${HOME}/.luarocks/bin"
script:
- make builder-image danger
- make test-doc
- make builder-image
- make test-doc
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Increased number of background timers and connections in the cosocket pool [PR #290](https://github.com/3scale/apicast/pull/290)
- Make OAuth tokens TTL configurable [PR #448](https://github.com/3scale/apicast/pull/448)
- Detect when being executed in Test::Nginx and use default backend accordingly [PR #458](https://github.com/3scale/apicast/pull/458)
- Update the s2i-openresty image to have the same path (`/opt/app-root/src`) in all images [PR #460](https://github.com/3scale/apicast/pull/460)

### Fixed

Expand Down
24 changes: 9 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,18 @@ ROVER ?= $(shell which rover 2> /dev/null)
ifeq ($(ROVER),)
ROVER := lua_modules/bin/rover
endif
export LUAROCKS_CONFIG=luarocks.config

export COMPOSE_PROJECT_NAME

DANGER_IMAGE ?= quay.io/3scale/danger

test: ## Run all tests
$(MAKE) --keep-going busted prove builder-image test-builder-image prove-docker runtime-image test-runtime-image

apicast-source: export IMAGE_NAME ?= apicast-test
apicast-source: ## Create Docker Volume container with APIcast source code
- docker rm -v -f $(COMPOSE_PROJECT_NAME)-source
docker create --rm -v /opt/app --name $(COMPOSE_PROJECT_NAME)-source $(IMAGE_NAME) /bin/true
docker cp . $(COMPOSE_PROJECT_NAME)-source:/opt/app
docker create --rm -v /opt/app-root/src --name $(COMPOSE_PROJECT_NAME)-source $(IMAGE_NAME) /bin/true
docker cp . $(COMPOSE_PROJECT_NAME)-source:/opt/app-root/src

danger: apicast-source
danger: TEMPFILE := $(shell mktemp)
danger:
env | grep -E 'CIRCLE|TRAVIS|DANGER|SEAL' > $(TEMPFILE)
docker run --rm -w /opt/app/ --volumes-from=$(COMPOSE_PROJECT_NAME)-source --env-file=$(TEMPFILE) -u $(shell id -u) $(DANGER_IMAGE) danger

busted: dependencies $(ROVER) ## Test Lua.
@$(ROVER) exec bin/busted
Expand Down Expand Up @@ -91,9 +83,9 @@ test-builder-image: export IMAGE_NAME = apicast-test
test-builder-image: builder-image clean-containers ## Smoke test the builder image. Pass any docker image in IMAGE_NAME parameter.
$(DOCKER_COMPOSE) --version
@echo -e $(SEPARATOR)
$(DOCKER_COMPOSE) run --rm --user 100001 gateway openresty -p /opt/app -t
$(DOCKER_COMPOSE) run --rm --user 100001 gateway openresty -c /opt/app-root/src/conf/nginx.conf -g 'error_log stderr info; pid /tmp/nginx.pid;' -t
@echo -e $(SEPARATOR)
$(DOCKER_COMPOSE) run --rm --user 100001 gateway openresty -p /opt/app
$(DOCKER_COMPOSE) run --rm --user 100001 gateway openresty -c /opt/app-root/src/conf/nginx.conf -g 'error_log stderr info; pid /tmp/nginx.pid;'
@echo -e $(SEPARATOR)
$(DOCKER_COMPOSE) run --rm test bash -c 'for i in {1..5}; do curl --fail http://gateway:8090/status/live && break || sleep 1; done'
$(DOCKER_COMPOSE) logs gateway
Expand All @@ -106,7 +98,9 @@ test-builder-image: builder-image clean-containers ## Smoke test the builder ima
@echo -e $(SEPARATOR)
$(DOCKER_COMPOSE) run --rm test curl --fail -X POST http://gateway:8090/boot
@echo -e $(SEPARATOR)
$(DOCKER_COMPOSE) run --rm -e THREESCALE_PORTAL_ENDPOINT=https://echo-api.3scale.net gateway /opt/app/libexec/boot | grep 'APIcast/'
$(DOCKER_COMPOSE) run --rm -e THREESCALE_PORTAL_ENDPOINT=https://echo-api.3scale.net gateway libexec/boot | grep 'APIcast/'
@echo -e $(SEPARATOR)
$(DOCKER_COMPOSE) run --rm gateway bin/apicast -c http://echo-api.3scale.net -d -b

gateway-logs: export IMAGE_NAME = does-not-matter
gateway-logs:
Expand All @@ -130,10 +124,10 @@ rover: $(ROVER)
@echo $(ROVER)

dependencies: $(ROVER)
$(ROVER) install
$(ROVER) install --roverfile=apicast/Roverfile

lua_modules/bin/rover:
@luarocks install --server=http://luarocks.org/dev lua-rover --tree lua_modules 1>&2
@LUAROCKS_CONFIG=apicast/config-5.1.lua luarocks install --server=http://luarocks.org/dev lua-rover --tree lua_modules 1>&2

clean-containers: apicast-source
$(DOCKER_COMPOSE) down --volumes
Expand Down
13 changes: 0 additions & 13 deletions Roverfile

This file was deleted.

1 change: 1 addition & 0 deletions apicast/.s2i/environment
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
OPENSSL_VERIFY=false
SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt
4 changes: 3 additions & 1 deletion apicast/.s2iignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.s2i
.s2i/bin
conf/ca-bundle.crt
apicast.d/proxy_ssl.conf
lua_modules
.cache
15 changes: 15 additions & 0 deletions apicast/Roverfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
luarocks {

rockspec 'apicast-0.1-0.rockspec',

group 'testing' {
module { 'busted' },
},

group 'development' {
module {'ldoc'},
module {'lua-resty-repl'},
module {'lua-resty-iputils', '0.3.0'},
}
}

2 changes: 1 addition & 1 deletion Roverfile.lock → apicast/Roverfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ busted 2.0.rc12-1
dkjson 2.5-2
inspect 3.1.0-1
ldoc 1.4.6-2
lua-resty-env 0.3.0-1
lua-resty-env 0.4.0-1
lua-resty-http 0.10-0
lua-resty-iputils 0.3.0-1
lua-resty-jwt 0.1.10-1
Expand Down
7 changes: 4 additions & 3 deletions apicast/bin/apicast
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ done
log="log_level_${log_level}"
log_level="${!log}"

mkdir -p "${apicast_dir}/logs"

daemon=off
worker_processes=${APICAST_WORKERS:-1}

Expand Down Expand Up @@ -125,5 +123,8 @@ main+=$(printenv | awk '$1 ~ /^(APICAST|THREESCALE)_/ {split($0,env,"="); print
function join_by { local IFS="$1"; shift; echo "$*"; }
args=$(join_by '' "${args[@]}")
main=$(join_by '' "${main[@]}")

cd "${apicast_dir}"

# shellcheck disable=SC2086
exec "${openresty_binary}" -p "${apicast_dir}" -c conf/nginx.conf ${args} -g "${main} error_log ${log_file} ${log_levels[log_level]};"
exec "${openresty_binary}" -c "${apicast_dir}/conf/nginx.conf" ${args} -g "${main} error_log ${log_file} ${log_levels[log_level]};"
2 changes: 1 addition & 1 deletion apicast/conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ http {
log_format time '[$time_local] $host:$server_port $remote_addr:$remote_port "$request" $status $body_bytes_sent ($request_time) $post_action_impact';
access_log off;

lua_package_path ";;${prefix}?.lua;${prefix}src/?.lua";
lua_package_path ";;./?.lua;./src/?.lua";

# Enabling the Lua code cache is strongly encouraged for production use
# Disabling it should only be done for testing and development purposes
Expand Down
5 changes: 5 additions & 0 deletions apicast/config-5.1.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- vim: set ft=lua:
-- workaround for https://github.com/luarocks/luarocks/issues/740
rocks_trees = {
{ name = 'rover', root = [[lua_modules]] },
}
4 changes: 3 additions & 1 deletion apicast/libexec/run
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

ssl=$(mktemp -q)

certificate=${SSL_CERT_FILE:-"$(pwd)/conf/ca-bundle.crt"}

echo "lua_ssl_verify_depth 5;" >> "${ssl}"
echo "lua_ssl_trusted_certificate \"$(pwd)/conf/ca-bundle.crt\";" >> "${ssl}"
echo "lua_ssl_trusted_certificate \"${certificate}\";" >> "${ssl}"

exec resty --http-include "${ssl}" "libexec/$(basename "$0").lua" "$@"
6 changes: 4 additions & 2 deletions apicast/src/configuration_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local synchronization = require('resty.synchronization').new(1)

local error = error
local len = string.len
local format = string.format
local assert = assert
local pcall = pcall
local tonumber = tonumber
Expand Down Expand Up @@ -89,8 +90,9 @@ end
-- Cosocket API is not available in the init_by_lua* context (see more here: https://github.com/openresty/lua-nginx-module#cosockets-not-available-everywhere)
-- For this reason a new process needs to be started to download the configuration through 3scale API
function _M.run_external_command(cmd, cwd)
cwd = cwd or env.get('TEST_NGINX_APICAST_PATH') or ngx.config.prefix()
local config, err, code = util.system("cd '" .. cwd .."' && libexec/"..(cmd or "boot"))
local config, err, code = util.system(format('cd %s && libexec/%s',
cwd or env.get('TEST_NGINX_APICAST_PATH') or '.',
cmd or 'boot'))

-- Try to read the file in current working directory before changing to the prefix.
if err then config = file_loader.call() end
Expand Down
12 changes: 11 additions & 1 deletion apicast/src/proxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,18 @@ end
if custom_config then
local path = package.path
local module = gsub(custom_config, '%.lua$', '') -- strip .lua from end of the file
package.path = package.path .. ';' .. ngx.config.prefix() .. '?.lua;'
package.path = package.path .. ';' .. './?.lua;'
local ok, c = pcall(function() return require(module) end)

if not ok then
local chunk, _ = loadfile(custom_config)

if chunk then
ok = true
c = chunk()
end
end

package.path = path

if ok then
Expand Down
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
- "8080:8080"
- "8090:8090"
volumes:
- .:/opt/app
- .:/opt/app-root/src
env_file: .env
environment:
TEST_NGINX_BINARY: openresty
Expand All @@ -36,9 +36,8 @@ services:
entrypoint: "bash -ec"
environment:
TEST_NGINX_BINARY: openresty
TEST_NGINX_APICAST_PATH: /opt/app
TEST_NGINX_REDIS_HOST: redis
command: "'$$TEST_NGINX_BINARY -V; prove; exit $$?'"
command: "'$$TEST_NGINX_BINARY -V; cd ; prove; exit $$?'"
dns_search:
- example.com
depends_on:
Expand Down
6 changes: 4 additions & 2 deletions t/004-custom-config.t
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use lib 't';
use TestAPIcast 'no_plan';

$ENV{APICAST_CUSTOM_CONFIG} = "$Test::Nginx::Util::HtmlDir/custom.lua";

env_to_nginx('APICAST_CUSTOM_CONFIG');

run_tests();

__DATA__
=== TEST 1: loading custom config file works
--- main_config
env APICAST_CUSTOM_CONFIG=html/custom.lua;
--- http_config
lua_package_path "$TEST_NGINX_LUA_PATH";
--- config
Expand Down
4 changes: 3 additions & 1 deletion t/014-resolver.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use TestAPIcast 'no_plan';
$ENV{TEST_NGINX_HTTP_CONFIG} = "$TestAPIcast::path/http.d/*.conf";
$ENV{RESOLVER} = '127.0.1.1:5353';

$ENV{TEST_NGINX_RESOLV_CONF} = "$Test::Nginx::Util::HtmlDir/resolv.conf";

env_to_nginx(
'RESOLVER'
);
Expand All @@ -18,7 +20,7 @@ both RESOLVER env variable and resolvers in resolv.conf should be used
--- http_config
lua_package_path "$TEST_NGINX_LUA_PATH";
init_by_lua_block {
require('resty.resolver').init(ngx.config.prefix() .. 'html/resolv.conf')
require('resty.resolver').init('$TEST_NGINX_RESOLV_CONF')
}
--- config
location = /t {
Expand Down

0 comments on commit dcf4498

Please sign in to comment.