本文共 27851 字,大约阅读时间需要 92 分钟。
ar.drone2.0
is an open-source container-native CI/CD platform written in . It works with configuration files written in YAML, JSON, , or , which define multiple build pipelines consisting of a number of steps.
是使用编写的开源容器本机CI / CD平台。 它与使用YAML,JSON, 或编写的配置文件一起使用,这些配置文件定义了由多个步骤组成的多个构建管道。
Drone integrates with multiple source code managers. Currently, three different SCMs are supported: (cloud/enterprise), (cloud/server), and . In general, each provider supports all Drone functionality.
Drone与多个源代码管理器集成。 当前,支持三种不同的SCM: (云/企业), (云/服务器)和 。 通常,每个提供商都支持所有Drone功能。
Drone also supports . These runners are not interchangeable (except with the simplest pipelines), because their configuration formats, features, and execution environments differ. Here is a brief summary of your options:
无人机还支持 。 这些运行程序是不可互换的(最简单的管道除外),因为它们的配置格式,功能和执行环境不同。 以下是您的选择的简要摘要:
is the stablest and most commonly used runner. It executes each build step in a new container.
是最稳定,最常用的赛跑者。 它在新容器中执行每个构建步骤。
is a newer (but still experimental) option. It has a similar syntax to the Docker runner and could integrate with .
是一个较新的(但仍在实验中)选项。 它具有与Docker运行程序相似的语法,并且可以与集成。
executes commands directly on the host. This runner does not provide isolation between builds, and should only be used with trusted repositories that are not suitable for running within Docker (note that you may want to consider using privileged Docker containers before resorting to this option).
直接在主机上执行命令。 该运行程序不提供构建之间的隔离,仅应与不适合在Docker中运行的受信任存储库一起使用(请注意,在诉诸该选项之前,您可能需要考虑使用特权Docker容器)。
is similar to Exec, but it runs commands over SSH on a host separate from the one running the runner.
运行程序类似于Exec,但是它在运行运行程序的主机之外的主机上通过SSH运行命令。
creates a new Droplet for each build and runs commands within it. Note that if you only need the scaling features, you can still use the Docker runner but with the autoscaler enabled (more on this later).
运行程序为每个构建创建一个新的Droplet并在其中运行命令。 请注意,如果仅需要缩放功能,则仍可以使用Docker运行器,但启用了自动缩放器(稍后对此有更多介绍)。
allows you to execute builds on macOS machines in the cloud. This option is only useful for specialized workloads.
允许您在云中的macOS计算机上执行构建。 此选项仅对专业工作负载有用。
In this tutorial, you will set up a Drone CI/CD server for source code on , add a Docker runner, use to secure your instance, and then create a YAML pipeline. You will also encounter options to scale your runner using Drone Autoscaler and to store your logs on an S3-compatible server, such as DigitalOcean Spaces.
在本教程中,您将在为源代码设置Drone CI / CD服务器,添加Docker运行器,使用保护实例,然后创建YAML管道。 您还将遇到使用Drone Autoscaler缩放运行程序并将日志存储在S3兼容服务器(例如DigitalOcean Spaces)上的选项。
Before you start this tutorial, you will need:
在开始本教程之前,您需要:
One Ubuntu 20.04 server with at least 1GB of RAM, 2GB of free disk space, and a non-root user with sudo
priveliges. You can follow our .
一台Ubuntu 20.04服务器,至少具有1GB的RAM,2GB的可用磁盘空间以及一个具有sudo
特权的非root用户。 您可以按照我们的 。
Note: This tutorial will optionally configure Drone to use its with DigitalOcean, which will automatically scale your number of Droplets on an as-needed basis. If you choose this route, ensure that your account will remain within your limit. On DigitalOcean, the default limit for most users is 5 Droplets, but you can contact support and request an increase. To do so, visit your account’s Cloud Dashboard and find ACCOUNT in the left-hand menu. A sub-menu will appear; click Settings. A page will open that displays your account username and your Member since
date. Beneath this date you will see a line like Droplet Limit:5 Increase
. Click Increase to submit a request for more Droplets.
注意 :本教程将有选择地配置Drone以将其与DigitalOcean一起使用,这将根据需要自动缩放您的Droplet数量。 如果选择此路线,请确保您的帐户保持在限额内。 在DigitalOcean上,大多数用户的默认限制是5个Droplet,但是您可以联系支持并要求增加。 为此,请访问您帐户的Cloud Dashboard,然后在左侧菜单中找到ACCOUNT 。 将出现一个子菜单。 点击设置 。 将打开一个页面,显示您的帐户用户名和您的Member since
日期。 在此日期下方,您会看到类似Droplet Limit: 5 Increase
。 单击增加以提交更多液滴的请求。
Moreover, the Autoscaler path described in this tutorial will require a Personal Access Token from DigitalOcean. If you do choose to install Autoscaler, you can follow . Copy this key down before leaving the page; it will disappear once you leave or refresh the page and you will need to input it during Step 6.
此外,本教程中描述的Autoscaler路径将需要DigitalOcean提供的Personal Access Token。 如果您选择安装Autoscaler,则可以按照 。 离开页面之前,请向下复制该密钥; 一旦您离开或刷新页面,它就会消失,您需要在步骤6中输入它。
Lastly, if you choose not to install Drone’s Autoscaler feature, you will need at least another 2GB of RAM and 10GB of free disk space to ensure that you can run pipelines.
最后,如果您选择不安装Drone的Autoscaler功能,则至少需要另外2GB的RAM和10GB的可用磁盘空间,以确保您可以运行管道。
A domain (or subdomain) with an available A record pointed at your server’s IP. If you are managing your DNS on DigitalOcean then you can follow . This tutorial will use drone.your_domain
.
具有指向您服务器IP的可用A记录的域(或子域)。 如果要在DigitalOcean上管理DNS,则可以按照 。 本教程将使用drone.your_domain
。
Docker set up on your server. For instructions, you can follow this tutorial on .
在您的服务器上设置Docker。 有关说明,您可以按照本教程, 。
You will encounter an option to store your logs on DigitalOcean Spaces. To follow this step, you will need to , and you will also need to generate a . Copy down your Access Key and Secret somewhere safe. Your Secret will disappear once you leave or refresh this page, and you will need to input both values wherever you see your_s3_access_key
and your_s3_secret_key
. Alternately, you can use a different S3-compatible service, or skip this step—Step 3—entirely. Note that skipping this step is only advisable if you are trying out Drone or if you know that your build volume will be quite low.
您将遇到一个将日志存储在DigitalOcean Spaces上的选项。 要执行此步骤,您需要 ,并且还需要生成一个 。 将您的访问密钥和秘密复制到安全的地方。 离开或刷新此页面后,您的秘密将消失,并且您需要在看到your_s3_access_key
和your_s3_secret_key
任何地方输入两个值。 或者,您可以使用其他兼容S3的服务,也可以完全跳过此步骤-步骤3。 请注意,仅在尝试使用Drone或知道构建量会非常低时才建议跳过此步骤。
A account.
帐户。
To access code, authenticate users, and add webhooks to receive events, Drone requires an OAuth application for GitHub. For other providers, you can .
要访问代码,对用户进行身份验证以及添加Webhooks以接收事件,Drone需要GitHub的OAuth应用程序。 对于其他提供商,您可以 。
To set up an OAuth application for GitHub, log in to your GitHub account and then click on your user menu in the top-right. Click Settings, then find the Developer Settings category in the menu on the left, and then click OAuth Applications. Alternatively, you can navigate directly to .
要为GitHub设置OAuth应用程序,请登录到GitHub帐户,然后单击右上角的用户菜单。 点击设置 ,然后在左侧菜单中找到开发人员设置类别,然后点击OAuth应用程序 。 或者,您可以直接导航到 。
Next, create a new application. Click on the New OAuth App button in the upper-right corner and a blank form will appear.
接下来,创建一个新的应用程序。 单击右上角的“ 新建OAuth应用”按钮,将出现空白表格。
Use Drone
for your application name. Replace drone.your_domain
with your own domain, add a brief explanation of your app, and then add drone.your_domain/login
for your Authorization callback URL.
使用Drone
作为您的应用程序名称。 将drone.your_domain
替换为您自己的域,添加对应用程序的简要说明,然后为您的授权回调URL添加drone.your_domain/login
。
Click Register application and you will see a dashboard containing information about your application. Included here are your app’s Client ID and Client Secret. Copy these two values somewhere safe; you will need to use them in the following steps wherever you see your_github_client_id
and your_github_client_secret
.
单击注册应用程序 ,您将看到一个包含有关您的应用程序信息的仪表板。 其中包括您应用的“ 客户端ID”和“ 客户端密钥” 。 将这两个值复制到安全的地方; 只要您看到your_github_client_id
和your_github_client_secret
就需要在以下步骤中使用它们。
With your app now registered on GitHub, you are ready to configure Drone.
现在您的应用程序已在GitHub上注册,您就可以配置Drone了。
Now start preparing your Docker configurations, which will build your Drone server. First, generate a shared secret to authenticate runners with the main Drone instance. Create one using the openssl
command:
现在开始准备您的Docker配置,这将构建您的Drone服务器。 首先,生成一个共享密钥,以使用主要Drone实例对跑步者进行身份验证。 使用openssl
命令创建一个:
openssl
will generate a random 16-bit hexadecimal number. It will produce an output like this:
openssl
将生成一个随机的16位十六进制数。 它将产生如下输出:
Output 918...46c74b143a1719594d010ad24
Copy your own output to your clipboard. You will add it into the next command, where it will replace your_rpc_secret
.
将您自己的输出复制到剪贴板。 您将其添加到下一个命令中,它将替换your_rpc_secret
。
Now create your Drone configuration file. Rather than continually opening and closing this configuration file, we will leverage the tee
command, which will split your command’s output to your console while also appending it to Drone’s configuration file. An explanation will follow every command block in this tutorial, but you can find a detailed description of all available Drone options .
现在创建您的Drone配置文件。 我们不会继续打开和关闭此配置文件,而是利用tee
命令,该命令会将命令的输出拆分到控制台,同时还将其输出附加到Drone的配置文件中。 本教程中的每个命令块后面都会有一个说明,但是您可以找到所有可用Drone选项的详细说明。
Now begin building your Drone server’s configuration. Copy the following command to your terminal. Be sure to replace drone.your_domain
with your domain. Also replace your_github_client_id
and your_github_client_secret
with your GitHub OAuth credentials, and then replace your_rpc_secret
with the output from your openssl
command. Lastly, replace sammy_the_shark
with your GitHub username. This will grant you :
现在开始构建您的Drone服务器的配置。 将以下命令复制到您的终端。 请确保将drone.your_domain
替换为您的域。 还要用GitHub OAuth凭据替换your_github_client_id
和your_github_client_secret
,然后用openssl
命令的输出替换your_rpc_secret
。 最后,用您的GitHub用户名替换sammy_the_shark
。 这将授予您 :
DRONE_SERVER_HOST=drone.your_domain
DRONE_SERVER_HOST = drone.your_domain
DRONE_GITHUB_CLIENT_ID=your_github_client_id
DRONE_GITHUB_CLIENT_ID = your_github_client_id
DRONE_GITHUB_CLIENT_SECRET=your_github_client_secret
DRONE_GITHUB_CLIENT_SECRET = your_github_client_secret
DRONE_RPC_SECRET=your_rpc_secret
DRONE_RPC_SECRET = your_rpc_secret
DRONE_USER_CREATE=username:sammy_the_shark,admin:true
DRONE_USER_CREATE =用户名: sammy_the_shark ,admin:true
This command makes use of a . A heredoc uses the <<
redirection operator followed by an arbitrary word, where EOF
is conventionally used to represent end-of-file. It allows the user to write a multiline input, ending with the EOF
or whatever word the user has chosen. The quotes around the end-of-file affect how the text is parsed with regards to variable substitution, in a similar way to how they work around literals. It is a very useful tool, which in this case you are using to create a file and then add lines to it. Here you are adding your first Drone configurations and ending them with EOF
. This input is then redirected to the cat
command, and the output of the cat
command is then piped to the tee
command via the |
pipe operator. Heredocs are a great way to quickly create or append text to a file.
此命令使用 。 Heredoc使用<<
重定向运算符,后跟任意字,其中EOF
通常用于表示文件结尾。 它允许用户编写多行输入,以EOF
或用户选择的任何单词结尾。 文件结尾两边的引号以与变量处理文字相似的方式影响变量替换方面的文本解析方式。 这是一个非常有用的工具,在这种情况下,您将使用它来创建文件,然后向其中添加行。 在这里,您将添加第一个Drone配置,并以EOF
结尾。 然后,该输入被重定向到cat
命令,并且输出cat
然后命令被管道输送到tee
通过命令|
管道操作员。 Heredocs是快速创建文本或将文本附加到文件的好方法。
Next, in order to prevent arbitrary users from logging in to your Drone server and having access to your runners, limit registration to specified usernames or organizations. If you need to add users at this time, run the following command, replacing users
with a comma-separated list of GitHub usernames or organization names:
接下来,为了防止任意用户登录到您的Drone服务器并有权访问您的跑步者,请将注册限制为指定的用户名或组织。 如果您此时需要添加用户,请运行以下命令,用逗号分隔的GitHub用户名或组织名称列表替换users
:
echo 'DRONE_USER_FILTER=users' | sudo tee -a /etc/drone
回显'DRONE_USER_FILTER = 用户 '| sudo tee -a / etc / drone
If you are not using an external load balancer or SSL proxy, you will also need to enable Let’s Encrypt for HTTPS:
如果您不使用外部负载平衡器或SSL代理,则还需要为HTTPS启用“让我们加密”:
You will note that your tee
command now includes the -a
switch, which instructs tee
to append, and not overwrite, this output to your Drone configuration file. Let’s now set up your log storage system.
您会注意到,您的tee
命令现在包括-a
开关,该命令指示tee
将此输出附加到而不是覆盖到您的Drone配置文件。 现在,我们来设置您的日志存储系统。
For heavily used installations, the volume of build logs can increase quite quickly to multiple gigabytes. By default, these logs are stored in the server’s database, but for performance, scalability, and stability, consider setting up external storage for your build logs. In this step, you’ll use DigitalOcean Spaces to do just that. You are welcome to modify these steps and use another S3-compatible storage service, or none at all if you are still prototyping your CI/CD workflow, or if you know that your build volume will be very low. In those cases you may continue to Step 4 now.
对于频繁使用的安装,构建日志的数量可以Swift增加到数GB。 默认情况下,这些日志存储在服务器的数据库中,但是出于性能,可伸缩性和稳定性的考虑,请考虑为构建日志设置外部存储。 在这一步中,您将使用DigitalOcean Spaces来做到这一点。 欢迎您修改这些步骤并使用另一种与S3兼容的存储服务,或者如果您仍在对CI / CD工作流程进行原型设计,或者您知道构建量将非常低,则完全不使用。 在这种情况下,您现在可以继续执行步骤4。
To store your logs on DigitalOcean Spaces, make sure that you have completed the necessary prerequisites and have set up a Spaces bucket and generated a matching . Copy that key to your clipboard and then update your configuration file with the following command:
要将日志存储在DigitalOcean Spaces上,请确保您已完成必要的先决条件并设置了Spaces存储桶并生成了匹配的 。 将该密钥复制到剪贴板,然后使用以下命令更新配置文件:
DRONE_S3_ENDPOINT=your_s3_endpoint
DRONE_S3_ENDPOINT = your_s3_endpoint
DRONE_S3_BUCKET=your_s3_bucket_name
DRONE_S3_BUCKET = your_s3_bucket_name
AWS_ACCESS_KEY_ID=your_s3_access_key
AWS_ACCESS_KEY_ID = your_s3_access_key
AWS_SECRET_ACCESS_KEY=your_s3_secret_key
AWS_SECRET_ACCESS_KEY = your_s3_secret_key
Remember to replace your_s3_endpoint
with the URL for your Space, your_s3_bucket_name
with the name of the Space you created, your_s3_access_key
with your access key, and your_s3_secret_key
with your secret. You can find the first two values in your Control Panel by clicking the Manage menu button, then clicking Spaces, and then choosing your new Space. You can retrieve your Spaces Access Key by clicking the Account menu button, and then clicking the API button, and then scrolling down until you find the Spaces section. If you have misplaced your secret key, then you will need to generate a new access key/secret pair.
记得替换your_s3_endpoint
的URL为你的空间, your_s3_bucket_name
与您创建的空间的名称your_s3_access_key
与您的访问密钥, your_s3_secret_key
与你的秘密。 通过单击“ 管理”菜单按钮,然后单击“ 空格” ,然后选择新的“ 空格” ,可以在“控制面板”中找到前两个值。 您可以通过单击“ 帐户”菜单按钮,然后单击“ API”按钮,然后向下滚动直到找到“ 空间”部分,来检索“空间访问密钥”。 如果您放错了密钥,那么您将需要生成一个新的访问密钥/秘密对。
Your Drone configuration file is now complete. Run a cat
command to view it:
您的Drone配置文件现已完成。 运行cat
命令查看它:
Your configuration file will look something like the following, depending on the options you chose:
根据您选择的选项,您的配置文件将类似于以下内容:
Output DRONE_SERVER_HOST=drone.your_domainDRONE_SERVER_PROTO=httpsDRONE_GITHUB_CLIENT_ID=your_github_client_idDRONE_GITHUB_CLIENT_SECRET=your_github_client_secretDRONE_RPC_SECRET=your_rpc_secretDRONE_USER_CREATE=username:sammy_the_shark,admin:trueDRONE_USER_FILTER=the_shark_orgDRONE_TLS_AUTOCERT=trueDRONE_S3_ENDPOINT=your_s3_endpointDRONE_S3_BUCKET=your_s3_bucketAWS_ACCESS_KEY_ID=your_s3_access_keyAWS_SECRET_ACCESS_KEY=your_s3_secret_key
Once you have confirmed that your configuration file is complete, you can start your Drone server.
确认配置文件完成后,即可启动Drone服务器。
With your proper configurations in place, your next step is to install and start Drone.
正确配置后,下一步就是安装并启动Drone。
First, pull the Drone Server Docker image:
首先,拉出Drone Server Docker映像:
Next, create a volume to store the database:
接下来,创建一个卷来存储数据库:
Finally, start the server, set it to restart on boot, and forward port 80
and 443
to it:
最后,启动服务器,将其设置为在启动时重新启动,然后将端口80
和443
转发给它:
If you followed the DigitalOcean Initial Server Setup Guide, then you will have enabled ufw
and only allowed OpenSSH
through your firewall. You will now need to open ports 80 and 443:
如果您遵循《 DigitalOcean初始服务器设置指南》,那么您将启用ufw
并且仅允许通过防火墙的OpenSSH
。 现在,您需要打开端口80和443:
Now reload ufw
and check that your rules updated:
现在重新加载ufw
并检查您的规则是否已更新:
You will see an output like this:
您将看到类似以下的输出:
Output Status: activeTo Action From-- ------ ----OpenSSH ALLOW Anywhere80 ALLOW Anywhere443 ALLOW AnywhereOpenSSH (v6) ALLOW Anywhere (v6)80 (v6) ALLOW Anywhere (v6)443 (v6) ALLOW Anywhere (v6)
At this point, you will be able to access your server, log in, and manage your repositories. Go to https://drone.your_domain
, enter your GitHub credentials, and authorize your new application when prompted.
此时,您将能够访问服务器,登录和管理存储库。 转到https:// drone.your_domain
,输入您的GitHub凭据,并在出现提示时授权您的新应用程序。
Your Drone server is now live and nearly ready for use. Configuring your Drone runner and/or the DigitalOcean Autoscaler are all that remains.
您的Drone服务器现在可以使用,即将投入使用。 剩下的工作就是配置您的Drone运行器和/或DigitalOcean Autoscaler。
Before your server can execute jobs, you need to set up a runner.
在服务器可以执行作业之前,您需要设置运行器。
If you want to automatically scale the runner with DigitalOcean Droplets, skip down to Option 2: Installing the Drone Autoscaler for DigitalOcean. If you want to use another runner, you can set that up instead and skip to Step 7. Otherwise, follow Option 1 and install the Docker runner.
如果要使用DigitalOcean Droplet自动缩放流道,请跳至选项2:安装适用于DigitalOcean的无人机自动缩放器 。 如果要使用其他运行程序,则可以进行设置,然后跳到步骤7。否则,请遵循选项1并安装Docker运行程序。
First, pull the Docker image for the runner:
首先,为跑步者拉Docker镜像:
Next, start the runner. Replace drone.your_domain
and your_rpc_secret
with your personal values. You can change the DRONE_RUNNER_CAPACITY
to increase the number of pipelines that will be executed at once, but be mindful of your available system resources:
接下来,启动跑步者。 用您的个人值替换drone.your_domain
和your_rpc_secret
。 您可以更改DRONE_RUNNER_CAPACITY
以增加将立即执行的管道数量,但是请注意可用的系统资源:
docker run --name drone-runner --detach --restart=always --volume=/var/run/docker.sock:/var/run/docker.sock -e DRONE_RPC_PROTO=https -e DRONE_RPC_HOST=drone.your_domain -e DRONE_RPC_SECRET=your_rpc_secret -e DRONE_RUNNER_CAPACITY=1 -e DRONE_RUNNER_NAME=${HOSTNAME} drone/drone-runner-docker:1
docker run --name drone-runner --detach --restart = always --volume = / var / run / docker.sock:/var/run/docker.sock -e DRONE_RPC_PROTO = https -e DRONE_RPC_HOST = drone.your_domain- e DRONE_RPC_SECRET = your_rpc_secret -e DRONE_RUNNER_CAPACITY = 1 -e DRONE_RUNNER_NAME = $ {HOSTNAME} drone / drone-runner-docker:1
Finally, ensure that the runner started successfully:
最后,确保跑步者成功启动:
You will see an output like this:
您将看到类似以下的输出:
Output time="2020-06-13T17:58:33-04:00" level=info msg="starting the server" addr=":3000"time="2020-06-13T17:58:33-04:00" level=info msg="successfully pinged the remote server"time="2020-06-13T17:58:33-04:00" level=info msg="polling the remote server" arch=amd64 capacity=1 endpoint="https://drone.your_domain" kind=pipeline os=linux type=docker
If you ever need to change the runner configuration or secret, delete your container with docker rm drone-runner
, and repeat this step. You can now proceed to Step 7 and create a basic pipeline.
如果您需要更改运行器配置或密钥,请使用docker rm drone-runner
删除容器,然后重复此步骤。 现在,您可以继续执行步骤7并创建一个基本管道。
The Drone Autoscaler for DigitalOcean can automatically create and destroy Droplets with the Docker runner as needed.
适用于DigitalOcean的Drone Autoscaler可以根据需要使用Docker运行程序自动创建和销毁Droplet。
First, go to your Drone server, log in, and click on User settings in the user menu. Find and copy your Personal Token. This is your_drone_personal_token
.
首先,转到您的Drone服务器,登录,然后在用户菜单中单击“ 用户设置 ”。 查找并复制您的个人令牌 。 这是your_drone_personal_token
。
Next, generate a new character string with the following command:
接下来,使用以下命令生成新的字符串:
Output e5cd27400...92b684526c622
Copy the output like you did in Step 2. This new output is your drone_user_token
.
像在步骤2中一样复制输出。此新输出是drone_user_token
。
Now add a new machine user with these new credentials:
现在使用以下新凭据添加新的计算机用户:
docker run --rm -it -e DRONE_SERVER=https://drone.your_domain -e DRONE_TOKEN=your_drone_personal_token --rm drone/cli:1 user add autoscaler --machine --admin --token=drone_user_token
docker run --rm -it -e DRONE_SERVER = https:// drone.your_domain -e DRONE_TOKEN = your_drone_personal_token --rm drone / cli:1用户添加自动定标器--machine --admin --token = drone_user_token
Now, if you haven’t already, you’ll need to create a DigitalOcean API Token with read/write privileges. We will refer to this as your_do_token
. If you did not complete this step in the prerequisites section then you can use . Keep this token very safe; it grants full access to all resources on your account.
现在,如果尚未创建,则需要创建具有读/写权限的DigitalOcean API令牌 。 我们将其称为your_do_token
。 如果您没有在先决条件部分中完成此步骤,则可以立即使用 。 确保此令牌非常安全; 授予对您帐户中所有资源的完全访问权限。
Finally, you can start the Drone Autoscaler. Make sure to replace all the highlighted variables with your own matching credentials:
最后,您可以启动Drone Autoscaler。 确保用您自己的匹配凭据替换所有突出显示的变量:
docker run --name=drone-autoscaler --detach --restart=always --volume=drone-autoscaler-data -e DRONE_SERVER_PROTO=https -e DRONE_SERVER_HOST=drone.your_domain -e DRONE_SERVER_TOKEN=drone_user_token -e DRONE_AGENT_TOKEN=your_rpc_secret -e DRONE_POOL_MIN=0 -e DRONE_POOL_MAX=2 -e DRONE_DIGITALOCEAN_TOKEN=your_do_token -e DRONE_DIGITALOCEAN_REGION=nyc1 -e DRONE_DIGITALOCEAN_SIZE=s-2vcpu-4gb -e DRONE_DIGITALOCEAN_TAGS=drone-autoscaler,drone-agent drone/autoscaler
docker run --name = drone-autoscaler --detach --restart = always --volume = drone-autoscaler-data -e DRONE_SERVER_PROTO = https -e DRONE_SERVER_HOST = drone.your_domain -e DRONE_SERVER_TOKEN = drone_user_token -e DRONE_AGENT_TOKEN = your_rpc_secret- DRONE_POOL_MIN = 0 -e DRONE_POOL_MAX = 2 -e DRONE_DIGITALOCEAN_TOKEN = your_do_token -e DRONE_DIGITALOCEAN_REGION = nyc1 -e DRONE_DIGITALOCEAN_SIZE = s-2vcpu-4gb -e DRONE_DIGITALOCEAN_TAGS = droneauto
You can also configure the minimum/maximum number of Droplets to create and the type/region for the Droplet. For faster build start times, set the minimum to 1 or more. Also, note that by default, the autoscaler will determine if new Droplets need to be created or destroyed every minute, and Droplets will be left running for at least 1 hour after creation before being automatically destroyed when inactive.
您还可以配置要创建的Droplet的最小/最大数量以及Droplet的类型/区域。 为了加快构建开始时间,请将最小值设置为1或更大。 另外,请注意,默认情况下,自动缩放器将确定是否需要每分钟创建或删除新的Droplet,并且Droplet在创建后至少要运行1小时,然后在不活动时自动销毁。
Afterwards, verify that the autoscaler started correctly with:
然后,使用以下命令验证自动缩放器是否正确启动:
If you decide you no longer want to use the autoscaler, delete the container with docker rm drone-autoscaler
, delete the leftover Droplets (if any) from your account, and revoke the DigitalOcean API Token. You are now prepared to test your new CI/CD workflow.
如果您决定不再使用自动缩放器,请使用docker rm drone-autoscaler
删除容器,从帐户中删除剩余的Droplet(如果有),然后撤销DigitalOcean API令牌。 现在,您准备测试新的CI / CD工作流程。
To test your new Drone installation, let’s create a YAML pipeline.
为了测试新的Drone安装,让我们创建一个YAML管道。
First, create a new repository on GitHub. From your GitHub profile page click on the Repositories menu, then click the green New button at the upper right. Give your repository a name on the following page and then click the green Create repository button. Now navigate to your Drone server, press SYNC, refresh the page, and your newly created repository should appear. Press the ACTIVATE button beside it.
首先,在GitHub上创建一个新的存储库。 在GitHub个人资料页面上,单击“ 存储库”菜单,然后单击右上角的绿色“ 新建”按钮。 在下一页上给您的存储库命名,然后单击绿色的“ 创建存储库”按钮。 现在,导航到您的Drone服务器,按SYNC ,刷新页面,然后将出现新创建的存储库。 按下旁边的ACTIVATE按钮。
Afterwards, create a new file in your repo named .drone.yml
. You can do this using GitHub’s UI or from the command line using git
. From the GitHub UI, click on the Repositories menu, then click on your new repository, and then click the Add file dropdown menu. Choose Create new file, name the file .drone.yaml
, and add the following contents:
然后,在您的.drone.yml
创建一个名为.drone.yml
的新文件。 您可以使用GitHub的UI或使用git
从命令行执行此操作。 在GitHub UI中,单击“ 存储库”菜单,然后单击新存储库,然后单击“ 添加文件”下拉菜单。 选择创建新文件 ,将文件命名为.drone.yaml
,并添加以下内容:
name: drone-testkind: pipelinetype: dockersteps:- name: test image: alpine commands: - echo "It worked!"
If you are using the GitHub UI, press the green Commit new file button at the bottom of the page. If you are using the command line then commit and push your changes. In either case, now open and watch your Drone dashboard in a browser.
如果您使用的是GitHub UI,请按页面底部的绿色“ 提交新文件”按钮。 如果使用命令行,则提交并推送更改。 无论哪种情况,现在打开并在浏览器中查看您的Drone仪表板。
If the build remains pending and doesn’t start, ensure that your runners are set up correctly (and that a Droplet was created if using the autoscaler). You can view the logs for the runner with docker logs drone-runner
and the logs for the autoscaler with docker logs drone-autoscaler
.
如果构建仍处于挂起状态且无法启动,请确保正确设置了运行程序(如果使用自动缩放器,则创建了Droplet)。 您可以使用docker logs drone-runner
查看运行程序的日志,并使用docker logs drone-autoscaler
查看自动docker logs drone-autoscaler
。
If you are using the autoscaler, it may take up to a minute for the initial build to start (the last log message during that time would be starting the server
).
如果您使用的是自动缩放器,则可能需要一分钟才能启动初始构建(在此期间,最后一条日志消息将starting the server
)。
After the build completes, you will see the text It worked!
in the logs for the test
stage of the drone-test
pipeline. If the logs fail to load, ensure that your S3 credentials and bucket name are correct. You can use docker logs drone
to view Drone’s logs for more information.
构建完成后,您将看到文本“ It worked!
在drone-test
管道test
阶段的日志中。 如果日志加载失败,请确保您的S3凭据和存储桶名称正确。 您可以使用docker logs drone
来查看Drone的日志以了解更多信息。
You’ve now set up and installed a Drone server to handle your CI/CD workflow.
现在,您已经设置并安装了Drone服务器来处理CI / CD工作流程。
In this tutorial you set up the Drone CI/CD server for use with your GitHub projects and optionally set up external storage for build logs. You also set up a local runner or a service to automatically scale them using DigitalOcean Droplets.
在本教程中,您将设置Drone CI / CD服务器以与GitHub项目一起使用,还可以选择为构建日志设置外部存储。 您还可以设置本地运行器或服务,以使用DigitalOcean Droplet自动缩放它们。
You can continue adding teammates and other authorized users to Drone using the process outlined in Step 2. Should you ever want to prevent any new users from signing up, run the following commands:
您可以继续使用步骤2中概述的过程将队友和其他授权用户添加到Drone。如果您想阻止任何新用户注册,请运行以下命令:
Drone is a very capable tool. From here, you might consider learning , or .
无人机是一种非常强大的工具。 从这里开始,您可能会考虑了解 ,或者 。
翻译自:
ar.drone2.0
转载地址:http://kvegb.baihongyu.com/