• Stars
    star
    266
  • Rank 154,103 (Top 4 %)
  • Language
    Perl
  • Created over 13 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Utilities for nginx module development

NAME

openresty-devel-utils - Development utilities for NGINX and OpenResty

Table of Contents

Description

This project provides some common tools for Nginx module development.

cd /path/to/some/module

# generate short-name symlinks for src/ngx_http_*.[ch]
ngx-links src

# build a custom nginx 1.0.5 (with cache)
ngx-build 1.0.5 \
    --add-module=`pwd` \
    --with-debug \
    <other nginx configure options go here>

export PATH=`pwd`/work/nginx/sbin:$PATH
nginx -V

# build a custom nginx 1.0.5 (without cache)
ngx-build -f 1.0.5 \
    --add-module=`pwd` \
    --with-debug \
    <other nginx configure options go here>

ngx-build

The ngx-build tool is used by almost all our NGINX C module projects for everyday development, for example, lua-nginx-module.

First of all, you should always add the directory of this tool to your PATH system environment, like this:

export PATH=/path/to/openresty-devel-utils:$PATH

Replace the placeholder /path/to/ with the real path in your system. You'd better put this line in your ~/.bashrc file so that you can always have it.

Usually, we have a util/build.sh shell script in each of the NGINX C module project's source tree, as in:

https://github.com/openresty/lua-nginx-module/blob/master/util/build.sh

And then we create a local shell script, usually called something like build13 (the number 13 means nginx 1.13.x) which contains the following:

#!/usr/bin/env bash

#export NGX_BUILD_DISABLE_NO_POOL=1
#export NGX_BUILD_NO_DEBUG=1

export NGX_BUILD_DTRACE=1
export NGX_BUILD_CC_OPTS="-O1 -I/opt/systemtap/include"

export LUAJIT=/usr/local/openresty-debug/luajit
export LUAJIT_LIB=$LUAJIT/lib
export LUAJIT_INC=$LUAJIT/include/luajit-2.1

export PCRE=/usr/local/openresty/pcre
export PCRE_LIB=$PCRE/lib
export PCRE_INC=$PCRE/include

export OPENSSL=/usr/local/openresty-debug/openssl
export OPENSSL_INC=$OPENSSL/include
export OPENSSL_LIB=$OPENSSL/lib

export NGX_BUILD_CC="gcc"
export NGX_BUILD_JOBS=9

# build using nginx 1.13.6
exec ./util/build.sh 1.13.6

The ngx-build script will download the specified version of the nginx source release tarball from nginx.org and caches it under ~/work/ in the local file system, and then builds everything under ./buildroot/nginx-1.13.6/ and finally, if everything builds fine, it will installs the nginx into ./work/nginx/.

The build13 shell script above assumes that you have installed the openresty-debug, openresty-pcre-devel, and openresty-openssl-debug-devel pre-built packages (along with their -debuginfo packages) from OpenResty's official Linux package repositories. You can surely specify your own local builds of LuaJIT, PCRE, and/or OpenSSL. Just change the path values for the corresponding system environment variables accordingly.

The build13 script should never get checked into the git repository. And it should be different for each developer and is subject to frequent edits during everyday development.

Only those system environments whose names start with the NGX_BUILD_ prefix are supported by the ngx-build script. Otherwise the environments are interpreted by the util/build.sh script of each nginx C module project.

ngx-build always tries to build things incrementally, so it is usually very fast to run. If the previous run of nginx's ./configure script fails, then subsequent ngx-build invokes would always fail with the following error message:

make: *** No rule to make target 'build', needed by 'default'.  Stop.
failed to run command "make -j9"

This is completely normal, and to fix this, you need to update the last modified time stamp of your config file like below:

touch config

Then ngx-build will see that the Makefile is older than config file and will try running nginx's ./configure script again.

To combine these 2 steps together, we get

touch config && ./build13

Do not touch the config file in other cases since it would only slow down your build by compiling everything from scratch.

