Skip to content

Commit

Permalink
fix: Fix version file handling in multi-arch builds
Browse files Browse the repository at this point in the history
  • Loading branch information
3377 committed Dec 17, 2024
1 parent 3c166db commit 83b640d
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,41 @@ RUN go mod download

# 复制源代码并构建
COPY . .
RUN go mod tidy && \
mkdir -p config && \
cp version config/version && \
# 确保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

# 运行阶段
FROM alpine:latest

WORKDIR /app

# 从builder阶段复制编译好的二进制文件
COPY --from=builder /build/bot /app/bot

# 创建必要的目录
# 创建必要的目录并复制文件
RUN mkdir -p /app/config /app/data

# 复制version文件到config目录(从构建阶段复制)
# 从builder阶段复制文件
COPY --from=builder /build/bot /app/bot
COPY --from=builder /build/config/version /app/config/version

# 复制entrypoint脚本
COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh

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

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

# 设置时区
ENV TZ=Asia/Shanghai

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

0 comments on commit 83b640d

Please sign in to comment.