Software and Systems Engineering Standards: Verification and Validation of Sy...
Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension _ Docker.pdf
1. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
Hackathon time! Join us for the Docker AI/ML Hackathon now through November 7th. Sign up now ✕
Products Developers Pricing Blog About
Us Partners Sign In Get
Started
2. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
Ajeet Singh Raina
Kamesh Sampath
Continuous Integration (CI) is a key element of cloud native application development. With containers forming the
Bring Continuous Integration to
Your Laptop With the Drone CI
Docker Extension
3. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
foundation of cloud-native architectures, developers need to integrate their version control system with a CI tool.
There’s a myth that continuous integration needs a cloud-based infrastructure. Even though CI makes sense for
production releases, developers need to build and test the pipeline before they can share it with their team — or have the
ability to perform the continuous integration (CI) on their laptop. Is that really possible today?
Introducing the Drone CI pipeline
An open-source project called Drone CI makes that a reality. With over 25,700 GitHub stars and 300-plus contributors,
Drone is a cloud-native, self-service CI platform. Drone CI offers a mature, container-based system that leverages the
scaling and fault-tolerance characteristics of cloud-native architectures. It helps you build container-friendly pipelines
that are simple, decoupled, and declarative.
Drone is a container based pipeline engine that lets you run any existing containers as part of your pipeline or package
your build logic into reusable containers called Drone Plugins.
Drone plugins are configurable based on the need and that allows distributing the container within your organization or to
the community in general.
Running Drone CI pipelines from Docker
Desktop
For a developer working with decentralized tools, the task of building and deploying microservice applications can be
monumental. It’s tricky to install, manage, and use these apps in those environments. That’s where Docker Extensions
4. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
come in. With Docker Extensions, developer tools are integrated right into Docker Desktop — giving you streamlined
management workflows. It’s easier to optimize and transform your development processes.
The Drone CI extension for Docker Desktop brings CI to development machines. You can now import Drone CI pipelines
into Docker Desktop and run them locally. You can also run specific steps of a pipeline, monitor execution results, and
inspect logs.
Setting up a Drone CI pipeline
In this guide, you’ll learn how to set up a Drone CI pipeline from scratch on Docker Desktop.
First, you’ll install the Drone CI Extension within Docker Desktop. Second, you’ll learn how to discover Drone pipelines.
Third, you’ll see how to open a Drone pipeline on Visual Studio Code. Lastly, you’ll discover how to run CI pipelines in
trusted mode, which grants them elevated privileges on the host machine. Let’s jump in.
Prerequisites
You’ll need to download Docker Desktop 4.8 or later before getting started. Make sure to choose the correct version for
your OS and then install it.
Next, hop into Docker Desktop and confirm that the Docker Extensions feature is enabled. Click the Settings gear >
Extensions tab > check the “Enable Docker Extensions” box.
5. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
Installing the Drone CI Docker extension
6. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
Drone CI isn’t currently available on the Extensions Marketplace, so you’ll have to download it via the CLI. Launch your
terminal and run the following command to install the Drone CI Extension:
The Drone CI extension will soon appear in the Docker Dashboard’s left sidebar, underneath the Extensions heading:
1 docker extension install drone/drone-ci-docker-extension:latest
7. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
Import Drone pipelines
You can click the “Import Pipelines” option to specify the host filesystem path where your Drone CI pipelines (
drone.yml files) are. If this is your first time with Drone CI pipelines, you can use the examples from our GitHub repo.
8. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
In the recording above, we’ve used the long-run-demo sample to run a local pipeline that executes a long running sleep
command. This occurs within a Docker container.
0:00 / 0:22
9. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
You can download this pipeline YAML file from the Drone CI GitHub page.
The file starts with a pipeline object that defines your CI pipeline. The type attribute defines your preferred runtime
while executing that pipeline.
Drone supports numerous runners like docker, kubernetes, and more. The extension only supports docker pipelines
currently.
Each pipeline step spins up a Docker container with the corresponding image defined as part of the step image
attribute.
Each step defines an attribute called commands . This is a list of shell commands that we want to execute as part of the
build. The defined list of commands will be converted into shell script and set as Docker container’s ENTRYPOINT . If any
command (for example, the missing yq command, in this case) returns a non-zero exit code, the pipeline fails and exits.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
kind: pipeline
type: docker
name: sleep-demos
steps:
- name: sleep5
image: busybox
pull: if-not-exists
commands:
- x=0;while [ $x -lt 5 ]; do echo "hello"; sleep 1; x=$((x+1)); done
- name: an error step
image: busybox
pull: if-not-exists
commands:
- yq --help
10. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
11. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
12. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
Edit your pipeline faster in VS Code via Drone
CI
Visual Studio Code (VS Code) is a lightweight, highly-popular IDE. It supports JavaScript, TypeScript, and Node.js. VS
Code also has a rich extensions ecosystem for numerous other languages and runtimes.
Opening your Drone pipeline project in VS Code takes just seconds from within Docker Desktop:
13. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
This feature helps you quickly view your pipeline and add, edit, or remove steps — then run them from Docker Desktop. It
lets you iterate faster while testing new pipeline changes.
14. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
Running specific steps in the CI pipeline
The Drone CI Extension lets you run individual steps within the CI pipeline at any time. To better understand this
functionality, let’s inspect the following Drone YAML file:
In this example, the first pipeline step defined as sleep5 lets you execute a shell script ( echo “hello” ) for five
seconds and then stop (ignoring an error step ).The video below shows you how to run the specific sleep-demos
stage within the pipeline:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
kind: pipeline
type: docker
name: sleep-demos
steps:
- name: sleep5
image: busybox
pull: if-not-exists
commands:
- x=0;while [ $x -lt 5 ]; do echo "hello"; sleep 1; x=$((x+1)); done
- name: an error step
image: busybox
pull: if-not-exists
commands:
- yq --help
15. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
0:00 / 0:09
16. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
Running steps in trusted mode
Sometimes, you’re required to run a CI pipeline with elevated privileges. These privileges enable a user to systematically
do more than a standard user. This is similar to how we pass the --privileged=true parameter within a docker run
command.
When you execute docker run --privileged , Docker will permit access to all host devices and set configurations in
AppArmor or SELinux. These settings may grant the container nearly equal access to the host as processes running
outside containers on the host.
Drone’s trusted mode tells your container runtime to run the pipeline containers with elevated privileges on the host
machine. Among other things, trusted mode can help you:
Mount the Docker host socket onto the pipeline container
Mount the host path to the Docker container
17. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
0:00 / 0:26
18. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
Run pipelines using environment
variable files
The Drone CI Extension lets you define environment variables for individual build steps. You can set these within a
pipeline step. Like docker run provides a way to pass environment variables to running containers, Drone lets you pass
usable environment variables to your build. Consider the following Drone YAML file:
The file starts with a pipeline object that defines your CI pipeline. The type attribute defines your preferred runtime
(Docker, in our case) while executing that pipeline. The platform section helps configure the target OS and architecture
(like arm64 ) and routes the pipeline to the appropriate runner. If unspecified, the system defaults to Linux amd64 .
The steps section defines a series of shell commands. These commands run within a busybox Docker container as
the ENTRYPOINT . As shown, the command prints the environment variables if you’ve declared the following environment
variables in your my-env file:
1
2
3
4
5
6
7
8
9
kind: pipeline
type: docker
name: default
steps:
- name: display environment variables
image: busybox
pull: if-not-exists
commands:
- printenv
1
2
DRONE_DESKTOP_FOO=foo
DRONE_DESKTOP_BAR=bar
19. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
You can choose your preferred environment file and run the CI pipeline (pictured below):
If you try importing the CI pipeline, you can print every environment variable.
20. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
Run pipelines with secrets files
We use repository secrets to store and manage sensitive information like passwords, tokens, and ssh keys. Storing this
information as a secret is considered safer than storing it within a plain text configuration file.
Note: Drone masks all values used from secrets while printing them to standard output and error.
The Drone CI Extension lets you choose your preferred secrets file and use it within your CI pipeline as shown below:
21. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
Remove pipelines
22. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
You can remove a CI pipeline in just one step. Select one or more Drone pipelines and remove them by clicking the red
minus (“-”) button on the right side of the Dashboard. This action will only remove the pipelines from Docker Desktop —
without deleting them from your filesystem.
Bulk remove all pipelines
23. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
Remove a single pipeline
Conclusion
Drone is a modern, powerful, container-friendly CI that empowers busy development teams to automate their workflows.
This dramatically shortens building, testing, and release cycles. With a Drone server, development teams can build and
deploy cloud apps. These harness the scaling and fault-tolerance characteristics of cloud-native architectures like
Kubernetes.
24. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
Check out Drone’s documentation to get started with CI on your machine. With the Drone CI extension, developers can
now run their Drone CI pipelines locally as they would in their CI systems.
Want to dive deeper into Docker Extensions? Check out our intro documentation, or discover how to build your own
extensions.
Docker Desktop, Docker Extensions, Docker Hub
Signing Docker Official Images
Using OpenPubkey
By Jonny Stoten October 13, 2023
Getting Started with JupyterLab
as a Docker Extension
By Marcelo Ochoa October 12, 2023
Security Advisory: High Severity
Curl Vulnerability
By Jonathan Roberts October 5, 2023
25. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
Posted
Sep 20, 2022
Post Tags
Docker Desktop
Docker Extensions
Docker Hub
Categories
Community
Company
Engineering
Products
26. 2023/10/20 上午9:18 Bring Continuous Integration to Your Laptop With the Drone CI Docker Extension | Docker
Products
Docker Personal
Docker Pro
Docker Team
Docker Business
Docker Scout
Desktop vs Docker Engine
Docker Desktop
Docker Hub
Extensions
Secure Software Supply Chain
Container Runtime
Developer Tools
Trusted Content
Docker Product Roadmap
Support
Developers
Docs
Getting Started
Extensions SDK
Community
Open Source
Preview Program
System Status
Pricing
FAQ
Docker Verified Publisher
Partners
Blog
About Us
What is a Container
Why Docker
Events
Swag Store
Newsroom
Careers
Contact Us
Customers
Trademark Guidelines