Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update Makefile for macosX installation about using luajit building deps #217

Merged
merged 8 commits into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ go
\.*
conf/apisix.uid
deps
scgi_temp
uwsgi_temp
proxy_temp
fastcgi_temp
client_body_temp
46 changes: 19 additions & 27 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
os: linux
os:
- linux
- osx
dist: xenial

compiler:
- gcc
- clang

sudo: required

addons:
Expand All @@ -17,37 +23,23 @@ addons:
- luarocks
- cmake
- lua-check

env:
global:
- OPENRESTY_PREFIX=/usr/local/openresty-debug
homebrew:
packages:
- perl
- cpanminus
- etcd
- luarocks
- openresty
update: true

before_install:
- sudo cpanm --notest Test::Nginx IPC::Run > build.log 2>&1 || (cat build.log && exit 1)
- sudo luarocks install --lua-dir=/usr/local/openresty/luajit luacov-coveralls
- ./utils/travis_runner.sh before_install

install:
- wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
- sudo apt-get -y install software-properties-common
- sudo add-apt-repository -y "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main"
- sudo apt-get update
- sudo apt-get install openresty-debug
- sudo luarocks install --lua-dir=/usr/local/openresty/luajit apisix-*.rockspec --only-deps
- git clone https://github.com/openresty/test-nginx.git test-nginx
- ./utils/travis_runner.sh do_install

script:
- export PATH=$OPENRESTY_PREFIX/nginx/sbin:$OPENRESTY_PREFIX/luajit/bin:$OPENRESTY_PREFIX/bin:$PATH
- sudo service etcd start
- ./bin/apisix help
- ./bin/apisix init
- ./bin/apisix init_etcd
- ./bin/apisix start
- mkdir -p logs
- sleep 1
- ./bin/apisix stop
- sleep 1
- make check || exit 1
- APISIX_ENABLE_LUACOV=1 prove -Itest-nginx/lib -r t
- ./utils/travis_runner.sh script

after_success:
- luacov-coveralls
- ./utils/travis_runner.sh after_success
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ INST_LUADIR ?= $(INST_PREFIX)/share/lua/5.1
INST_BINDIR ?= /usr/bin
INSTALL ?= install
UNAME ?= $(shell uname)
OR_EXEC ?= $(shell which openresty)
LUA_JIT_DIR ?= $(shell TMP='./v_tmp' && $(OR_EXEC) -V &>$${TMP} && cat $${TMP} | grep prefix | grep -Eo 'prefix=(.*?)/nginx' | grep -Eo '/.*/' && rm $${TMP})luajit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'./v_tmp' -> '/tmp/v_tmp', how about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't make any sense, the v_tmp file will been clean immediately at the end of this command.



.PHONY: default
Expand All @@ -23,7 +25,7 @@ help:
dev:
./utils/update_nginx_conf_dev.sh
ifeq ($(UNAME),Darwin)
luarocks install --lua-dir=/usr/local/openresty/luajit apisix-*.rockspec --tree=deps --only-deps
luarocks install --lua-dir=$(LUA_JIT_DIR) apisix-*.rockspec --tree=deps --only-deps
else
sudo luarocks install --lua-dir=/usr/local/openresty/luajit apisix-*.rockspec --tree=deps --only-deps
endif
Expand Down Expand Up @@ -52,13 +54,13 @@ init:
run:
mkdir -p logs
mkdir -p /tmp/cores/
$$(which openresty) -p $$PWD/ -c $$PWD/conf/nginx.conf
$(OR_EXEC) -p $$PWD/ -c $$PWD/conf/nginx.conf


### stop: Stop the apisix server
.PHONY: stop
stop:
$$(which openresty) -p $$PWD/ -c $$PWD/conf/nginx.conf -s stop
$(OR_EXEC) -p $$PWD/ -c $$PWD/conf/nginx.conf -s stop


