This is the first day of my participation in the August Text Challenge.More challenges in August

Has been I are using Jenkins for deployment of project management, but in fact, I used to is it receives webhook function, and then trigger the corresponding project default shell script to run the deployment, it is somewhat kill on the wheel (most actual deployment process should be the same), on the spur of the moment, just recently I wanted to try different integration construction schemes. After a simple investigation, I chose Drone. Its characteristics of light weight and high appearance level immediately attracted me

My current construction scheme is: Github + Drone + Docker (Docker installation)

Let’s take a look at the server memory usage comparison before and after the modification

When using Jenkins:

Here’s when Jenkins was stopped and Drone was enabled:

You can see that the memory usage has been cut in half, and it feels light enough to fly

In volume, there are two dimensions:

If there is any disadvantage of Drone, it is that the official documents are too simple, and it is difficult to find articles with any problems, resulting in a lot of time.

0. The configuration a lot

First log in to your Github account, click on your profile picture in the upper right corner, select Setting, Developer Settings, OAuth Application, and create a new Application:

Once the Client ID and Client Secret are created, take a notebook and write them down.

  1. What needs to be noted here is that the callback URL needs to fill in the login address of your Drone, which is specified at the end of the Drone homepage link/login

1. Install the Drone

Docker is used to install drone. Drone needs to create two containers, one is the webService end that provides view interface, and the other is the Runner end that performs tasks. Here, the Web end is installed first.

Note: Remove the description after the # sign at runtime

Docker run \ --volume=/var/drone:/data \ # note: 1 --env=DRONE_GITHUB_CLIENT_ID= \ # note: 2 --env=DRONE_SERVER_HOST= xxx.com 3 --env=DRONE_SERVER_PROTO= HTTP \ # note: 4 --env=DRONE_USER_CREATE=username:name,admin:true 5 --publish=10086:80 \ # note: 6 --publish= 10087:80 \ # note: 6 --restart=always \ --detach=true \ --name=drone \ drone/drone:latestCopy the code
  1. Drone and host directory mapping, which can change /var/drone into your host customized directory
  2. Fill in the previous stepClient IDandClient Secret, RPC_SECRET is the same as Client Secret
  3. Your drone domain name, no fillIP: port
  4. You are advised to set HTTP if there are no special cases
  5. Set the admin account (required) tonameChange your Github account name
  6. Map the port number of the host (I use port 10086 of the host computer here, and use port 80 in the drone container). Set the external port 10086 as your custom port. Remember to confirm that the whitelist has been configured

1.1 configure nginx

Nginx: /data/nginx: /data/nginx: /data/nginx: /data/nginx: /data/nginx

  docker run -d \
  -v /data/nginx/nginx.conf:/etc/nginx/nginx.conf \
  -v /data/nginx/cert:/etc/nginx/cert \
  -v /data/docker_home:/home \
  --net host \
  --name nginx \
  nginx
Copy the code

2. Install the runner

docker run -d \ -v /var/run/docker.sock:/var/run/docker.sock \ -e DRONE_RPC_PROTO=http \ -e DRONE_RPC_HOST=xxx.com \ # Note: 1 -e DRONE_RPC_SECRET= XXX \ # 2 -e DRONE_RUNNER_CAPACITY=2 \ -e DRONE_RUNNER_NAME=runner\ -e TZ="Asia/GuangZhou" \ -p 10088:3000 \ --restart always \ --name drone-runner \ drone/drone-runner-docker:latestCopy the code
  1. Enter drone domain name, or IP: port
  2. RPC_SECRET is the same as in the previous stepClient Secret

3. Login

Open the configured URL, and the Github login will be activated when you log in. Log in to your Github account.

Click on the top right to sync your warehouse and see all your projects

Click on the project you want to manage (you can create a repository test on Github) and activate it:

After activating the warehouse, you can do some configuration, basically as follows:TrustedThis parameter can be set only for administrators:

When activating the warehouse, Drone will send a Activie notification to the warehouse. At this time, the corresponding warehouse will set a current Webhook record, which is very convenient without manual configuration.

4. Automatically trigger the build

Next, submit a COMMIT record to the test repository

  1. Directly go to Github to create a warehouse d_test, enter Drone, click on the upper right corner to synchronize the warehouse, search d_test, and click the Active button to activate.

  2. Create new file.drone.yml in d_test directory:

Kind: Pipeline type: docker name: default Clone: disable: true Steps: -name: image: alpine Commands: - echo hello droneCopy the code

Briefly explain the above configuration. First, the file directory and name can be customized in the Setting of Drone project management:

Config file note indent, type: docker is the most important build method we use later, you may have noticed that step can configure multiple steps, each step will pull a docker image to use a temporary container to run, immediately destroyed after completion.

Which line of clone configuration turns off the default clone step of drone. Due to network problems, the Clone warehouse code will be time-consuming, and how to write a Clone operation by myself will be explained in detail later.

  1. Going back to Drone’s project management, see that the build has been triggered automatically:

At this point the project becomes active and can be screened

So far Drone is up and running, nice and simple, all ready to go, and more on yML configuration writing will be covered in the next article.

Postscript: a pit point

When configuring Apps on Github, pay attention to the Settings of this place. If there is a token expired mechanism, you’d better quit, otherwise webhook will fail 8 hours later and you can only log in drone again.