Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Rancher and DroneCI to establish ultra-high-speed Docker CI/CD pipeline

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How to use Rancher and DroneCI to build ultra-high-speed Docker CI/CD assembly line, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Text

At Higher Education, we tested using a number of CI/CD tools to build our CI/CD pipeline. The experience of using Rancher and Drone is by far the simplest, fastest and most enjoyable. From the moment the code is pushed / merged to the deployment branch, cloud-managed solutions will spend about half of their time testing, building, and deploying-a process that takes only three to five minutes (some applications take more time due to more complex build / test processes).

Setting up the configuration and maintenance of the Drone environment is very friendly to our developers, and installing Drone on Rancher is as simple as installing anything else on Rancher.

The maximum demand point of CI/CD pipeline

The quality of the CI/CD pipeline is actually the core of the DevOps experience, directly affecting our developers. For developers, the two most important points of the CI/CD pipeline are speed and simplicity.

The first point is speed. After all, there is nothing worse than the experience of having to wait 20 minutes to push a line of code to run. Another bad thing is that when there is something wrong with the product, the hot fix launched by the developer will only cost the company more money when it is deployed through the pipeline.

The second point is simplicity, where developers can ideally build and maintain their application deployment configurations. This makes them easier to use, after all, you certainly don't want developers to keep Slack you for some reason when they fail to build.

Speed pain points of Docker CI/CD pipelining

Although using immutable containers is far better than maintaining stateful servers, they still have some drawbacks-the biggest of which is the speed of deployment: container images are built and deployed more slowly than simply pushing code to an existing server. The following figure shows where it takes time for Docker to deploy the pipeline:

The latency of the Docker image repository (step 1, 4, 5) may be related to the amount of time it takes to build the Docker, depending on the size of the application and the time it takes to build. The application build time (step 2 and 3) may be a fixed amount, but it may also be severely affected by the memory available during the build process or the CPU core.

If you are using a cloud-hosted CI solution, you will not be able to control where the CI server is running (the latency of the image repository may be very slow), and you may not be able to grasp the type of server / instance running (application build may be slow). In addition, each build process will generate a lot of repetitive work, such as downloading the basic image for each build.

Start Drone CI

Similar to the Jenkins tool, Drone needs to run on your Rancher infrastructure. The difference is that Drone is a native tool for Docker-- every part of the build process is a container. Because basic images can be shared across builds and even across projects, Drone can speed up the build process when running on your infrastructure. If you push Drone to the Docker image repository on your infrastructure (such as AWS's ECR), you can also largely avoid latency.

Drone's Docker localization also eliminates a lot of configuration compatibility issues, and friends who have worked with Jenkins must know how convenient this is.

The standard Drone deployment process is as follows:

Run a container to notify Slack that the build has started

Configure a basic image for the Test container, insert code, and test run in the container

Run a container to build and push production images (to Docker Hub, AWS ECR, etc.)

Run a container to tell Rancher to upgrade the service

Run a container to notify Slack that the build has completed / failed

The A.drone.yml file looks very similar to the docker-compose.yml file-- a list of containers. Because each step has a container dedicated to that task, the configuration of the step is usually very simple.

Start and run Drone

The brief actions required are as follows:

Register a new Github OAuth app

Create a Drone environment on Rancher

Add a "Drone Server" host and one or more "Drone Worker" hosts

Add drone=server tags to Drone Server hosts

Run the Drone stack

The size of the instance depends on you-at Higher Education, we tend to use less, more powerful workers, which speeds up the build. (we found that a strong worker can handle the building of 7 teams.)

Once your drone service starts, run this stack:

Version: '2'services: drone-server: image: drone/drone:0.5 environment: DRONE_GITHUB:' true' DRONE_GITHUB_CLIENT: DRONE_GITHUB_SECRET: DRONE_OPEN: 'true' DRONE_ORGS: myGithubOrg DRONE_SECRET: DRONE_GITHUB_PRIVATE_MODE:' true' DRONE_ADMIN: someuser,someotheruser DRONE_DATABASE_DRIVER: mysql DRONE_DATABASE_DATASOURCE: user:password@tcp (databaseurl:3306) / drone?parseTime=true volumes:-/ drone:/var/lib/drone/ ports:-80:8000/tcp labels: io.rancher.scheduler.affinity:host_label: drone=server drone-agent: image: drone/drone:0.5 environment: DRONE_SECRET: DRONE_SERVER: ws://drone-server: 8000/ws/broker volumes:-/ var/run/docker.sock:/var/run/docker.sock command:-agent labels: io.rancher.scheduler.affinity:host_label_ne: drone=server io.rancher.scheduler.global: 'true'

This will run a Drone service on your drone=server host and a drone agent for every other host in your environment. We highly recommend that you use MySQL to back up Drone and set DATABASE_DRIVER and data values to achieve this. In this example, we use a small instance of RDS.

When the stack is up and running, you can log in to the IP address of the Drone service and open a warehouse for building (from the account menu). Here you will notice that every warehouse in Drone UI is not configured. You need a .drone.yml file to take care of all this.

Add scaffolding configuration

Let's build and test a Node.js project and add a .drone.yml file to your repository, like this:

Pipeline: build: image: node:6.10.0 commands:-yarn install-yarn test

The content of the file is very concise, you only need to set up the container image of the repository code in the build step and specify the command to run in the container.

Other projects can also be managed by Drone plug-ins, which act as containers for a task. And because the plug-ins are all on Docker Hub, you don't need to install them, just add them to the .drone.yml file.

Here is an example of creating .drone.yml in detail using the Slack, ECR, and Rancher plug-ins:

Pipeline: slack: image: plugins/slack webhook: channel: deployments username: drone template: "on by {{build.author}}" when: branch: [master Staging] build: image: commands:-yarn install-yarn test environment:-SOME_ENV_VAR=some-value ecr: image: plugins/ecr access_key: ${AWS_ACCESS_KEY_ID} secret_key: ${AWS_SECRET_ACCESS_KEY} repo: dockerfile: Dockerfile storage_path: / drone/docker rancher: image: peloton/drone-rancher url: access_key: ${ RANCHER_ACCESS_KEY} secret_key: ${RANCHER_SECRET_KEY} service: core/platform docker_image: confirm: true timeout: 240 slack: image: plugins/slack webhook: channel: deployments username: drone when: branch: [master Staging] status: [success, failure]

Although the above code is close to 40 lines, it is very readable, and 80% of the code is copied from the Drone plug-in documentation. (if you want to do this on a cloud-hosted CI platform, it may take a day to read the documentation.) it is important to note that each plug-in does not actually require tedious configuration. If you want to use Docker Hub instead of ECR, just use the Docker plug-in.

In a few minutes, you can start running a fully functional CD pipeline. In addition, it's also a good idea to use the Rancher Janitor directory stack to ensure that your workers has disk space. All you need to know is that the fewer times you clean up, the faster the build will be, because more layers are already cached.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report