选择executor类型

本文档描述了可用的executor类型(docker,,赢得dows苹果系统)在以下部分中:

Overview

一种n执行者typedefines the underlying technology or environment in which to run a job. CircleCI enables you to run jobs in one of four environments:

  • 在Docker图像中(docker)
  • Within a Linux virtual machine (VM) image ()
  • 在macOS VM映像(苹果系统)
  • Within a windows VM image (赢得dows)

可以为每个作业指定不同的executor类型'.circleci / config.yml'by specifying the executor type and an appropriate image. Animage是一个包装系统,具有创建运行环境的说明。一种container要么virtual machine是用于图像的运行实例的术语。例如,您可以为每个作业指定executor类型和图像:

  • Jobs that require Docker images (docker)可以使用Node.js或python的图像。该预构建的Circleci Docker图像从CircleCI码头工人hub will help you get started quickly without learning all about Docker. These images are not a full operating system, so they will generally make building your software more efficient.
  • 需要完整的Linux虚拟机(VM)图像的作业() may use an Ubuntu version such as 16.04.
  • Jobs that require a macOS VM image (苹果系统)可以使用Xcode版本,例如10.0.0。

Using Docker

docker键将Docker定义为使用Docker容器运行作业的底层技术。容器是您指定的Docker映像的实例,并且配置中列出的第一个映像是所有步骤运行的主要容器图像。如果您是Docker的新手,请参阅Docker概述文档for concepts.

Docker increases performance by building only what is required for your application. Specify a Docker image in your.circleci / config.yml.将生成所有步骤运行的主容器的文件:

jobs:建立:docker:-image:建立pack-deps:trusty

In this example, all steps run in the container created by the first image listed under the建立工作。为了使转变容易,Circleci在Docker集线器上维护便利图像以获得流行语言。看到Using Pre-Built CircleCI Docker Imagesfor the complete list of names and tags. If you need a Docker image that installs Docker and has Git, consider usingdocker:stable-git,这是一个官方的Docker Image.

Docker Image.best practices

  • If you encounter problems with rate limits imposed by your registry provider, usingauthenticated docker pulls可能会授予更高的限制。

  • Circleci.has partnered with Docker to ensure that our users can continue to access Docker Hub without rate limits. As of November 1st 2020, with few exceptions, you should not be impacted by any rate limits when pulling images from Docker Hub through CircleCI. However, these rate limits may go into effect for CircleCI users in the future. That’s why we’re encouraging you and your team to添加Docker Hub身份验证to your CircleCI configuration and consider upgrading your Docker Hub plan, as appropriate, to prevent any impact from rate limits in the future.

  • 一种void using mutable tags like最新要么1作为您的图像版本config.yml.file。It is best practice to use precise image versions or digests, likeredis:3.2.7要么redis @ sha256:95f0c9434f37db0a4f ...as shown in the examples. Mutable tags often lead to unexpected changes in your job environment. CircleCI cannot guarantee that mutable tags will return an up-to-date version of an image. You could specify高山:最新和actually get a stale cache from a month ago.

  • 如果您在执行期间安装其他工具时,您遇到了运行时代的升高,则最好使用练习Building Custom Docker Images Documentation使用预加载在容器中的工具创建自定义映像以满足作业要求。

More details on the Docker Executor are available in theConfiguring CircleCI文件。

Using multiple Docker images

可以为您的作业指定多个图像。例如,指定多个图像(例如,您需要为测试或其他其他必需的服务使用数据库)。在多图像配置作业中,所有步骤都在列出的第一张图像创建的容器中执行。所有容器都在公共网络中运行,并且每个公开的端口都将可用localhost来自A.primary container

jobs:建立:docker:# Primary container image where all steps run.-image:建立pack-deps:trusty# Secondary container image on common network.-image:mongo:2.6.8-jessie命令:[蒙多,--smallfiles]Working_Directory.:~/脚步:# command will execute in trusty container# and can access mongo on localhost-run:睡眠5 && nc -vz localhost27017

Docker Images may be specified in three ways, by the image name and version tag on Docker Hub or by using the URL to an image in a registry:

Public convenience images on Docker Hub

  • name:tag
    • circleci/node:7.10-jessie-browsers
  • name@digest
    • redis @ sha256:34057dd7e135ca41 ...

Docker Hub上的公共图像

  • name:tag
    • 高山:3.4
  • name@digest
    • redis @ sha256:54057dd7e125ca41 ...

公共码头注册管理机构

  • image_full_url:tag
    • gcr.io/google-containers/busybox:1.24
  • image_full_url @ digest.
    • gcr.io/google-containers/busybox@sha256:4bdd623e848417d9612...

Nearly all of the public images on Docker Hub and Docker Registry are supported by default when you specify thedocker:键在yourconfig.yml.file. If you want to work with private images/registries, please refer toUsing Docker Authenticated Pulls

内存disks

RAM磁盘可用/ mnt / ramdiskthat offers a临时文件存储范式, similar to using/dev/shm。使用RAM磁盘可以帮助加快构建,只要该resource_classyou are using has enough memory to fit the entire contents of your project (all files checked out from git, dependencies, assets generated etc).

该simplest way to use this RAM disk is to configure theWorking_Directory.一份工作/ mnt / ramdisk:

jobs:建立:docker:-image:高寒Working_Directory.:/ mnt / ramdisk脚步:-run:|echo '#!/bin/sh' > run.shecho 'echo Hello world!' >> run.shchmod + x run.sh-run:。/run.sh

Docker benefits and limitations

