我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们
文章版本: Enterprise Server 2.20

Creating a pre-receive hook environment

To execute pre-receive hooks, use either the default pre-receive environment, or create a custom environment.

本文内容

A pre-receive environment for GitHub Enterprise Server is a Linux chroot environment. Because pre-receive hooks execute on every push event, they should be fast and lightweight. The environment needed for such checks will typically be minimal.

GitHub Enterprise Server provides a default environment which includes these packages: awk, bash, coreutils, curl, find, gnupg, grep, jq, sed.

If you have a specific requirement that isn't met by this environment, such as support for a particular language, you can create and upload your own 64-bit Linux chroot environment.

Creating a pre-receive hook environment using Docker

You can use a Linux container management tool to build a pre-receive hook environment. This example uses Alpine Linux and Docker.

  1. 确保 Docker 在本地安装

  2. Create the file Dockerfile.alpine-3.3 that contains this information:

    FROM gliderlabs/alpine:3.3
    RUN apk add --no-cache git bash
    
  3. From the working directory that contains Dockerfile.alpine-3.3, build an image:

    $ 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
  4. Create a container:

    $ docker create --name pre-receive.alpine-3.3 pre-receive.alpine-3.3 /bin/true
  5. Export the Docker container to a gzip compressed tar file:

    $ docker export pre-receive.alpine-3.3 | gzip > alpine-3.3.tar.gz

    This file alpine-3.3.tar.gz is ready to be uploaded to the GitHub Enterprise Server appliance.

Creating a pre-receive hook environment using chroot

  1. Create a Linux chroot environment.

  2. Create a gzip compressed tar file of the chroot directory.

    $ cd /path/to/chroot
    $ tar -czf /path/to/pre-receive-environment.tar.gz .

    Notes:

    • Do not include leading directory paths of files within the tar archive, such as /path/to/chroot.
    • /bin/sh must exist and be executable, as the entry point into the chroot environment.
    • Unlike traditional chroots, the dev directory is not required by the chroot environment for pre-receive hooks.

For more information about creating a chroot environment see "Chroot" from the Debian Wiki, "BasicChroot" from the Ubuntu Community Help Wiki, or "Installing Alpine Linux in a chroot" from the Alpine Linux Wiki.

Uploading a pre-receive hook environment on GitHub Enterprise Server

  1. 在任何页面的右上角,单击
    用于访问站点管理员设置的火箭图标
  2. 在左侧边栏中,单击 Enterprise(企业)
    站点管理设置中的 Enterprise(企业)选项卡
  3. 在企业帐户侧边栏中,单击 Settings(设置)
    企业帐户侧边栏中的“设置”选项卡
  4. 在“ Settings(设置)”下,单击 Hooks(挂钩)
    企业帐户设置侧边栏中的 Hooks(挂钩)选项卡
  5. Click Manage environments.
    Manage Environments
  6. Click Add environment.
    Add Environment
  7. Enter the desired name in the Environment name field.
    Environment name
  8. Enter the URL of the *.tar.gz file that contains your environment.
    Upload environment from a URL
  9. Click Add environment.
    Add environment button

Uploading a pre-receive hook environment via the administrative shell

  1. Upload a readable *.tar.gz file that contains your environment to a web host and copy the URL or transfer the file to the GitHub Enterprise Server appliance via scp. When using scp, you may need to adjust the *.tar.gz file permissions so that the file is world readable.

  2. Connect to the administrative shell.

  3. Use the ghe-hook-env-create command and type the name you want for the environment as the first argument and the full local path or URL of a *.tar.gz file that contains your environment as the second argument.

    admin@ghe-host:~$ ghe-hook-env-create AlpineTestEnv /home/admin/alpine-3.3.tar.gz
    > Pre-receive hook environment 'AlpineTestEnv' (2) has been created.

问问别人

找不到要找的内容?

联系我们