One thing to note here is that ngx-build never tries to add RPATH to the resulting nginx build, so it is each nginx C module project's responsibility to do that if it is desired. It is usually done in the util/build.sh script of each project, as in:

https://github.com/openresty/lua-nginx-module/blob/master/util/build.sh#L34

Sometimes, the project may prefer not hard-coding an RPATH setting for particular dependency libraries like LuaJIT. For example, the lua-nginx-module project only adds RPATH for OpenSSL, PCRE, and Libdrizzle in its util/build.sh script:

https://github.com/openresty/lua-nginx-module/blob/master/util/build.sh#L34

And it intentionally omits the RPATH for LuaJIT. This is because the developers of lua-nginx-module usually want to run different builds of LuaJIT when running the test suite in different "test modes" of the Test::Nginx::Socket test scaffold without the burden of re-linking the local nginx binary.

For example, when running the test suite with Valgrind, the developers of lua-nginx-module would set the system environment:

export LD_LIBRARY_PATH=/usr/local/openresty-valgrind/luajit/lib:$LD_LIBRARY_PATH
export TEST_NGINX_USE_VALGRIND=1

Here we use the LuaJIT shipped with OpenResty's official binary package openresty-valgrind, which enables the system allocator which would only work atop Valgrind.

And for normal running modes, we should switch to another LuaJIT at runtime like below:

export LD_LIBRARY_PATH=/usr/local/openresty-debug/luajit/lib:$LD_LIBRARY_PATH

or when running the tests in the "benchmark" test mode, switch to a non-debug build of LuaJIT:

export LD_LIBRARY_PATH=/usr/local/openresty/luajit/lib:$LD_LIBRARY_PATH

Such runtime environment settings are conventionally put into a custom ./go script at the root of each nginx C module project's source tree, as in:

#!/usr/bin/env bash

export PATH=$PWD/work/nginx/sbin:/opt/systemtap/bin:$PATH

export LD_LIBRARY_PATH=/usr/local/openresty/luajit/lib:$LD_LIBRARY_PATH
#export LD_LIBRARY_PATH=/usr/local/openresty-valgrind/luajit/lib:$LD_LIBRARY_PATH
#export TEST_NGINX_USE_VALGRIND=1

export TEST_NGINX_SLEEP=0.002
export TEST_NGINX_PORT=8080
export TEST_NGINX_TIMEOUT=5
export TEST_NGINX_RESOLVER=8.8.4.4

which nginx
nginx -V
ldd work/nginx/sbin/nginx|grep luajit

exec prove -I../test-nginx/lib "$@"

It is very convenient to comment or uncomment the environment settings on demand. It is much harder to mess your environment settings up.

Once the ./go script is ready, you can always run ./go -r t to run the full test suite or ./go t/foo.t to run a particular test file like t/foo.t (one can choose to run only an individual test block only in the foo.t file by temporarily inserting a --- ONLY section to that test block).

Those system environments whose names start with TEST_NGINX_ are those supported by the Test::Nginx::Socket test scaffold. You can find more details about this test scaffold here:

https://openresty.gitbooks.io/programming-openresty/content/testing/