Docker还拥有内置的图像缓存,并使您能够通过构建,运行和发布Docker图像Remote Docker。考虑您的应用程序的要求。如果您的申请是如下,Docker可能是正确的选择:

  • Your application is self-sufficient
  • 您的应用程序需要额外的服务进行测试
  • 您的应用程序作为Docker图像分发(需要使用Remote Docker)
  • You want to usedocker-compose(requires usingRemote Docker)

Choosing Docker limits your runs to what is possible from within a Docker container (including ourRemote Dockerfeature). For instance, if you require low-level access to the network or need to mount external volumes consider using

使用权衡来使用dockerimage versus an Ubuntu-basedimage as the environment for the container, as follows:

能力 docker
Start time 瞬间 30-60 sec
清洁环境 Yes Yes
Custom images Yes(1) 没有
Build Docker images Yes(2) Yes
完全控制工作环境 没有 Yes
全root访问 没有 Yes
Run multiple databases Yes(3) Yes
运行同一软件的多个版本 没有 Yes
Docker Layer Caching Yes Yes
运行特权容器 没有 Yes
使用Docker撰写卷 没有 Yes
可配置资源(CPU / RAM) Yes Yes

(1)看到使用自定义Docker图像

(2)Requires usingRemote Docker

(3)While you can run multiple databases with Docker, all images (primary and secondary) share the underlying resource limits. Performance in this regard will be dictated by the compute capacities of your container plan.

有关的更多信息,请参阅下面的下一节。

一种vailable Docker resource classes

resource_class键允许您为每个作业配置CPU和RAM资源。在Docker中,可以使用以下资源类:

Class vcpus. 内存
small 1 2GB
medium (default) 2 4GB
medium+ 3 6GB
4 8GB
xlarge 8 16 GB
2xlarge(2) 16. 32GB
2xlarge +.(2) 20. 40GB

Where example usage looks like the following:

jobs:建立:docker:-image:建立pack-deps:trustyresource_class:xlarge脚步:# ... other config

使用机器

option runs your jobs in a dedicated, ephemeral VM that has the following specifications:

Class vcpus. 内存
medium (default) 2 7.5GB
4 15GB.
xlarge 8 32GB
2xlarge 16. 64 gb

使用遗嘱执行人给your application full access to OS resources and provides you with full control over the job environment. This control can be useful in situations where you need full access to the network stack, for example to listen on a network interface, or to modify the system withsysctl命令s. To find out about migrating a project from using the Docker executor to using, see theExecutor Migration from Docker to Machine文件。

使用执行者also means that you get full access to the Docker process. This allows you to run privileged Docker containers and build new Docker images.

没有te: Usingmay require additional fees in a future pricing update.

To use the machine executor, set the.circleci / config.yml.:

version:2.1jobs:建立::image:ubuntu-1604:202007-01

You can view the list of available images这里

以下示例使用图像并启用Docker Layer Caching(DLC)当您在工作或工作流程中构建Docker图像时很有用。注意:Check ourpricing pageto see which plans include the use of Docker Layer Caching.

version:2.1jobs:建立::image:ubuntu-1604:202007-01docker_layer_caching.:真正# default - false

注意:imageCircleci的私人安装不支持密钥。看看VM服务文档for more information.

使用MacOS.

一种vailable on CircleCI Cloud - not currently available on self-hosted installations

使用苹果系统执行者allows you to run your job in a macOS environment on a VM. You can also specify which version of Xcode should be used. See theSupported Xcode Versions section of the Testing iOS文档有关运行每个特定版本的Xcode的VM的技术规范的完整版本号和信息的信息。

jobs:建立:苹果系统:xcode:11.3.0脚步:#命令将在MacOS容器中执行# with Xcode 11.3 installed-run:xcodebuild -version

使用Windows executor

使用赢得dowsExecutor允许您在Windows环境中运行您的作业。以下是一个示例配置,它将运行一个简单的Windows作业。CONFIC中使用Windows Executor的语法因您是使用的吗?

  • Circleci.云– config version 2.1.
  • 自托管安装带有Config 2.0的Circleci服务器 - 此选项是使用该选项的实例执行者with a Windows image –Introduced in CircleCI Server v2.18.3
version:2.1# Use version 2.1 to enable Orb usage.绿色原子:赢得:circleci/windows@2.2.0#Windows ORB给您使用Windows executor开始的所有内容。jobs:建立:# name of your job执行者:赢得/default# executor type脚步:#命令在Windows虚拟机环境中运行-checkout-run:写主机'Hello,Windows'
version:2jobs:建立:# name of your job:image:Windows默认# Windows machine imageresource_class:Windows.Medium.脚步:#命令在Windows虚拟机环境中运行-checkout-run:写主机'Hello,Windows'

云users will notice the Windows Orb is used to set up the Windows executor to simplify the configuration. SeeWindows ORB详细信息页面更多细节。

Circleci.Server users should contact their system administrator for specific information about the image used for Windows jobs. The Windows image is configured by the system administrator, and in the CircleCI config is always available as theWindows默认图像名称。

Using GPUs

Circleci.云has execution environments with Nvidia GPUs for specialized workloads. The hardware is Nvidia Tesla T4 Tensor Core GPU, and our GPU executors come in both Linux and Windows VMs.

version:2.1jobs:建立::resource_class:gpu.nvidia.smallimage:Ubuntu-1604-CUDA-10.1:201909-23脚步:-run:nvidia-smi
version:2.1绿色原子:赢得:circleci/windows@2.3.0jobs:建立:执行者:赢/ gpu-nvidia脚步:-run:'&"C:\ProgramFiles\NVIDIA公司\ nvsmi \ nvidia-smi.exe“'

Customers using CircleCI server can configure their VM service to use GPU-enabled machine executors. SeeRunning GPU Executors in Server

看到also

组态Reference