Skip to content

Commit

Permalink
travis ci
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigzagAK committed Sep 5, 2017
1 parent 894db3d commit 6a7838d
Show file tree
Hide file tree
Showing 6 changed files with 337 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ t/servroot
nginx-build.ini
tmp/
cpanm
tmp
download
install
build
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: c

compiler:
- gcc

script:
- ./build.sh
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ such as [`ngx_http_upstream_conf`](http://nginx.org/en/docs/http/ngx_http_upstre

This module also supports stream upstreams manipulation.

# Build status
[![Build Status](https://travis-ci.org/ZigzagAK/ngx_dynamic_upstream.svg)](https://travis-ci.org/ZigzagAK/ngx_dynamic_upstream)

# Requirements

`ngx_dynamic_upstream` requires the `zone` directive in the `upstream` context.
Expand Down
286 changes: 286 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
#!/bin/bash

# Copyright, Aleksey Konovkin ([email protected])
# BSD license type

download=0
if [ "$1" == "1" ]; then
download=1
fi
build_deps=0

DIR="$(pwd)"

VERSION="1.11.6"
PCRE_VERSION="8.39"
LUAJIT_VERSION="2.1.0-beta2"
ZLIB_VERSION="1.2.11"

SUFFIX=""

BASE_PREFIX="$DIR/build"
INSTALL_PREFIX="$DIR/install"

JIT_PREFIX="$DIR/build/deps/luajit"

export PCRE_SOURCES="$DIR/build/pcre-$PCRE_VERSION"
export ZLIB_SOURCES="$DIR/build/zlib-$ZLIB_VERSION"

EMBEDDED_OPTS="--with-pcre=$PCRE_SOURCES --with-zlib=$ZLIB_SOURCES"

export LUAJIT_INC="$JIT_PREFIX/usr/local/include/luajit-2.1"
export LUAJIT_LIB="$JIT_PREFIX/usr/local/lib"

export LD_LIBRARY_PATH="$JIT_PREFIX/lib"

function clean() {
rm -rf install 2>/dev/null
rm -rf $(ls -1d build/* 2>/dev/null | grep -v deps) 2>/dev/null
if [ $download -eq 1 ]; then
rm -rf download 2>/dev/null
fi
}

if [ "$1" == "clean" ]; then
clean
exit 0
fi

function build_luajit() {
echo "Build luajit"
cd LuaJIT-$LUAJIT_VERSION
make -j1 > /dev/null
r=$?
if [ $r -ne 0 ]; then
exit $r
fi
DESTDIR="$JIT_PREFIX" make install > /dev/null
cd ..
}

function build_cJSON() {
echo "Build cjson"
cd lua-cjson
PREFIX="$JIT_PREFIX/usr/local" make > /dev/null
r=$?
if [ $r -ne 0 ]; then
exit $r
fi
cd ..
}

function build_debug() {
cd nginx-$VERSION$SUFFIX
echo "Configuring debug nginx-$VERSION$SUFFIX"
./configure --prefix="$INSTALL_PREFIX/nginx-$VERSION$SUFFIX" \
$EMBEDDED_OPTS \
--with-stream \
--with-debug \
--with-cc-opt="-O0" \
--add-module=../ngx_devel_kit \
--add-module=../lua-nginx-module \
--add-module=../stream-lua-nginx-module \
--add-module=../../../ngx_dynamic_upstream > /dev/null

r=$?
if [ $r -ne 0 ]; then
exit $r
fi

echo "Build debug nginx-$VERSION$SUFFIX"
make -j8 > /dev/null

r=$?
if [ $r -ne 0 ]; then
exit $r
fi
make install > /dev/null

mv "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/sbin/nginx" "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/sbin/nginx.debug"

cd ..
}

function build_release() {
cd nginx-$VERSION$SUFFIX
echo "Configuring release nginx-$VERSION$SUFFIX"
./configure --prefix="$INSTALL_PREFIX/nginx-$VERSION$SUFFIX" \
$EMBEDDED_OPTS \
--with-stream \
--add-module=../ngx_devel_kit \
--add-module=../lua-nginx-module \
--add-module=../stream-lua-nginx-module \
--add-module=../../../ngx_dynamic_upstream > /dev/null

r=$?
if [ $r -ne 0 ]; then
exit $r
fi

echo "Build release nginx-$VERSION$SUFFIX"
make -j8 > /dev/null

r=$?
if [ $r -ne 0 ]; then
exit $r
fi
make install > /dev/null
cd ..
}

function download_module() {
if [ -e $DIR/../$2 ]; then
echo "Get $DIR/../$2"
dir=$(pwd)
cd $DIR/..
tar zcf $dir/$2.tar.gz $(ls -1d $2/* | grep -vE "(install$)|(build$)|(download$)|(.git$)")
cd $dir
else
if [ $download -eq 1 ] || [ ! -e $2.tar.gz ]; then
echo "Download $2 branch=$3"
curl -s -L -o $2.zip https://github.com/$1/$2/archive/$3.zip
unzip -q $2.zip
mv $2-* $2
tar zcf $2.tar.gz $2
rm -rf $2-* $2 $2.zip
fi
fi
}

function gitclone() {
git clone $1 > /dev/null 2> /tmp/err
if [ $? -ne 0 ]; then
cat /tmp/err
fi
}

function download_nginx() {
if [ $download -eq 1 ] || [ ! -e nginx-$VERSION.tar.gz ]; then
echo "Download nginx-$VERSION"
curl -s -L -O http://nginx.org/download/nginx-$VERSION.tar.gz
else
echo "Get nginx-$VERSION.tar.gz"
fi
}

function download_luajit() {
if [ $download -eq 1 ] || [ ! -e LuaJIT-$LUAJIT_VERSION.tar.gz ]; then
echo "Download LuaJIT-$LUAJIT_VERSION"
curl -s -L -O http://luajit.org/download/LuaJIT-$LUAJIT_VERSION.tar.gz
else
echo "Get LuaJIT-$LUAJIT_VERSION.tar.gz"
fi
}

function download_pcre() {
if [ $download -eq 1 ] || [ ! -e pcre-$PCRE_VERSION.tar.gz ]; then
echo "Download PCRE-$PCRE_VERSION"
curl -s -L -O http://ftp.cs.stanford.edu/pub/exim/pcre/pcre-$PCRE_VERSION.tar.gz
else
echo "Get pcre-$PCRE_VERSION.tar.gz"
fi
}

function download_dep() {
if [ $download -eq 1 ] || [ ! -e $2-$3.tar.gz ]; then
echo "Download $2-$3.$4"
curl -s -L -o $2-$3.tar.gz $1/$2-$3.$4
else
echo "Get $2-$3.tar.gz"
fi
}

function extract_downloads() {
cd download

for d in $(ls -1 *.tar.gz)
do
echo "Extracting $d"
tar zxf $d -C ../build --no-overwrite-dir --keep-old-files 2>/dev/null
done

cd ..
}

function download() {
mkdir build 2>/dev/null
mkdir build/deps 2>/dev/null

mkdir download 2>/dev/null
mkdir download/lua_modules 2>/dev/null

cd download

download_luajit
download_pcre
download_nginx

download_module ZigzagAK ngx_dynamic_upstream master
download_module openresty stream-lua-nginx-module master
download_module simpl ngx_devel_kit master
download_module openresty lua-nginx-module master
download_module openresty lua-cjson master

download_dep http://zlib.net zlib $ZLIB_VERSION tar.gz

cd ..
}

function install_file() {
echo "Install $1"
if [ ! -e "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/$2" ]; then
mkdir -p "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/$2"
fi
cp -r $3 $1 "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/$2/"
}

function install_files() {
for f in $(ls $1)
do
install_file $f $2 $3
done
}

function build() {
cd build

patch -N -p0 < ../lua-cjson-Makefile.patch

if [ $build_deps -eq 1 ] || [ ! -e deps/luajit ]; then
build_luajit
fi

build_cJSON

make clean > /dev/null 2>&1
build_debug

make clean > /dev/null 2>&1
build_release

install_file "$JIT_PREFIX/usr/local/lib" .
install_file lua-cjson/cjson.so lib/lua/5.1

cd ..
}

clean
download
extract_downloads
build

cp LICENSE "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/LICENSE"

cd "$DIR"

kernel_name=$(uname -s)
kernel_version=$(uname -r)

cd install

tar zcvf nginx-$VERSION$SUFFIX-$kernel_name-$kernel_version.tar.gz nginx-$VERSION$SUFFIX
rm -rf nginx-$VERSION$SUFFIX

cd ..

exit $r
17 changes: 17 additions & 0 deletions lua-cjson-Makefile.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--- lua-cjson/Makefile 2016-11-07 08:47:47.000000000 +0300
+++ lua-cjson/Makefile 2016-10-26 00:04:44.000000000 +0300
@@ -13,12 +13,12 @@
##### Build defaults #####
LUA_VERSION = 5.1
TARGET = cjson.so
-PREFIX = /usr/local
+PREFIX ?= /usr/local
#CFLAGS = -g -Wall -pedantic -fno-inline
CFLAGS = -O3 -Wall -pedantic -DNDEBUG
CJSON_CFLAGS = -fpic
CJSON_LDFLAGS = -shared
-LUA_INCLUDE_DIR ?= $(PREFIX)/include
+LUA_INCLUDE_DIR ?= $(PREFIX)/include/luajit-2.1
LUA_CMODULE_DIR ?= $(PREFIX)/lib/lua/$(LUA_VERSION)
LUA_MODULE_DIR ?= $(PREFIX)/share/lua/$(LUA_VERSION)
LUA_BIN_DIR ?= $(PREFIX)/bin
21 changes: 20 additions & 1 deletion tests.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
#!/bin/bash

DIR=$(pwd)
nginx_fname=$(ls -1 $DIR/install/*.tar.gz)

[ -d install/tmp ] || mkdir install/tmp
tar zxf $nginx_fname -C install/tmp

folder="$(ls -1 $DIR/install/tmp | grep nginx)"

export PATH=$DIR/install/tmp/$folder/sbin:$PATH
export LD_LIBRARY_PATH=$DIR/install/tmp/$folder/lib

ret=0

for t in $(ls t/*.t)
do
echo "Tests : "$t
prove $t
if [ $? -ne 0 ]; then
ret=$?
fi
done

rm -rf t/servroot
rm -rf t/servroot
rm -rf install/tmp

exit $ret

0 comments on commit 6a7838d

Please sign in to comment.