Original link: https://editor.leonh.space/2022/drone/
Summary of the previous situation: I built Gitea before, and then I checked it online. Most people use Drone CI to match it, so I also choose Drone CI!
Drone CI is divided into Drone server and Drone runner, one is the main control machine, and the other is the machine that actually runs the CI task. Of course, you can also set up multiple runners, as long as you have the ability to banknotes.
Whether it is Drone server or Drone runner, they are all run in the form of containers, please get Podman or Docker first.
Another reminder, if you are in a company and don’t have the ability to make money, don’t install Docker Desktop, you can modify Docker Engine to avoid becoming a pirated software. beneficiary victim.
Setting up Drone Server
Before getting the container up and running, do some paperwork in Gitea.
Pre-work
Create a Drone external application in Gitea, in “Settings → Applications”, fill in two values, the example is as follows:
- application name
drone
- application URI
http://192.168.0.226:3001/login
The URI here is the URI of the Drone server, which does not actually exist at present. This is expected in advance.
After submission, a pair of Client ID and Client Secret will be generated, please transcribe them. The example is as follows:
- Client ID
1306e04d-f653
- Client Secret
gto_de5nyz
The pre-work of Gitea is completed, and the Drone server can be set up.
Run the Drone Server container
There are many parameters for running the Drone server, so let’s sort them out first:
- DRONE_GITEA_CLIENT_ID
1306e04d-f653
- DRONE_GITEA_CLIENT_SECRET
gto_de5nyz
- DRONE_GITEA_SERVER
http://192.168.0.226:3000
- DRONE_RPC_SECRET
super-duper-secret
- DRONE_SERVER_HOST
192.168.0.226:3001
- DRONE_SERVER_PROTO
http
- DRONE_USER_CREATE
username:drone_admin,admin:true
From here, you can see that my Gitea is running at 192.168.0.226:3000, and the Drone server is expected to be running at 192.168.0.226:3001. The house number is only one number away, and it will run faster (nonsense).
Most of the other parameters are self-explanatory and will not be explained.
Here I use Podman, its CLI usage and Docker have nine images.
Download the Drone server image:
$ podman pull docker.io/drone/drone:2
The board number used in the Drone file is the fixed major version number 2
, and the latest
is not used, which should be a more robust consideration.
start running:
$ podman run \ --volume =/var/lib/drone:/data \ --env =DRONE_GITEA_SERVER=http://200.0.0.226:3000 \ --env =DRONE_GITEA_CLIENT_ID=1306e04d-f653 \ --env =DRONE_GITEA_CLIENT_SECRET=gto_de5nyz \ --env =DRONE_RPC_SECRET=super-duper-secret \ --env =DRONE_SERVER_HOST=200.0.0.226:3001 \ --env =DRONE_SERVER_PROTO=http \ --env =DRONE_USER_CREATE=username:drone_admin,admin:true \ --env =TZ=Asia/Taipei \ --publish =3001:80 \ --restart =always \ --detach =true \ --name =drone \ --restart =always \ docker.io/drone/drone:2
After execution, use podman ps
to confirm that it is not dead.
Open a browser to https://ift.tt/BdXUi4e, you should reach the Drone server login page.
After following the instructions to authorize and open an account, you will see the repo on the Drone page.
So far, some actions of Gitea (such as commit, merge) will be called to the webhook of the Drone server, and the Drone server will assign the task to the runner, the runner will pull the project down to a new container, and the Drone server is responsible for monitoring the runner , and the specific task is defined by the .drone.yml file in the project. We can give it commands to run tests, builds, and deployments.
some small instructions
To see the log, you can execute:
$ podman logs drone
To enter the container:
$ podman exec -it drone /bin/sh
Next comes the Drone runner.
Run Drone Runner
As mentioned earlier, the Drone server is the master, and the runner is the one who runs the pipeline.
Runner itself is also a container.
- Image
- Image real URL
docker.io/drone/drone-runner-docker
Drone Runner fails to run on Podman, and another one runs with pure Docker.
Grab the image:
$ sudo docker pull docker.io/drone/drone-runner-docker:1
Prepare parameters:
- DRONE_RPC_HOST
192.168.0.226:3001
- DRONE_RPC_PROTO
http
- DRONE_RPC_SECRET
super-duper-secret
start running:
$ sudo docker run \ --detach \ --volume =/var/run/docker.sock:/var/run/docker.sock \ --env =DRONE_RPC_PROTO=http \ --env =DRONE_RPC_HOST=192.168.0.226:3001 \ --env =DRONE_RPC_SECRET=super-duper-secret \ --env =DRONE_RUNNER_CAPACITY=2 \ --env =DRONE_RUNNER_NAME=my-first-runner \ # --env=DRONE_UI_USERNAME=root \ # --env=DRONE_UI_PASSWORD=root \ --env = TZ=Asia/Taipei \ --publish = 3000:3000 \ --restart = always \ --name = runner \ drone/drone-runner-docker:1
Two of the annotated lines are the account secrets of the runner web UI. This runner web UI is a bit tasteless. The main information is on the Drone server web, and the runner side is not open. After the annotation, the runner will not start the web UI. .
Through the above parameters, the Drone runner will register itself with the Drone server, and there is no need to do paperwork such as manual registration of the runner. After that, when the Drone server receives a job, it will be assigned to the runner.
Generally speaking, you can take a rest here, there is a real devil behind, and the pipeline configuration is waiting for us.
Drone CLI on the same scene
The Drone CLI is installed on the local computer and is responsible for interacting with the Drone server and managing the Drone.
Install:
$ curl -L https://github.com/harness/drone-cli/releases/latest/download/drone_linux_amd64.tar.gz | tar zx $ sudo install -t /usr/local/bin drone
In Windows, drone-cli can only be installed with Scoop, so you need to install Scoop first, and then drone-cli. For this part, please refer to the following documents:
After installation, configure the parameters to connect to the Drone server, and add the following to ~/.bashrc:
export DRONE_SERVER = http://192.168.0.226:3001 export DRONE_TOKEN = HnkG4wJYNY6D1VSVpKt1YGJqMVaMbuyf
The token can be seen on the Drone web personal account page.
After configuration, log in again and try:
$ drone info
You should see your account profile.
Please refer to the Drone CLI documentation for detailed usage.
References
Residual issues
How to make Drone server / Drone Runner become a service and start it by itself?
This article is reprinted from: https://editor.leonh.space/2022/drone/
This site is for inclusion only, and the copyright belongs to the original author.