### clean: Remove generated files
Expand All @@ -70,7 +72,7 @@ clean:
### reload: Reload the apisix server
.PHONY: reload
reload:
$$(which openresty) -p $$PWD/ -c $$PWD/conf/nginx.conf -s reload
$(OR_EXEC) -p $$PWD/ -c $$PWD/conf/nginx.conf -s reload


### install: Install the apisix
Expand Down Expand Up @@ -101,4 +103,8 @@ install:
$(INSTALL) bin/apisix $(INST_BINDIR)/apisix

test:
ifeq ($(UNAME),Darwin)
prove -I../test-nginx/lib -I./ -r -s t/
else
prove -I../test-nginx/lib -r -s t/
endif
108 changes: 108 additions & 0 deletions utils/travis_runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env bash

### BEGIN ###
# Author: idevz
# Since: 08:52:47 2019/07/08
# Description: travis_runner.sh
# travis_runner ./travis_runner.sh
#
# Environment variables that control this script:
#
### END ###

set -ex

export_or_prefix() {
if [ $TRAVIS_OS_NAME = osx ]; then
export OPENRESTY_PREFIX=$(TMP='./v_tmp' && $(which openresty) -V &>${TMP} &&
cat ${TMP} | grep prefix | grep -Eo 'prefix=(.*?)/nginx' |
grep -Eo '/.*/' && rm ${TMP})
else
export OPENRESTY_PREFIX="/usr/local/openresty-debug"
fi
}

before_install() {
sudo cpanm --notest Test::Nginx IPC::Run >build.log 2>&1 || (cat build.log && exit 1)
}

do_install() {
if [ $TRAVIS_OS_NAME = osx ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's more convenient for different systems to use separate scripts.

how about: ***_mac.sh, ***_linux.sh ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if using like ***_mac.sh, ***_linux.sh things, the control logic about to using which one will need to write in .travis.yaml, I think it's so ugly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about this way in travis: bash utils/travis_$TRAVIS_OS_NAME.sh

brew install openresty/brew/openresty-debug
else
wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
sudo apt-get -y install software-properties-common
sudo add-apt-repository -y "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main"
sudo apt-get update
sudo apt-get install openresty-debug
fi

export_or_prefix

luarocks install --lua-dir=${OPENRESTY_PREFIX}luajit luacov-coveralls --local --tree=deps

if [ $TRAVIS_OS_NAME = osx ]; then
make dev
else
sudo luarocks install --lua-dir=${OPENRESTY_PREFIX}luajit apisix-*.rockspec --only-deps
fi

git clone https://github.com/openresty/test-nginx.git test-nginx
}

script() {
export_or_prefix
export PATH=$OPENRESTY_PREFIX/nginx/sbin:$OPENRESTY_PREFIX/luajit/bin:$OPENRESTY_PREFIX/bin:$PATH
if [ $TRAVIS_OS_NAME = osx ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this style:

# mac os
if [ $TRAVIS_OS_NAME = osx ]; then
   ...
   return
fi

# default linux
...

luarocks install luacheck
brew services start etcd
make help
make init
sudo make run
mkdir -p logs
sleep 1
sudo make stop

sudo cpanm Test::Nginx

sleep 1
make check || exit 1

ln -sf $PWD/deps/lib $PWD/deps/lib64
APISIX_ENABLE_LUACOV=1 prove -Itest-nginx/lib -I./ -r t
else
sudo service etcd start
./bin/apisix help
./bin/apisix init
./bin/apisix init_etcd
./bin/apisix start
mkdir -p logs
sleep 1
./bin/apisix stop
sleep 1
make check || exit 1
APISIX_ENABLE_LUACOV=1 prove -Itest-nginx/lib -r t
fi
}

after_success() {
luacov-coveralls
}

case_opt=$1
shift

case ${case_opt} in
before_install)
before_install "$@"
;;
do_install)
do_install "$@"
;;
script)
script "$@"
;;
after_success)
after_success "$@"
;;
esac