Skip to content

Commit fe338d7

Browse files
authored
feat: optimize something (#9)
* feat: optimize something Signed-off-by: yuluo-yx <[email protected]> * fix: fix md style Signed-off-by: yuluo-yx <[email protected]> --------- Signed-off-by: yuluo-yx <[email protected]>
1 parent 6f38aaa commit fe338d7

File tree

7 files changed

+428
-59
lines changed

7 files changed

+428
-59
lines changed

Dockerfile

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,49 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
19-
# syntax=docker/dockerfile:1
20-
21-
# Build stage
22-
FROM golang:1.24-alpine AS builder
23-
24-
WORKDIR /app
25-
26-
# 安装 git 以支持 go mod 下载私有依赖(如有需要)
27-
RUN apk add --no-cache git
28-
29-
# 复制 go.mod 和 go.sum 并下载依赖
30-
COPY go.mod go.sum ./
31-
RUN go mod download
32-
33-
# 复制源代码
34-
COPY . .
35-
36-
# 构建二进制文件
37-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o collector ./cmd/main.go
38-
39-
# Production stage
40-
FROM alpine:3.19
41-
42-
WORKDIR /app
43-
44-
# 拷贝构建产物
45-
COPY --from=builder /app/collector /app/collector
46-
47-
# 如有配置文件等需要一并拷贝
48-
# COPY --from=builder /app/etc /app/etc
49-
50-
# 暴露端口(如有需要)
51-
# EXPOSE 1158
52-
53-
ENTRYPOINT ["./collector"]
18+
FROM golang:1.23-alpine AS golang-builder
19+
20+
ARG GOPROXY
21+
# ENV GOPROXY ${GOPROXY:-direct}
22+
# ENV GOPROXY=https://proxy.golang.com.cn,direct
23+
24+
ENV GOPATH /go
25+
ENV GOROOT /usr/local/go
26+
ENV PACKAGE hertzbeat.apache.org/hertzbeat-collector-go
27+
ENV BUILD_DIR /app
28+
29+
COPY . ${BUILD_DIR}
30+
WORKDIR ${BUILD_DIR}
31+
RUN apk --no-cache add build-base git bash
32+
33+
RUN make init && \
34+
make fmt && \
35+
make go-lint &&\
36+
make build
37+
38+
RUN chmod +x bin/collector
39+
40+
FROM alpine
41+
42+
ARG TIMEZONE
43+
ENV TIMEZONE=${TIMEZONE:-"Asia/Shanghai"}
44+
45+
RUN apk update \
46+
&& apk --no-cache add \
47+
bash \
48+
ca-certificates \
49+
curl \
50+
dumb-init \
51+
gettext \
52+
openssh \
53+
sqlite \
54+
gnupg \
55+
tzdata \
56+
&& ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
57+
&& echo "${TIMEZONE}" > /etc/timezone
58+
59+
COPY --from=golang-builder /app/bin/collector /usr/local/bin/collector
60+
COPY --from=golang-builder /app/etc/hertzbeat-collector.yml /etc/hertzbeat-collector.yml
61+
62+
EXPOSE 8090
63+
ENTRYPOINT ["collector", "server", "--config", "/etc/hertzbeat-collector.yml"]

README-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ HertzBeat-Collector-Go 是 [Apache HertzBeat](https://github.com/apache/hertzbea
1414

1515
## 📂 目录结构
1616

17-
```
17+
```text
1818
.
1919
├── cmd/ # 主程序入口
2020
├── internal/ # 采集器核心实现与通用组件

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ HertzBeat-Collector-Go is the Go implementation of the collector for [Apache Her
3636

3737
```bash
3838
# Install dependencies
39-
39+
go mod tidy
4040

4141
# Build
4242
make build

Roadmap.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
> 以优先级排序
44
5-
- [ ] 完善
5+
- [ ] 完善调度模块
66
- [ ] 完善网络通信模块;
7-
- [ ] 补充收集器类型,参照 Java 实现;
7+
- [ ] 补充采集器协议,参照 Java 实现;
88
- [ ] 完善文档;
99
- [ ] 增加更多示例。
1010
- [ ] 补充单测

docker-compose.yml

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,17 @@
1616
# under the License.
1717

1818
services:
19-
# collector service
19+
20+
# collector go service
2021
hertzbeat-collector:
21-
image: hertzbeat/hertzbeat-collector:latest
22-
container_name: hertzbeat-collector
23-
restart: always
22+
image: hertzbeat/hertzbeat-collector-go:latest
23+
container_name: hertzbeat-collector-go
24+
restart: on-failure
2425
ports:
25-
- "8080:8080" # Web access port
26-
- "8091:8091" # Agent communication port
27-
environment:
28-
- TZ=Asia/Shanghai # Set your timezone
29-
- JAVA_OPTS=-Xms512m -Xmx1024m -XX:+UseG1GC # Java memory settings
30-
- SPRING_PROFILES_ACTIVE=prod # Active profile (prod or dev)
31-
- HERTZBEAT_DB_HOST=db # Database host (use 'db' if using the db service below)
32-
- HERTZBEAT_DB_PORT=3306 # Database port
33-
- HERTZBEAT_DB_NAME=hertzbeat # Database name
34-
- HERTZBEAT_DB_USER=root # Database user
35-
- HERTZBEAT_DB_PASSWORD=yourpassword # Database password, change this to a secure password
36-
depends_on:
37-
- db # Ensure the database service starts before the collector
38-
volumes:
39-
- hertzbeat_data:/opt/hertzbeat/data # Persist data
26+
- "8090:8090"
27+
networks:
28+
hcg-network:
29+
30+
networks:
31+
hcg-network:
32+
driver: bridge

0 commit comments

Comments
 (0)