golang通过二进制、Docker或Drone CI发送通知的插件drone-line的使用
drone-line 插件使用指南
功能概述
drone-line 是一个用于通过二进制文件、Docker 或 Drone CI 发送 LINE 通知的插件。它支持以下功能:
- 发送多种消息类型(文本、视频、音频、贴纸、位置)
- 支持 Prometheus 指标 API
- 自动从 Let’s Encrypt 安装 TLS 证书
- 支持 Localtunnel 用于 webhook 隧道
- 支持 LINE Notify
安装方式
1. 二进制安装
预编译的二进制文件可以从发布页面下载,支持以下操作系统:
- Windows amd64/386
- Linux amd64/386
- Darwin amd64/386
使用 Go 安装:
go get -u -v github.com/appleboy/drone-line
或手动构建:
make build
2. Docker 安装
构建 Docker 镜像:
make docker
使用示例
1. 二进制方式使用
设置 Webhook 服务
默认端口 8088:
drone-line \
--secret xxxx \
--token xxxx \
webhook
更改端口到 8089:
drone-line \
--port 8089 \
--secret xxxx \
--token xxxx \
webhook
使用 Localtunnel:
drone-line \
-s secret \
-t token \
--tunnel \
--port 2002 \
webhook
使用 Let’s Encrypt:
drone-line \
-s secret \
-t token \
-autotls \
-host example.com \
-cache /var/www/.cache \
--port 443 \
webhook
发送通知
drone-line \
--secret xxxx \
--token xxxx \
--to xxxx \
--message "Test Message"
发送 LINE Notify
drone-line \
--token xxxx \
--message "Test Message" \
notify
2. Docker 方式使用
设置 Webhook 服务
默认端口 8088:
docker run --rm \
-e LINE_CHANNEL_SECRET=xxxxxxx \
-e LINE_CHANNEL_TOKEN=xxxxxxx \
appleboy/drone-line webhook
更改端口到 8089:
docker run --rm \
-e LINE_CHANNEL_SECRET=xxxxxxx \
-e LINE_CHANNEL_TOKEN=xxxxxxx \
-e LINE_PORT=8089 \
appleboy/drone-line webhook
发送通知
docker run --rm \
-e LINE_CHANNEL_SECRET=xxxxxxx \
-e LINE_CHANNEL_TOKEN=xxxxxxx \
-e LINE_TO=xxxxxxx \
-e LINE_MESSAGE=test \
-e LINE_IMAGES=https://example.com/1.png \
-e LINE_VIDEOS=https://example.com/1.mp4 \
-e LINE_AUDIOS=https://example.com/1.mp3::1000 \
-e LINE_STICKERS=1::1 \
-e LINE_LOCATIONS=title::address::latitude::longitude \
-e LINE_DELIMITER=:: \
appleboy/drone-line
3. Drone CI 方式使用
docker run --rm \
-e PLUGIN_CHANNEL_SECRET=xxxxxxx \
-e PLUGIN_CHANNEL_TOKEN=xxxxxxx \
-e PLUGIN_TO=xxxxxxx \
-e PLUGIN_MESSAGE=test \
-e PLUGIN_IMAGES=https://example.com/1.png \
-e PLUGIN_VIDEOS=https://example.com/1.mp4 \
-e PLUGIN_AUDIOS=https://example.com/1.mp3::1000 \
-e PLUGIN_STICKERS=1::1 \
-e PLUGIN_LOCATIONS=title::address::latitude::longitude \
-e PLUGIN_DELIMITER=:: \
-e PLUGIN_ONLY_MATCH_EMAIL=false \
-e DRONE_REPO_OWNER=appleboy \
-e DRONE_REPO_NAME=go-hello \
-e DRONE_COMMIT_SHA=e5e82b5eb3737205c25955dcc3dcacc839b7be52 \
-e DRONE_COMMIT_BRANCH=master \
-e DRONE_COMMIT_AUTHOR=appleboy \
-e DRONE_COMMIT_AUTHOR_EMAIL=appleboy@gmail.com \
-e DRONE_COMMIT_MESSAGE=Test_Your_Commit \
-e DRONE_BUILD_NUMBER=1 \
-e DRONE_BUILD_STATUS=success \
-e DRONE_BUILD_LINK=http://github.com/appleboy/go-hello \
-e DRONE_JOB_STARTED=1477550550 \
-e DRONE_JOB_FINISHED=1477550750 \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-line
测试
运行测试:
make test
图片示例
内存使用情况:
通知计数使用情况:
更多关于golang通过二进制、Docker或Drone CI发送通知的插件drone-line的使用的实战教程也可以访问 https://www.itying.com/category-94-b0.html
更多关于golang通过二进制、Docker或Drone CI发送通知的插件drone-line的使用的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html
使用 drone-line 插件在 Drone CI 中发送通知
drone-line 是一个 Drone CI 插件,用于通过 LINE Notify 服务发送构建通知。下面我将详细介绍如何使用这个插件通过二进制、Docker 或直接在 Drone CI 中使用。
1. 插件概述
drone-line 插件允许你在 Drone CI 构建过程中向 LINE 聊天室或群组发送通知消息,非常适合团队协作和构建状态通知。
2. 前置条件
- 已设置 LINE Notify 服务并获取访问令牌
- 已配置 Drone CI 服务器
- 基本的 Drone CI 配置文件 (.drone.yml) 知识
3. 使用方式
3.1 通过二进制使用
首先从 GitHub 下载预编译的二进制文件:
wget https://github.com/appleboy/drone-line/releases/download/v1.3.0/drone-line_linux_amd64
chmod +x drone-line_linux_amd64
然后在脚本中使用:
./drone-line_linux_amd64 --token YOUR_LINE_TOKEN --message "构建成功"
3.2 通过 Docker 使用
docker run --rm \
-e PLUGIN_TOKEN=YOUR_LINE_TOKEN \
-e PLUGIN_MESSAGE="构建成功" \
appleboy/drone-line
3.3 在 Drone CI 中使用
在 .drone.yml
配置文件中添加如下步骤:
kind: pipeline
type: docker
name: default
steps:
- name: notify
image: appleboy/drone-line
settings:
token:
from_secret: line_token
message: "构建成功 🎉"
when:
status: [success]
4. 完整 Drone CI 示例
kind: pipeline
type: docker
name: default
steps:
- name: build
image: golang:1.19
commands:
- go build -o app .
- go test ./...
- name: notify-success
image: appleboy/drone-line
settings:
token:
from_secret: line_token
message: |
构建成功 🎉
项目: ${DRONE_REPO_NAME}
分支: ${DRONE_BRANCH}
提交: ${DRONE_COMMIT_MESSAGE}
构建号: ${DRONE_BUILD_NUMBER}
when:
status: [success]
- name: notify-failure
image: appleboy/drone-line
settings:
token:
from_secret: line_token
message: |
构建失败 😞
项目: ${DRONE_REPO_NAME}
分支: ${DRONE_BRANCH}
提交: ${DRONE_COMMIT_MESSAGE}
构建号: ${DRONE_BUILD_NUMBER}
日志: ${DRONE_BUILD_LINK}
when:
status: [failure]
5. 可用参数
参数名 | 描述 | 示例 |
---|---|---|
token | LINE Notify 访问令牌 | abc123 |
message | 要发送的消息 | “构建成功” |
image_url | 附加的图片URL | “http://example.com/image.jpg” |
sticker_id | LINE 贴纸ID | 1 |
sticker_package_id | LINE 贴纸包ID | 1 |
debug | 启用调试模式 | true |
6. 安全建议
- 永远不要将 LINE token 直接写在配置文件中
- 使用 Drone 的 secrets 功能存储敏感信息
- 为 CI 用途创建专用的 LINE Notify token
7. 高级用法
7.1 发送图片通知
- name: notify-with-image
image: appleboy/drone-line
settings:
token:
from_secret: line_token
message: "构建完成截图"
image_url: "https://example.com/build-screenshot.png"
7.2 发送贴纸
- name: notify-with-sticker
image: appleboy/drone-line
settings:
token:
from_secret: line_token
message: "构建成功!"
sticker_id: 1
sticker_package_id: 1
8. 自定义消息模板
你可以使用 Go 的模板语法自定义消息:
- name: notify
image: appleboy/drone-line
settings:
token:
from_secret: line_token
message: |
{{#success build.status}}
构建成功 🎉
{{else}}
构建失败 😞
{{/success}}
详情: {{build.link}}
9. 总结
drone-line 插件为 Drone CI 提供了简单而强大的 LINE 通知功能,无论是简单的文本消息还是带有图片和贴纸的丰富通知,都能轻松实现。通过合理配置,可以让团队及时了解构建状态,提高开发效率。
更多详细信息和最新更新,请参考插件的 GitHub 仓库:appleboy/drone-line