In our daily development, test, or operational environments, there is a growing need for automated deployments.
Those of you who have used SVN are aware of this “special” feature which is used by everyday enterprise testing environments to automatically update published code.
Later, continuous integration and continuous deployment were introduced, most commonly through Jenkins in conjunction with other code management tools or platforms to achieve the above functionality. I’ve written a number of articles before: Jenkins+Maven+ SVN for automatic packaging and distribution of code, Gitlab+Jenkins for automatic stand-alone deployment of multiple branches, if you’re interested, check them out.
However, based on the above model, as we all know, there are some deficiencies, the first is the deployment environment is more troublesome, a bunch of components need to be installed, the second is the server itself resource condition requirements are higher. Recently found a very awesome tool Drone(you are still using Jenkins? Check out these alternatives!) , compared with the above tool is a lightweight player, but can also achieve the function of automatic deployment, so today, the migrant brother to share with you this tool hanging blast sky.
Introduction to the
Drone is a continuous delivery system based on container technology. Drone uses simple YAML configuration files to define and execute a Docker container in a Pipeline. There are currently 23.2K+ Star on GitHub, which is very popular.
Drone seamlessly integrates with popular source code management systems, including GitHub, GitHub Enterprise, BitBucket, and more.
Preliminary environment configuration
Use GitHub as a repository for code management (other options are also available, this is more convenient)
Go to github.com and click on the avatar, select Settings/Developer Settings/ OAuth Apps, and then click on the New OAuth App to create the OAuth App.
The domain name http://drone.mingongge.com is your deployment Drone, pay attention to the Authorization callback URL don’t fill in the address is wrong.
Save the ClientId and ClientSecret, which you will need later.
The deployment of Drone
Note: installing Drone requires a Drone-Server and Drone-Runner,
Drone -runner is not required, and it is not recommended to install runner and server on the same server. If you want to do so, you can set DRONE_AGENTS_ENABLED=false. Drone -server will be the default runner. This article is about installing Runner and Server on the same server.
# Drone Server Docker Pull Drone/Drone :1 # Drone Runner Docker Pull Drone/Drone-Runner-Docker :1 # Drone Runner Docker
Drone – server installation
docker run \ --volume=/var/lib/drone:/data \ --env=DRONE_GITHUB_CLIENT_ID={{DRONE_GITHUB_CLIENT_ID}} \ --env=DRONE_GITHUB_CLIENT_SECRET={{DRONE_GITHUB_CLIENT_SECRET}} \ --env=DRONE_RPC_SECRET={{DRONE_RPC_SECRET}} \ --env=DRONE_SERVER_HOST={{DRONE_SERVER_HOST}} \ --env=DRONE_SERVER_PROTO={{DRONE_SERVER_PROTO}} \ - env = DRONE_USER_CREATE = username: USER_NAME, admin:true \ --publish=80:80 \ --publish=443:443 \ --restart=always \ --detach=true \ --name=drone \ drone/drone:1
Parameters that
DRONE_GITHUB_CLIENT_SECRET # The GitHub OAuth client key generated in the previous step DRONE_RPC_SECRET # provides the shared key that was generated in the previous step. This is used to verify the RPC connection between the server and the running program. The server and the runner must provide the same secret key value. DRONE_SERVER_HOST # The domain name or IP address that the server provides or accords to. Use IP+ port to configure DRONE_SERVER_PROTO # with the required string value to provide your external protocol scheme. This value should be set to HTTP or HTTPS. DRONE_USER_CREATE # Initial administrator user
Install the drone – runner – docker
$ docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock \
-e DRONE_RPC_PROTO=https \
-e DRONE_RPC_HOST=drone.mingongge.com \
-e DRONE_RPC_SECRET=super-duper-secret \
-e DRONE_RUNNER_CAPACITY=2 \
-e DRONE_RUNNER_NAME=${HOSTNAME} \
-p 3000:3000 \
--restart always \
--name runner \
drone/drone-runner-docker:1
Parameters that
DRONE_RPC_HOST # Provides the host name (and optional port) of the Drone server. The runner connects to the server at the host address to receive pipes for execution. DRONE_RPC_PROTO # Provides the protocol used to connect to your Drone server. The value must be HTTP or HTTPS. DRONE_RPC_SECRET # Provides a shared key used to authenticate with your Drone server. This must match the secrets defined in your Drone Server configuration.
Management usage operation
Then open the browser, enter the server’s domain name or IP+ port, you can access Drone’s management page.
If you have created a project repository on GitHub, this page will be displayed. If not, click Sync to synchronize.
Next we need to set up the repository, click on the project and set the repository as Trusted, and click Save to SAVE.
A Webhooks are then generated on GitHub to trigger the Drone to execute the job.
Create the Secrets
The process is much like Jenkins’s: when you submit an update to the code repository, it automatically triggers Webhooks, and the Drone will Clone the code from the repository and execute the pipelined operation using the.drone.yml configuration, which is the equivalent of the pom.xml file used in Java.
Write a simple document like this
kind: pipeline
type: kubernetes
name: default
steps:
- name: drone_deploy
image: alpine
commands:
- echo hello
- echo world
The actions are then performed and pushed to the code repository
git add .
git commit -m 'deploy test by mingongge'
git remote add origin [email protected]:mingongge/dronetest.git
git push -u origin master
View the results through the Drone administration page
And the pipelining operation is also successful, the relevant information is returned as follows
Compared with Jenkins’ operation, it seems to be a lot easier, the key operation is to write the configuration file.dron. yml, the other is some graphical operation, there is no particular difficulty.
Official operation document: Official document: https://docs.drone.io/
Time is limited, the tutorial may not be complete, you can deploy their own, welcome to come together to discuss this super cow artifact, together to create their own CI/CD pipeline.