创建预接收挂钩环境
要执行预接收挂钩,请使用默认的预接收环境,或者创建自定义环境。
本文内容
GitHub Enterprise Server 的预接收环境是 Linux chroot 环境。 由于预接收挂钩会在每个推送事件上执行,因此它们应该快速且轻量化。 这类检查需要的环境通常极少。
GitHub Enterprise Server 提供了一个默认环境,其中包括以下包:awk、bash、coreutils、curl、find、gnupg、grep、jq、sed。
如果您具有此环境未满足的特定要求(例如对特定语言的支持),则可以创建并上传您自己的 64 位 Linux chroot 环境。
使用 Docker 创建预接收挂钩环境
您可以使用 Linux 容器管理工具来构建预接收挂钩环境。 此示例使用 Alpine Linux 和 Docker。
- 
创建包含此信息的文件 Dockerfile.alpine-3.3:FROM gliderlabs/alpine:3.3 RUN apk add --no-cache git bash
- 
从包含 Dockerfile.dev的工作目录中,构建一个镜像:$ docker build -f Dockerfile.alpine-3.3 -t pre-receive.alpine-3.3 . > Sending build context to Docker daemon 12.29 kB > Step 1 : FROM gliderlabs/alpine:3.3 > ---> 8944964f99f4 > Step 2 : RUN apk add --no-cache git bash > ---> Using cache > ---> 0250ab3be9c5 > Successfully built 0250ab3be9c5
- 
创建一个容器: $ docker create --name pre-receive.alpine-3.3 pre-receive.alpine-3.3 /bin/true
- 
将 Docker 容器导出到 gzip压缩的tar文件:$ docker export pre-receive.alpine-3.3 | gzip > alpine-3.3.tar.gz此文件 alpine-3.3.tar.gz已准备好上传到 GitHub Enterprise Server 设备。
使用 chroot 创建预接收挂钩环境
- 
创建 Linux chroot环境。
- 
Create a gzipcompressedtarfile of thechrootdirectory.$ cd /path/to/chroot $ tar -czf /path/to/pre-receive-environment.tar.gz .注: - Do not include leading directory paths of files within the tar archive, such as /path/to/chroot.
- /bin/shmust exist and be executable, as the entry point into the chroot environment.
- Unlike traditional chroots, the devdirectory is not required by the chroot environment for pre-receive hooks.
 
- Do not include leading directory paths of files within the tar archive, such as 
关于创建 chroot 环境的更多信息,请参阅 Debian Wiki 中的“Chroot”、Ubuntu 社区帮助 Wiki 中的“BasicChroot”,或者 Alpine Linux Wiki 中的“在 chroot 中安装 Alpine Linux”。
在 GitHub Enterprise Server 上上传预接收挂钩环境
- 
在任何页面的右上角,单击 。  
- 
在左侧边栏中,单击 Business(业务)。  
- 
在企业帐户名称下,单击 Settings(设置)。  
- 
在左侧侧边栏中,单击 Hooks。  
- 
单击 Manage environments。  
- 
单击 Add environment。  
- 
在 Environment name 字段中输入所需的名称。  
- 
输入包含您的环境的 * .tar.gz文件的 URL。 
- 
单击 Add environment。  
通过管理 shell 上传预接收挂钩环境
- 
将包含您的环境的可读 * .tar.gz文件上传到 web 主机并复制 URL 或通过scp将文件传送到 GitHub Enterprise Server 设备。 使用scp时,您可能需要调整* .tar.gz文件权限,以使该文件全局可读。
- 
连接到管理 shell。 
- 
使用 ghe-hook-env-create命令并输入所需的环境名称作为第一个参数,然后将包含环境的* .tar.gz文件的完整本地路径或 URL 作为第二个参数。admin@ghe-host:~$ ghe-hook-env-create AlpineTestEnv /home/admin/alpine-3.3.tar.gz > Pre-receive hook environment 'AlpineTestEnv' (2) has been created.