The ngx-build script would try patching the nginx core with patches in the openresty/openresty and openresty/no-pool-nginx github repos which are checked out locally as the ../openresty/ and ../no-pool-nginx/ directories, respectively. But such patching process only happens when the local ./buildroot/nginx-* directory does not exist. So if you want to enforce patching the nginx core all over again (for example, when you toggle the values of the system environments NGX_BUILD_NO_DEBUG, NGX_BUILD_DTRACE, and/or NGX_BUILD_DISABLE_NO_POOL, then you must re-apply the patches for the nginx core. You can do that by wiping out the ./buildroot/nginx-* directories like this:

rm -rf buildroot/nginx-*

and then run the ./build13 script previously mentioned.

The Travis CI build files for most of our nginx C module projects are also making use of this ngx-build tool (through util/build.sh script, of course) and can serve as more examples. See for instance:

https://github.com/openresty/lua-nginx-module/blob/master/.travis.yml

Back to TOC

reindex

The reindex is used to unify the block title format of the test files, which are written based on Test::Base. And you can install this tool like ngx-build.

The reindex will unify the block title format of each test file according to the following conditions:

  • Ensure that all test blocks starting with === TEST {$index} are sequentially numbered starting from ${begin_index}.
  • Ensure 3 newlines between two blocks.
  • Ensure that there is a line break between the first test case and the separator(__DATA__ or __END__).

You can run reindex like this:

reindex /path/to/module/t*.t

Also you can set the begin index of test block in each test file by the -b {$index} command-line option, its default option is 1.

reindex -b 0 /path/to/module/t*.t

Back to TOC

Copyright & License

The bundle itself is licensed under the 2-clause BSD license.

Copyright (c) 2011-2017, Yichun "agentzh" Zhang (η« δΊ¦ζ˜₯) [email protected], OpenResty Inc.

This module is licensed under the terms of the BSD license.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Back to TOC

More Repositories

1

openresty

High Performance Web Platform Based on Nginx and LuaJIT
C
12,431
star
2

lua-nginx-module

Embed the Power of Lua into NGINX HTTP servers
C
11,224
star
3

nginx-tutorials

Nginx Tutorials
Perl
2,864
star
4

lua-resty-redis

Lua redis client driver for the ngx_lua based on the cosocket API
Lua
1,893
star
5

openresty-systemtap-toolkit

Real-time analysis and diagnostics tools for OpenResty (including NGINX, LuaJIT, ngx_lua, and more) based on SystemTap
Perl
1,653
star
6

headers-more-nginx-module

Set, add, and clear arbitrary output headers in NGINX http servers
C
1,636
star
7

openresty.org

Code and data for the openresty.org site
HTML
1,262
star
8

luajit2

OpenResty's Branch of LuaJIT 2
C
1,229
star
9

echo-nginx-module

An Nginx module for bringing the power of "echo", "sleep", "time" and more to Nginx's config file
C
1,162
star
10

docker-openresty

Docker tooling for OpenResty
Dockerfile
934
star
11

redis2-nginx-module

Nginx upstream module for the Redis 2.0 protocol
C
902
star
12

lua-resty-limit-traffic

Lua library for limiting and controlling traffic in OpenResty/ngx_lua
Lua
815
star
13

lua-resty-core

New FFI-based API for lua-nginx-module
Lua
797
star
14

stream-lua-nginx-module

Embed the power of Lua into NGINX TCP/UDP servers
C
723
star
15

lua-resty-mysql

Nonblocking Lua MySQL driver library for ngx_lua or OpenResty
Lua
703
star
16

stapxx

Simple macro language extentions to systemtap
Perl
692
star
17

sregex

A non-backtracking NFA/DFA-based Perl-compatible regex engine matching on large data streams
C
616
star
18

lua-resty-upstream-healthcheck

Health Checker for Nginx Upstream Servers in Pure Lua
Lua
513
star
19

lua-resty-websocket

WebSocket support for the ngx_lua module (and OpenResty)
Lua
503
star
20

lua-upstream-nginx-module

Nginx C module to expose Lua API to ngx_lua for Nginx upstreams
C
499
star
21

srcache-nginx-module

Transparent subrequest-based caching layout for arbitrary nginx locations.
C
474
star
22

opm

OpenResty Package Manager
Lua
458
star
23

test-nginx

Data-driven test scaffold for Nginx C module and OpenResty Lua library development
Perl
438
star
24

lua-resty-lrucache

Lua-land LRU Cache based on LuaJIT FFI
Lua
437
star
25

lua-resty-string

String utilities and common hash functions for ngx_lua and LuaJIT
Lua
426
star
26

lua-resty-upload

Streaming reader and parser for http file uploading based on ngx_lua cosocket
Lua
401
star
27

set-misc-nginx-module

Various set_xxx directives added to nginx's rewrite module (md5/sha1, sql/json quoting, and many more)
C
388
star
28

drizzle-nginx-module

an nginx upstream module that talks to mysql and drizzle by libdrizzle
C
336
star
29

openresty-gdb-utils

GDB Utilities for OpenResty (including Nginx, ngx_lua, LuaJIT, and more)
Python
335
star
30

lua-resty-balancer

A generic consistent hash implementation for OpenResty/Lua
Lua
325
star
31

lua-resty-dns

DNS resolver for the nginx lua module
Lua
321
star
32

programming-openresty

Programming OpenResty Book
Perl
317
star
33

lua-resty-lock

Simple nonblocking lock API for ngx_lua based on shared memory dictionaries
Lua
304
star
34

resty-cli

Fancy command-line utilities for OpenResty
Perl
263
star
35

replace-filter-nginx-module

Streaming regular expression replacement in response bodies
C
258
star
36

memc-nginx-module

An extended version of the standard memcached module that supports set, add, delete, and many more memcached commands.
C
213
star
37

lua-resty-memcached

Lua memcached client driver for the ngx_lua based on the cosocket API
Lua
210
star
38

encrypted-session-nginx-module

encrypt and decrypt nginx variable values
C
198
star
39

openresty-packaging

Official OpenResty packaging source and scripts for various Linux distributions and other systems
Makefile
176
star
40

rds-json-nginx-module

An nginx output filter that formats Resty DBD Streams generated by ngx_drizzle and others to JSON
C
153
star
41

xss-nginx-module

Native support for cross-site scripting (XSS) in an nginx
C
148
star
42

mockeagain

Mocking ideally slow network that only allows reading and/or writing one byte at a time
C
129
star
43

lua-resty-shell

Lua module for nonblocking system shell command executions
Perl
124
star
44

lua-tablepool

Lua table recycling pools for LuaJIT
Perl
112
star
45

lua-redis-parser

Lua module for parsing raw redis responses
C
93
star
46

openresty-survey

OpenResty Web App for OpenResty User Survey
HTML
90
star
47

lua-ssl-nginx-module

NGINX C module that extends ngx_http_lua_module for enhanced SSL/TLS capabilities
Lua
86
star
48

opsboy

A rule-based sysadmin tool that helps setting up complex environment for blank machines
Perl
85
star
49

no-pool-nginx

replace nginx's pool mechanism with plain malloc & free to help tools like valgrind
Shell
77
star
50

stream-echo-nginx-module

TCP/stream echo module for NGINX (a port of ngx_http_echo_module)
C
69
star
51

meta-lua-nginx-module

Meta Lua Nginx Module supporting both Http Lua Module and Stream Lua Module
C
66
star
52

array-var-nginx-module

Add support for array-typed variables to nginx config files
C
66
star
53

lemplate

OpenResty/Lua template framework implementing Perl's TT2 templating language
Perl
54
star
54

openresty-con

JavaScript
48
star
55

nginx-dtrace

An nginx fork that adds dtrace USDT probes
C
44
star
56

orbpf-ko

The orbpf (eBPF+) Linux kernel module from OpenResty Inc.
C
37
star
57

lua-resty-memcached-shdict

Powerful memcached client with a shdict caching layer and many other features
Lua
33
star
58

lua-resty-signal

Lua library for killing or sending signals to UNIX processes
Perl
32
star
59

lua-resty-shdict-simple

Simple applicaton-oriented interface to the OpenResty shared dictionary API
Perl
32
star
60

luajit2-test-suite

OpenResty's LuaJIT test suite based on Mike Pall's LuaJIT tests
Lua
29
star
61

ngx_postgres

OpenResty's fork of FRiCKLE/ngx_postgres
C
26
star
62

rds-csv-nginx-module

Nginx output filter module to convert Resty-DBD-Streams (RDS) to Comma-Separated Values (CSV)
C
22
star
63

showman-samples

Sample screenplay files for generating our public video tutorials using OpenResty Showman
20
star
64

lua-rds-parser

Resty DBD Stream (RDS) parser for Lua written in C
C
19
star
65

redis-nginx-module

8
star
66

AB-test-http

test http requests between two systems.
Perl
5
star
67

transparency

2
star