Skip to content

Commit

Permalink
还原: 恢复Dockerfile到原始版本
Browse files Browse the repository at this point in the history
1. 移除不必要的version文件处理逻辑
2. 保持构建过程简洁
3. 使用原始的ENTRYPOINT配置
  • Loading branch information
3377 committed Dec 17, 2024
1 parent a000f98 commit a4fde35
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,32 @@ RUN go mod download

# 复制源代码并构建
COPY . .
# 确保version文件存在并复制到正确位置
RUN mkdir -p config && \
if [ -f version ]; then \
cp version config/version; \
else \
echo "1.0.0" > config/version; \
fi && \
go mod tidy && \
go build -ldflags="-w -s" -o bot
RUN go mod tidy
RUN go build -ldflags="-w -s" -o bot

# 运行阶段
FROM alpine:latest

WORKDIR /app

# 创建必要的目录并复制文件
# 从builder阶段复制编译好的二进制文件
COPY --from=builder /build/bot /app/bot

# 创建必要的目录
RUN mkdir -p /app/config /app/data

# 从builder阶段复制文件
COPY --from=builder /build/bot /app/bot
COPY --from=builder /build/config/version /app/config/version
COPY entrypoint.sh /app/entrypoint.sh
# 复制version文件到config目录
COPY version /app/config/version

# 设置文件权限
RUN chmod +x /app/entrypoint.sh /app/bot && \
# 确保version文件存在且有正确的权限
touch /app/config/version && \
chmod 644 /app/config/version
# 复制entrypoint脚本
COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh

# 安装运行时依赖和时区数据
RUN apk add --no-cache ca-certificates tzdata

# 设置时区
ENV TZ=Asia/Shanghai

# 使用shell形式的ENTRYPOINT以确保正确的权限和路径
ENTRYPOINT ["/bin/sh", "-c", "exec /app/entrypoint.sh"]
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["/app/bot"]

0 comments on commit a4fde35

Please sign in to comment.