build: add alpine-based dockerfile#5732
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new Dockerfile based on Alpine Linux, aiming to drastically reduce the final container image size. By implementing a multi-stage build process, it separates build-time dependencies from runtime requirements, resulting in a more efficient and smaller deployment artifact. The change also sets a default timezone for the container, which can be customized. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Hey - 我在这里给出了一些高层次的反馈:
- 建议将镜像中的默认时区切换为 UTC,并让使用者通过环境变量 TZ 来覆盖,这样可以避免对于非 Asia/Shanghai 区域用户的意外行为。
- 如果已经存在一个非 Alpine 的 Dockerfile,你可能希望把通用的构建步骤重构为共享的 ARG 或基础构建阶段,这样在两个 Dockerfile 之间就不需要重复配置和依赖变更。
给 AI Agent 的提示
请根据本次代码评审中的评论进行修改:
## 总体评论
- 建议将镜像中的默认时区切换为 UTC,并让使用者通过环境变量 TZ 来覆盖,这样可以避免对于非 Asia/Shanghai 区域用户的意外行为。
- 如果已经存在一个非 Alpine 的 Dockerfile,你可能希望把通用的构建步骤重构为共享的 ARG 或基础构建阶段,这样在两个 Dockerfile 之间就不需要重复配置和依赖变更。帮我变得更有用!请在每条评论上点 👍 或 👎,我会利用这些反馈来改进对你代码的评审。
Original comment in English
Hey - I've left some high level feedback:
- Consider switching the default timezone in the image to UTC and letting consumers override it via TZ, to avoid surprising behavior for users outside Asia/Shanghai.
- If there is an existing non-Alpine Dockerfile, you may want to refactor common build steps into shared ARGs or a base stage so that configuration and dependency changes don't need to be duplicated across two Dockerfiles.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider switching the default timezone in the image to UTC and letting consumers override it via TZ, to avoid surprising behavior for users outside Asia/Shanghai.
- If there is an existing non-Alpine Dockerfile, you may want to refactor common build steps into shared ARGs or a base stage so that configuration and dependency changes don't need to be duplicated across two Dockerfiles.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request introduces an Alpine-based Dockerfile, which is a great initiative to reduce the container image size. My review focuses on applying Docker best practices to further optimize the new file. I've provided suggestions to improve layer caching for faster builds, enhance dependency management, reduce the final image size by questioning unnecessary runtime dependencies, and correct the way application source code is copied to ensure consistency and security.
| COPY --from=builder /usr/local/bin /usr/local/bin | ||
|
|
||
| # Copy application source | ||
| COPY . /AstrBot/ |
There was a problem hiding this comment.
This command copies the application source from the build context, not from the builder stage. This can lead to inconsistencies if the code changes between stages and may inadvertently include local files (like .git or .env) in the final image. It's safer and more consistent to copy the source code from the builder stage, which is where dependencies were installed against.
COPY --from=builder /AstrBot/ /AstrBot/
| make | ||
|
|
||
| # Install uv and generate + install Python deps | ||
| COPY . . |
There was a problem hiding this comment.
To optimize Docker layer caching, it's recommended to copy only the files required for dependency installation first (e.g., pyproject.toml), install the dependencies, and then copy the rest of the source code. The current COPY . . command invalidates the cache for the dependency installation layer whenever any file in the project changes, leading to longer build times.
| && uv lock \ | ||
| && uv export --format requirements.txt --output-file requirements.txt --frozen \ | ||
| && uv pip install -r requirements.txt --no-cache-dir --system \ | ||
| && uv pip install socksio pilk --no-cache-dir --system |
There was a problem hiding this comment.
| git \ | ||
| nodejs \ |
There was a problem hiding this comment.
The runtime image includes git and nodejs, which contribute significantly to the image size. Please verify if they are both strictly necessary at runtime. If they are only needed during the build process (e.g., git for fetching dependencies, nodejs for building assets), they should be confined to the builder stage to keep the final image as lean as possible.
Modifications / 改动点
Add alpine-based dockerfile, decrease container size to less than 800MB from 1.8G.
Default timezone is Asia/Shanghai, it can be changed via setting TZ ENV,for example: TZ=Asia/Singapore.
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.Summary by Sourcery
Build:
TZ环境变量设置可配置的默认时区。Original summary in English
Summary by Sourcery
Build: