1 Star 14 Fork 1

nature-lang / parker

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Parker

轻量级打包工具与容器运行时,一条命令将工作目录打包成可执行文件,并以轻量级容器的方式直接运行在目标机器上。

示例是一个 c 语言编写的 ip 解析服务 gcc -o ipservice,其依赖 ipdb 资源文件。

使用 parker 将可执行文件 ipservice 和其依赖的 assert 压缩并打包成新的可执行文件 ipservice-c。

在目标机器上运行 ipservice-c 将会生成一个轻量的容器环境来运行原始的 ipservice 服务和其关联的资源文件。

⚙️ 安装

github releases 中下载并解压 Parker 安装包。推荐将解压后的 parker 文件夹移动到/usr/local/下,并将/usr/local/parker/bin目录加入到系统环境变量。

> parker --version
1.0.1

📦 使用

cd 到工作目录,执行 parker :target 该命令将 :target 连同当前的工作目录一起打包成一个 :target-c 可执行文件,将可执行文件放到目标机器上运行即可。

> cd :workdir && parker :target

示例

上面的可执行文件+资源文件打包是标准使用示例,当然也有一些非标准的使用方式,比如以一个 python3.11 编写的 server 为例子

> tree .
├── bar.png
├── foo.txt
├── python # cp /usr/bin/python3.11 ./
└── server.py

0 directories, 4 files

server.py 内容如下

from http.server import SimpleHTTPRequestHandler, HTTPServer

def run():
    print("listen on http://127.0.0.1:8000")
    server_address = ('127.0.0.1', 8000)
    httpd = HTTPServer(server_address, SimpleHTTPRequestHandler)
    httpd.serve_forever()

run()

cd 到工作目录中执行 parker python,你将会得到一个 python-c 文件,这就是打包好的可执行文件,将其上传到目标机器中执行即可。

> parker python
python-c
├── server.py
├── python
├── foo.txt
└── bar.png
🍻 parker successful

------------------------------------------------------------------------ move pyhon-c to target
> tree .
.
└── python-c

0 directories, 1 file

------------------------------------------------------------------------ run python-c
> ./python-c server.py
listen on http://127.0.0.1:8000

此处 python-c 会将参数传递给 python 进程。

❗️ parker 不解决 python 的动态编译问题。

🚢 运行说明

python-c 是 parker 构建的轻量级容器运行时,并且 python-c 是一个静态编译的可执行文件。其在执行时通过 linux namespace 创建了一个隔离环境,并解压工作目录运行目标 python 。

python-c 将监听 python 主进程的运行,一旦 python 进程停止或异常,python-c 会通过 cgroup 清理容器环境,并清理 python 的所有子进程。

用户像 python-c 中传递的所有参数和信号都会原封不动的传递给 python 进程。

🐧 环境依赖

容器运行时依赖 cgroup 和 namespace,需要 linux 内核版本大于 2.6.24。并且正确挂载了 cgroup。检查文件 /sys/fs/cgroup/cgroup.controllers/sys/fs/cgroup/freezer 中任意一个目录存在即可。

测试环境: ubuntu:22 / ubuntu:20

🛠️ 源码构建

源代码由编程语言 nature 开发,nature 编译器版本需要 >= 0.4.0。安装完成后在源码目录执行 make amd64 && make install 即可安装到 /usr/local/parker 目录下。

nature 目前主要支持 amd64 构建,nature 构建的可执行文件体积更小,效率更高。如果需要构建等其他架构, 主仓库提供了 golang 版本实现。

🎉 Thinks

nature 是现代系统级编程语言与编译器,携手 c 一起进行高性能且高效的开发工作。

nature 社区可用版本即将发布,现在也可以先行体验并提供改进意见。并邀您一起进行标准库贡献,所有的标准库贡献都会合并至主仓库。

邀您加入 nature 编程语言交流群,添加微信号 nature-lang

🪶 License

This project is open-sourced software licensed under the MIT license.

Copyright (c) 2020-2023 WEIWENHAO, all rights reserved.

Copyright (c) 2020-2023 WEIWENHAO, all rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

🍀 轻量级打包工具与容器运行时,一条命令将工作目录打包成可执行文件 展开 收起
其他 等 4 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
其他
1
https://gitee.com/nature-lang/parker.git
git@gitee.com:nature-lang/parker.git
nature-lang
parker
parker
master

搜索帮助