Drone CI 中文文档

Cloud-init(实例初始化)

在某些情况下,你可能需要在创建云服务实例时自定义实例,然后再开始构建。

覆盖默认的 cloud-init 文件是一项高级功能,除非绝对必要,否则应避免使用。

你可以通过提供自定义 cloud-init 文件来自定义你的实例配置。

模板是使用 golang 模板语法提供的,你可以在 这里 找到更多信息。

Pool 文件的规范部分中有 2 个变量可用:

user_data

cloud-init 文件的内容将作为 pool.yml 中的字符串

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
version: "1"
instances:
  - name: test_pool
    default: true
    type: amazon
    pool: 1    
    limit: 1 
    platform:
      os: linux
      arch: amd64
    spec:
      account:
        region: us-east-2
        access_key_id: XXXXXXXXXXXXXXXXXXXXX
        access_key_secret: XXXXXXXXXXXXXXXXXXXXX
      ami: ami-051197ce9cbb023ea
      size: t2.micro
      user_data: |
        #cloud-config
        apt:
          sources:
            docker.list:
              source: deb [arch={{ .Architecture }}] https://download.docker.com/linux/ubuntu $RELEASE stable
              keyid: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88
        packages:
        - wget
        - docker-ce
        write_files:
        - path: {{ .CaCertPath }}
          permissions: '0600'
          encoding: b64
          content: {{ .CACert | base64  }}
        - path: {{ .CertPath }}
          permissions: '0600'
          encoding: b64
          content: {{ .TLSCert | base64 }}
        - path: {{ .KeyPath }}
          permissions: '0600'
          encoding: b64
          content: {{ .TLSKey | base64 }}
        runcmd:
        - 'wget "{{ .LiteEnginePath }}/lite-engine-{{ .Platform }}-{{ .Architecture }}" -O /usr/bin/lite-engine'
        - 'chmod 777 /usr/bin/lite-engine'
        - 'touch /root/.env'
        - 'touch /tmp/magic_lives_here'
        - '/usr/bin/lite-engine server --env-file /root/.env > /var/log/lite-engine.log 2>&1 &'        
    

user_data_path

cloud-init 文件的路径,将作为 pool.yml 中的字符串

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
version: "1"
instances:
  - name: test_pool
    default: true
    type: amazon
    pool: 1    
    limit: 1 
    platform:
      os: linux
      arch: amd64
    spec:
      account:
        region: us-east-2
        access_key_id: XXXXXXXXXXXXXXXXXXXXX
        access_key_secret: XXXXXXXXXXXXXXXXXXXXX
      ami: ami-051197ce9cbb023ea
      size: t2.micro
      user_data_path: /tmp/user-data.yml
    

你可以在 此处 查看自定义 cloud-init 模板文件的示例。