-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
build: add alpine-based dockerfile #5732
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # ======== Stage 1: Builder ======== | ||
| FROM python:3.12-alpine AS builder | ||
| WORKDIR /AstrBot | ||
|
|
||
| # Install build-time dependencies only | ||
| RUN apk add --no-cache \ | ||
| gcc \ | ||
| git \ | ||
| musl-dev \ | ||
| libffi-dev \ | ||
| openssl-dev \ | ||
| make | ||
|
|
||
| # Install uv and generate + install Python deps | ||
| COPY . . | ||
| RUN python -m pip install --no-cache-dir uv \ | ||
| && echo "3.12" > .python-version \ | ||
| && 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| # ======== Stage 2: Runtime ======== | ||
| FROM python:3.12-alpine | ||
| WORKDIR /AstrBot | ||
|
|
||
| ENV TZ=Asia/Shanghai | ||
|
|
||
| # Install runtime-only dependencies | ||
| RUN apk add --no-cache \ | ||
| ca-certificates \ | ||
| bash \ | ||
| ffmpeg \ | ||
| git \ | ||
| nodejs \ | ||
|
Comment on lines
+34
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The runtime image includes |
||
| tzdata | ||
|
|
||
| # Copy installed Python packages from builder | ||
| COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages | ||
| COPY --from=builder /usr/local/bin /usr/local/bin | ||
|
|
||
| # Copy application source | ||
| COPY . /AstrBot/ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This command copies the application source from the build context, not from the |
||
|
|
||
| EXPOSE 6185 | ||
|
|
||
| CMD ["python", "main.py"] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 currentCOPY . .command invalidates the cache for the dependency installation layer whenever any file in the project changes, leading to longer build times.