Skip to content

Commit 4943fe6

Browse files
author
wangzheng1
committed
初始化项目
0 parents  commit 4943fe6

28 files changed

+1826
-0
lines changed

.github/workflows/go.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This workflow will build a golang project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
3+
4+
name: Go
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
18+
- name: Set up Go1.16
19+
uses: actions/setup-go@v4
20+
with:
21+
go-version: '1.16'
22+
23+
- uses: actions/checkout@v2
24+
25+
- name: Get dependencies
26+
run: go get -v -t -d ./...
27+
28+
- name: Build
29+
run: go build -v ./...
30+
31+
- name: Test
32+
run: go test -v ./...

.github/workflows/release.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# 工作流的名称
2+
name: Release And Build Docker
3+
4+
on:
5+
release:
6+
# 创建release时触发
7+
types: [created]
8+
9+
jobs:
10+
releases-matrix:
11+
name: Release Go Binary
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
goos: [ linux ]
16+
goarch: [ amd64, arm64 ]
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: wangyoucao577/[email protected]
20+
with:
21+
github_token: ${{ secrets.MY_TOKEN }}
22+
goos: ${{ matrix.goos }}
23+
goarch: ${{ matrix.goarch }}
24+
goversion: "https://go.dev/dl/go1.16.6.linux-amd64.tar.gz"
25+
project_path: "./src"
26+
binary_name: "kafka2es"
27+
docker:
28+
# 指定的运行器环境
29+
runs-on: ubuntu-latest
30+
31+
steps:
32+
# 检出当前代码(触发工作流时的commits)
33+
- name: Checkout
34+
uses: actions/checkout@v4
35+
# 获取docker源信息
36+
- name: Docker meta
37+
id: meta
38+
uses: docker/metadata-action@v5
39+
with:
40+
images: registry.cn-beijing.aliyuncs.com/whoops/kafka2es
41+
# 登录到阿里云容器镜像服务
42+
- name: Login to Ali Docker
43+
uses: docker/login-action@v3
44+
# 配置登录信息,secrets 变量在 github settings -> secrets 中设置
45+
with:
46+
registry: ${{ secrets.ALI_DOCKER_HUB_REGISTRY }}
47+
username: ${{ secrets.ALI_DOCKER_HUB_USN }}
48+
password: ${{ secrets.ALI_DOCKER_HUB_PWD }}
49+
# 构建镜像并上传到阿里云容器镜像仓库
50+
- name: Build and push
51+
id: docker_build
52+
uses: docker/build-push-action@v5
53+
with:
54+
push: true
55+
tags: ${{ steps.meta.outputs.tags }}

.idea/.gitignore

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kafka2es.iml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# 第一层是构建一个builder镜像,目的是在其中编译出可执行文件 kafka2es
2+
FROM golang:alpine AS builder
3+
4+
LABEL stage=gobuilder
5+
6+
# 禁用cgo
7+
ENV CGO_ENABLED 0
8+
# 添加代理
9+
ENV GOPROXY https://goproxy.cn,direct
10+
RUN apk update --no-cache && apk add --no-cache tzdata
11+
12+
13+
WORKDIR /app
14+
15+
ADD go.mod .
16+
ADD go.sum .
17+
RUN go mod tidy
18+
COPY .. .
19+
COPY ../src/etc/ /app/etc
20+
RUN go build -ldflags="-s -w" -o /app/kafka2es src/main.go
21+
22+
23+
# 从第一个镜像里copy出来可执行文件,并且使用尽可能小的基础镜像 alphine 以保障最终镜像尽可能小
24+
FROM scratch
25+
26+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
27+
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai
28+
ENV TZ Asia/Shanghai
29+
30+
WORKDIR /app
31+
COPY --from=builder /app/kafka2es /app/kafka2es
32+
COPY --from=builder /app/etc /app/etc
33+
34+
EXPOSE "8080"
35+
36+
CMD ["./kafka2es","--config","etc/config.yaml"]

README-CN.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Kafka2ES
2+
3+
Kafka2ES 是一个从Kafka读取消息,按照配置的格式化规则进行处理,然后写入的ElasticSearch集群的工具。
4+
![main](img/flow.png)
5+
### 安装
6+
7+
```shell
8+
cd src && go build -o kafka2es main.go
9+
```
10+
### Quick Start
11+
12+
- 可执行文件方式
13+
14+
```shell
15+
./kafka2es
16+
```
17+
18+
- docker 方式,确保配置文件路径正确 [部署在了阿里云容器里]
19+
20+
```shell
21+
docker run -d -v `pwd`/src/etc:/app/etc registry.cn-beijing.aliyuncs.com/whoops/kafka2es:v1.0
22+
```
23+
### 目录介绍
24+
- src [主要代码逻辑]
25+
- api[http路由相关信息]
26+
- cmd[程序入口函数]
27+
- es_proxy[输出组件es的相关操作]
28+
- etc[配置文件]
29+
- format[格式化相关操作]
30+
- handle[Kafka-handler-ES的逻辑代码]
31+
- kafka_proxy[输入组件kafka的相关操作]
32+
- logger[日志相关操作]
33+
- model[一些常量信息]
34+
- main.go [函数执行入口]

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# kafka2es
2+
消费Kafka消息格式化处理后写入到ES

go.mod

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module whoops/kafka2es
2+
3+
go 1.16
4+
5+
require (
6+
github.com/Shopify/sarama v1.36.0
7+
github.com/antonfisher/nested-logrus-formatter v1.3.1
8+
github.com/go-basic/uuid v1.0.0
9+
github.com/gorilla/mux v1.8.0
10+
github.com/jonboulle/clockwork v0.2.2 // indirect
11+
github.com/json-iterator/go v1.1.12
12+
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
13+
github.com/lestrrat-go/strftime v1.0.5 // indirect
14+
github.com/olivere/elastic/v7 v7.0.32
15+
github.com/panjf2000/ants/v2 v2.9.0
16+
github.com/pkg/errors v0.9.1
17+
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
18+
github.com/sirupsen/logrus v1.8.1
19+
github.com/spf13/pflag v1.0.5
20+
github.com/spf13/viper v1.8.1
21+
go.uber.org/automaxprocs v1.5.1
22+
)

0 commit comments

Comments
 (0)