luarocks 简单使用&openresty 离线集成说明

luarocks支持的命令

luarocks --help
Usage: luarocks [-h] [--version] [--dev] [--server <server>]
       [--only-server <server>] [--only-sources <url>]
       [--namespace <namespace>] [--lua-dir <prefix>]
       [--lua-version <ver>] [--tree <tree>] [--local] [--global]
       [--verbose] [--timeout <seconds>] [--pin] [<command>] ...
 
LuaRocks 3.8.0, the Lua package manager
 
/usr/local/bin/luarocks - LuaRocks main command-line interface
 
Options:
   -h, --help            Show this help message and exit.
   --version             Show version info and exit.
   --dev                 Enable the sub-repositories in rocks servers for
                         rockspecs of in-development versions.
   --server <server>     Fetch rocks/rockspecs from this server (takes priority
                         over config file).
   --only-server <server>
                         Fetch rocks/rockspecs from this server only (overrides
                         any entries in the config file).
   --only-sources <url>  Restrict downloads to paths matching the given URL.
   --namespace <namespace>
                         Specify the rocks server namespace to use.
   --lua-dir <prefix>    Which Lua installation to use.
   --lua-version <ver>   Which Lua version to use.
   --tree <tree>         Which tree to operate on.
   --local               Use the tree in the user's home directory.
                         To enable it, see '/usr/local/bin/luarocks help path'.
   --global              Use the system tree when `local_by_default` is `true`.
   --verbose             Display verbose output of commands executed.
   --timeout <seconds>   Timeout on network operations, in seconds.
                         0 means no timeout (wait forever). Default is 30.
   --pin                 Create a luarocks.lock file listing the exact versions
                         of each dependency found for this rock (recursively),
                         and store it in the rock's directory. Ignores any
                         existing luarocks.lock file in the rock's sources.
 
Commands:
   help                  Show help for commands.
   completion            Output a shell completion script.
   build                 Build/compile a rock.
   config                Query information about the LuaRocks configuration.
   doc                   Show documentation for an installed rock.
   download              Download a specific rock file from a rocks server.
   init                  Initialize a directory for a Lua project using
                         LuaRocks.
   install               Install a rock.
   lint                  Check syntax of a rockspec.
   list                  List currently installed rocks.
   make                  Compile package in current directory using a rockspec.
   new_version           Auto-write a rockspec for a new version of a rock.
   pack                  Create a rock, packing sources or binaries.
   path                  Return the currently configured package path.
   purge                 Remove all installed rocks from a tree.
   remove                Uninstall a rock.
   search                Query the LuaRocks servers.
   show                  Show information about an installed rock.
   test                  Run the test suite in the current directory.
   unpack                Unpack the contents of a rock.
   upload                Upload a rockspec to the public rocks repository.
   which                 Tell which file corresponds to a given module name.
   write_rockspec        Write a template for a rockspec file.
 
Variables:
   Variables from the "variables" table of the configuration file can be
   overridden with VAR=VALUE assignments.
 
Run 'luarocks' without any arguments to see the configuration.

几个常用命令

luarocks 包含的命令不少,很多我们不是很关注

luarocks init // 创建一个模版项目,方便上手的
luarocks pack  // 基于rocksspec 构建一个包,包含了源码文件,我们可以基于次实现离线安装
luarocks unpack //  解压一个使用pack 打包的包,
luarocks install  // 可以安装luarocks 仓库、rockspec 以及pack 的
luarocks upload // 进行包的上传(仓库)
luarocks list  // 查看安装的包
luarocks show // 查看安装包的信息
luarocks remove // 移除安装的包
luarocks new_version  // 对于luarocks 项目提升版本号,比如集成发布很方便

openresty 集成说明

对于openresty 集成包含了一些几种

* 基于容器all-in-one 已经包含了一个luarocks了(openresty 官方构建好的)
* 自己构建的luarocks (注意编译处理,很重要,不然查找肯定会有问题的)
对于具体包的安装我们还会分几类: 支持基于网络的,以及离线情况
  • 支持openresty luarocks 的构建
wget https://luarocks.org/releases/luarocks-3.8.0.tar.gz
tar -xzvf luarocks-3.8.0.tar.gz
cd luarocks-3.8.0
./configure --prefix=/usr/local/openresty/luajit \
    --with-lua=/usr/local/openresty/luajit/ \
    --lua-suffix=jit \
    --with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1
make
sudo make install
  • luarocks 离线包制作
    会自动下载代码文件,基于source 定义
 
luarocks pack lua-resty-http-0.17.0.beta.1-0.rockspec   
  • 安装
luarocks install lua-resty-http-0.17.0.beta.1-0.src.rock

说明

以上是一个简单的使用,同时说明下luarocks 集成openresty 的玩法, 以及离线包安装说明,当然openresty 官方也提供了opm 包管理
但是目前来说并不是特别的好,大家使用比较多的还是luarocks

参考资料

https://github.com/luarocks/luarocks/wiki/Installation-instructions-for-Unix
https://luarocks.org/modules/pintsized/lua-resty-http
https://github.com/rongfengliang/luarockcs-first-package

posted on 2022-05-04 10:28  荣锋亮  阅读(774)  评论(0编辑  收藏  举报

导航