This is a creation in Article, where the information may have evolved or changed.
Objective
In the previous article, we simply introduced the deployment of drone. The next step is to introduce the official documents as well as the plugins I used in the actual work. This article, is mainly a complete drone demo. Pipeline includes the Git clone pull code, the go build build, the Docker image is generated and pushed to the harbor,notify notification. On the notice, the official plug-ins are some of the West's favorite instant Messaging or collaboration tools, such as Telegram,slack,line. So in the late stages, I plan to write a plug-in or nail.
. drone.yml
First on the configuration file, there is a general understanding, and then one after another interpretation.
workspace: base: /go path: src/gogs.xxx.com/baa-cicdpipeline: build: image: golang:latest commands: - go build -o baa-cicd publish: image: plugins/docker registry: registry.xxx.com repo: registry.xxx.com/test/baa-cicd tags: latest secrets: [ docker_username, docker_password ] insecure: true notify: image: plugins/slack webhook: https://hooks.slack.com/services/xxx/xxx/xxx channel: dev template: > {{#success build.status}} build {{build.number}} succeeded. Good job. {{else}} build {{build.number}} failed. Fix me please. {{/success}}
Workspace
Work space, is a can be pipeline all stages of sharing volume and work path, the advantage is to avoid a variety of CDs and copies. Because the demo project uses Golang. So the set path is/GO/SRC/GOGS.XXX.COM/BAA-CICD.
Clone
Git plugin is a default plug-in, even if not configured, drone is automatically configured to pull code.
Build
Because it is a Golang project. A command go build. Of course, because the project is relatively small, I used glide to install the dependent package into the vendor directory in advance. Otherwise you should customize your own glide image, or execute the Glide install command before the Go Build command. Of course, you can also add a go test to the project.
build: image: golang:latest commands: - glide install - go build -o baa-cicd - go test -v
Docker Build
To build the Docker mirroring phase, we built our own private registry on this side with harbor. The note here is secrets: [Docker_username, Docker_password] settings here. In fact there are some scenarios where, for security reasons, you do not want to expose the username and password to the configuration file, drone provides the use of secret ref. In the drone UI interface, configure the secret as follows:
Then you can associate it with the Secrets option in the. drone.yml.
This step is, of course, a prerequisite to provide a dockerfile file.
FROM alpineRUN apk add -U tzdataRUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtimeCOPY baa-cicd /usr/local/bin/baa-cicdEXPOSE 13123ENTRYPOINT ["baa-cicd","--port=13123"]
Notify
In the notice this piece, I did not use the email plugin, just before joined the Istio Slack, so oneself established slack in the workspace, then in which establishes a channal, named Dev.
What you need to explain here is the settings for Webhook. You can view the official slack documentation for details. After the setup is successful,
Then copy the Webhookurl. Of course, you can customize your avatar and app name. My side is the default.
Finally actually receive the notification effect:
Demo Source
Specific code, I put it on GitHub. Everyone directly git clone down can.
Finally, put a picture of the whole build.