Docker Pipelines
This tutorial will help you create and execute a simple Docker pipeline. Please see our pipeline documentation for detailed usage instructions.
Step 1: Authenticate
First, navigate to your Drone server URL in your browser. If you are not already authenticated, Drone will redirect you to GitHub to login.
After login you are redirected back to your Drone dashboard. If this is your first time using Drone your dashboard will be empty for a few seconds while Drone synchronizes your repository list with GitHub.
Step 2: Enable your Repository
Next, search for your repository and click the Enable button. Clicking the enable button adds a webhook to your repository to notify Drone every time you push code. Please note you must have admin privileges to the repository to enable.
Step 3: Configure your Pipeline
Next, you need to configure a pipeline by creating a .drone.yml
file to the root of your git repository. In this file we define a series of steps that are executed every time a webhook is received.
1 kind: pipeline
2 type: docker
3 name: default
4
5 steps:
6 - name: greeting
7 image: alpine
8 commands:
9 - echo hello
10 - echo world
Here is a quick overview of the variables used in this example:
- kind
The kind attribute defines the kind of object. This example defines a pipeline object. Other kinds of object are secret and signature objects.
- type
The type attribute defines the type of pipeline. This example defines a Docker pipeline where each pipeline step is executed inside a Docker container. Drone supports different types of pipeline execution environments.
- name
The name attribute defines a name for your pipeline. You can define one or many pipelines for your project.
- steps
The steps section defines an array of pipeline steps that are executed serially. If any step in the pipeline fails, the pipeline exits immediately.- name
The name attribute defines the name of the pipeline step.
- image
The image attribute defines a Docker image in which the shell commands are executed. You can use any Docker image in your pipeline from any Docker registry, including private registries.
- commands
The commands attribute defines a list of shell commands that are executed inside the Docker container as the container entrypoint. If any command returns a non-zero exit code the pipeline step fails.
- name
Please see our pipeline documentation for a full list of configuration options.
Additional Examples
- You can add multiple steps to your pipeline:
1 kind: pipeline
2 type: docker
3 name: greeting
4
5 steps:
6 - name: en
7 image: alpine
8 commands:
9 - echo hello world
10
11 - name: fr
12 image: alpine
13 commands:
14 - echo bonjour monde
- You can conditionally limit step execution:
1 kind: pipeline
2 type: docker
3 name: greeting
4
5 steps:
6 - name: en
7 image: alpine
8 commands:
9 - echo hello world
10
11 - name: fr
12 image: alpine
13 commands:
14 - echo bonjour monde
15 when:
16 branch:
17 - develop
- You can even define multiple pipelines:
1 kind: pipeline
2 type: docker
3 name: en
4
5 steps:
6 - name: greeting
7 image: alpine
8 commands:
9 - echo hello world
10
11 ---
12 kind: pipeline
13 type: docker
14 name: fr
15
16 steps:
17 - name: greeting
18 image: alpine
19 commands:
20 - echo bonjour monde
- You can conditionally limit pipeline execution:
1 kind: pipeline
2 type: docker
3 name: en
4
5 steps:
6 - name: greeting
7 image: alpine
8 commands:
9 - echo hello world
10
11 trigger:
12 event:
13 - push
14
15 ---
16 kind: pipeline
17 type: docker
18 name: fr
19
20 steps:
21 - name: greeting
22 image: alpine
23 commands:
24 - echo bonjour monde
25
26 trigger:
27 event:
28 - pull_request
- You can use any image from any docker registry:
1 kind: pipeline
2 type: docker
3 name: default
4
5 steps:
6 - name: test
7 image: gcr.io/library/golang
8 commands:
9 - go build
10 - go test -v
- You can define service containers for integration tests:
1 kind: pipeline
2 type: docker
3 name: default
4
5 steps:
6 - name: test
7 image: golang:1.13
8 commands:
9 - go build
10 - go test -v
11
12 services:
13 - name: redis
14 image: redis
- You can use plugins to integrate with third party systems and perform common tasks, such as notify, publish or deploy software.
1 kind: pipeline
2 type: docker
3 name: default
4
5 steps:
6 - name: test
7 image: golang:1.13
8 commands:
9 - go build
10 - go test -v
11
12 - name: notify
13 image: plugins/slack
14 settings:
15 channel: dev
16 webhook: https://hooks.slack.com/services/...
- You can also source sensitive parameters from secrets:
1 kind: pipeline
2 type: docker
3 name: default
4
5 steps:
6 - name: test
7 image: golang:1.13
8 commands:
9 - go build
10 - go test -v
11
12 - name: notify
13 image: plugins/slack
14 settings:
15 channel: dev
16 webhook:
17 from_secret: endpoint
Step 4: Execute your Pipeline
The final step is to commit your .drone.yml
to your repository and push your changes. When you push code, GitHub sends a webhook to Drone which in turn executes your pipeline.