#script #run-command #sandbox #package #command-line-tool #docker #packages

app envyr

Envyr是一个用于自动打包应用程序并在沙箱环境中运行的工具

9个版本

0.1.8 2024年4月25日
0.1.7 2024年3月28日
0.1.6 2024年1月17日
0.1.1 2023年12月20日
0.1.0 2023年7月25日

#233 in 开发工具

Download history 57/week @ 2024-04-26 7/week @ 2024-05-03 2/week @ 2024-05-17 1/week @ 2024-05-24 47/week @ 2024-07-26 4/week @ 2024-08-02

51个月下载量

Apache-2.0

52KB
1.5K SLoC

Envyr

Envyr是一个用于自动打包应用程序并在沙箱环境中运行的工具。 该项目正在积极开发中,可能会出现错误。

是否曾想在没有克隆、安装依赖项等操作的情况下直接运行git仓库中的脚本?Envyr可以为您完成这些操作。它可以检测语言、安装依赖项,并在沙箱环境中为您运行项目。

例如

envyr run [email protected]:tchaudhry91/python-sample-script.git --autogen -- https://blog.tux-sudo.com > my_blog.html

此命令将检索仓库,构建沙箱(目前支持docker/podman),并运行脚本!有关支持的特性的更多信息,请参阅以下内容。

安装

可以使用Cargo安装此项目。将很快提供更多预构建的包。

用法

Envyr目前具有内置智能,可以运行以下类型的应用程序

1. Python脚本

Envyr将自动检测并运行您的Python脚本。

检测:

  • 如果项目包含.py文件,它将被检测为Python脚本。
  • 如果项目包含requirements.txt文件,它将在执行前在沙箱中安装。
  • 如果没有找到requirements.txt文件,它将尝试使用生成一个。
  • 入口点通过if __name__ == __main__或shebang语句检测。通过优先级来打破平局,并可以使用-code-x标志来覆盖。

示例:

  • 以下是一个Envyr运行公共仓库中Python脚本的情况。
$ envyr run --autogen [email protected]:sivel/speedtest-cli.git                    

Retrieving speedtest.net configuration...
Testing from xyz (xyz.xyz.xyz.xyz)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
^C
Cancelling...

第一次运行将克隆仓库并构建沙箱。后续运行将几乎瞬间完成。

2. Node JS脚本

Envyr将自动检测并运行您的Node.js脚本。

检测:

  • 项目需要包含package.json文件。
  • 该文件用于安装依赖项并确定入口点(从package.json中的main)。

3. Shell脚本

检测:

  • 基于Shebang。
  • 待定:一种检测依赖项的方法。在生成时仍可以手动提供。

4. 将来还有更多。

配置选项

$ envyr -h
A tool to automagically create 'executable' packages for your scripts.

Usage: envyr [OPTIONS] <COMMAND>

Commands:
  generate  Generate the associated meta files. Overwrites if re-run.
  alias     Subcommands for aliases.
  run       Run the package with the given executor.
  help      Print this message or the help of the given subcommand(s)

Options:
  -v, --verbose  Emit Envyr logs to stdout. Useful for debugging. But may spoil pipes.
  -h, --help     Print help
  -V, --version  Print version

运行包

$ envyr run -h
Run the package with the given executor.

Usage: envyr run [OPTIONS] <PROJECT_ROOT> [-- <ARGS>...]

Arguments:
  <PROJECT_ROOT>  The location to the project. Accepts, local filesystem path/git repos.
  [ARGS]...       

Options:
  -s, --sub-dir <SUB_DIR>          relative sub-directory to the project_root, useful if you're working with monorepos.
  -t, --tag <TAG>                  The tag of the package to run. Accepts git tags/commits. Defaults to latest. [default: latest]
      --refresh                    refresh code cache before running.
      --alias <ALIAS>              Upon successful completion, record this run command as an alias. To allow usage of `envyr run <alias>` in the future.
  -e, --executor <EXECUTOR>        [default: docker] [possible values: docker, nix, native]
      --autogen                    Attempt to automatically generate the package metadata before running. This overwrites existing metadata.
      --fs-map [<FS_MAP>...]       Mount the given directory as a volume. Format: host_dir:container_dir. Allows multiples. Only applicable on Docker Executor.
      --port-map [<PORT_MAP>...]   Map ports to host system, Format host_port:source_port. Allows multiples. Only applicable on Docker Executor.
      --env-map [<ENV_MAP>...]     Environment variables to pass through, leave value empty to pass through the value from the current environment. Format: 'key=value' or 'key' (passwthrough). Allows multiples.
  -n, --name <NAME>                
  -i, --interpreter <INTERPRETER>  
  -x, --entrypoint <ENTRYPOINT>    
  -t, --type <PTYPE>               [possible values: python, node, shell, other]
  -h, --help                       Print help

大多数情况应通过自动检测来覆盖。如果--autogen不起作用,请使用覆盖。

提前生成包元数据

Generate the associated meta files. Overwrites if re-run.

Usage: envyr generate [OPTIONS] <PROJECT_ROOT>

Arguments:
  <PROJECT_ROOT>  The location to the project. Accepts, local filesystem path/git repos.

Options:
  -s, --sub-dir <SUB_DIR>          relative sub-directory to the project_root, useful if you're working with monorepos.
  -t, --tag <TAG>                  The tag of the package to run. Accepts git tags/commits. Defaults to latest. [default: latest]
      --refresh                    refresh code cache before running.
  -n, --name <NAME>                
  -i, --interpreter <INTERPRETER>  
  -x, --entrypoint <ENTRYPOINT>    
  -t, --type <PTYPE>               [possible values: python, node, shell, other]
  -h, --help                       Print help

生成命令通常旨在由可以提交由该命令生成的.envyr文件夹的作者使用。这允许其他人通过作者默认想要的(入口点/解释器)覆盖来运行此包。

别名 您可以为常见的运行命令生成别名,使其在日常使用中更便于操作。通过传递--alias标志,在成功运行特定包时创建新的别名。

$envyr run --alias sample --env-map=MYVAR --autogen git@github.com:tchaudhry91/python-sample-script.git -- https://blog.tux-sudo.com

这将把上述命令存储为一个名为sample的别名,可以按以下方式运行

$envyr run sample

别名也存储了args,但在需要时可以覆盖。

$envyr run sample -- https://test.com

可以使用以下方式管理别名

$envyr alias -h        2 ↵
Subcommands for aliases.

Usage: envyr alias <COMMAND>

Commands:
  list    List all aliases.
  delete  Delete an existing alias.
  help    Print this message or the help of the given subcommand(s)

Options:
  -h, --help  Print help

计划功能

  • 目前只有Docker/Podman可用作沙箱环境。也添加nix/native选项。
  • 更多语言
  • Bash脚本依赖检测。

请参阅问题跟踪器/项目板以获取更多信息。

依赖关系

~5–13MB
~158K SLoC