Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

容器配置时区为东八时区 #4

Closed
DesireWithin opened this issue Feb 29, 2024 · 5 comments · Fixed by #5
Closed

容器配置时区为东八时区 #4

DesireWithin opened this issue Feb 29, 2024 · 5 comments · Fixed by #5
Labels
enhancement New feature or request

Comments

@DesireWithin
Copy link

DesireWithin commented Feb 29, 2024

现在输出的时间是 UTC时间, 我们应该设置成+8时区
我正在尝试参考:
https://cloud.tencent.com/developer/article/1666529
编辑dockerfile 以及a2w.go
有进展同步.

@DesireWithin
Copy link
Author

DesireWithin commented Feb 29, 2024

经测试, 将基镜像(基于debian)的 /usr/share/zoneinfo 拷贝后, 并制定TZ 后, 时区生效

FROM golang:1.20 as builder

ENV GO111MODULE=on \
    GOPROXY=https://goproxy.cn,direct

WORKDIR /usr/src/app

COPY go.mod go.sum ./
RUN go mod download && go mod verify

COPY a2w.go .
RUN CGO_ENABLED=0 go build -o /usr/local/bin/a2w a2w.go

FROM scratch

ENV GIN_MODE=release

WORKDIR /app

COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo  #新增行, 也可使用args定义变量
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /usr/local/bin/a2w .
COPY templates templates

ENV TZ=Asia/Shanghai   #新增行, 也可使用ARG定义变量

EXPOSE 5001

ENTRYPOINT ["./a2w"]

@rea1shane rea1shane added the enhancement New feature or request label Mar 4, 2024
@rea1shane rea1shane assigned rea1shane and unassigned rea1shane Mar 4, 2024
@rea1shane
Copy link
Owner

rea1shane commented Mar 4, 2024

Hi @DesireWithin

我想了解一下为何要添加时区?目前使用中没有遇到过时间错误的问题。

而且 Prometheus 也是 UTC 时区,并且不能修改,官方文档:Can I change the timezone? Why is everything in UTC?

@rea1shane rea1shane added needs info The issue needs more info before it can be addressed. and removed enhancement New feature or request labels Mar 4, 2024
@DesireWithin
Copy link
Author

我们在输出企业微信消息的时候, 初始信息是不带时区的时间, 显示有歧义.
图片
和普罗米修斯的时区无关.
而通知模板的代码在这里, 没有输出时区.

a2w/a2w.go

Line 196 in 5ec3f48

func timeFormat(t time.Time) string {

@rea1shane
Copy link
Owner

我们在输出企业微信消息的时候, 初始信息是不带时区的时间, 显示有歧义.

我测试了一下确实是有这个问题,a2w 容器内的时区不是上海时区,这个项目一般是在中国使用的,所以改为东八时区还是有意义的。

你愿意提交一个 PR 么?感谢你指出这个问题。

@rea1shane rea1shane added enhancement New feature or request and removed needs info The issue needs more info before it can be addressed. labels Apr 25, 2024
@rea1shane rea1shane changed the title 通知消息配置时区 容器配置时区为东八时区 Apr 25, 2024
@rea1shane
Copy link
Owner

感谢你指出这个问题,我已经合并了相关内容。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants