From 222273b3b3a3711aabed5c02b52c75c081ac3641 Mon Sep 17 00:00:00 2001 From: 404MaximWang Date: Thu, 9 Apr 2026 01:09:01 +0800 Subject: [PATCH 1/3] feat: add minimal docker image build support and remove dashboard building process --- .github/workflows/docker-image.yml | 59 +++++++++++++++--------------- Dockerfile.minimal | 54 +++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 30 deletions(-) create mode 100644 Dockerfile.minimal diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index b0378532d1..0b32f2a064 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -13,6 +13,15 @@ jobs: build-nightly-image: if: github.repository == 'AstrBotDevs/AstrBot' && github.event_name == 'schedule' runs-on: ubuntu-latest + strategy: + matrix: + include: + - type: standard + file: Dockerfile + tag_suffix: "" + - type: minimal + file: Dockerfile.minimal + tag_suffix: "-minimal" env: DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} GHCR_OWNER: astrbotdevs @@ -44,17 +53,6 @@ jobs: if: github.event_name == 'schedule' && steps.check-commits.outputs.has_commits == 'false' run: exit 0 - - name: Build Dashboard - run: | - cd dashboard - npm install - npm run build - mkdir -p dist/assets - echo $(git rev-parse HEAD) > dist/assets/version - cd .. - mkdir -p data - cp -r dashboard/dist data/ - - name: Determine test image tags id: test-meta run: | @@ -86,12 +84,12 @@ jobs: - name: Build nightly image tags list id: test-tags run: | - TAGS="${{ env.DOCKER_HUB_USERNAME }}/astrbot:nightly-latest - ${{ env.DOCKER_HUB_USERNAME }}/astrbot:nightly-${{ steps.test-meta.outputs.build_date }}-${{ steps.test-meta.outputs.short_sha }}" + TAGS="${{ env.DOCKER_HUB_USERNAME }}/astrbot:nightly-latest${{ matrix.tag_suffix }} + ${{ env.DOCKER_HUB_USERNAME }}/astrbot:nightly-${{ steps.test-meta.outputs.build_date }}-${{ steps.test-meta.outputs.short_sha }}${{ matrix.tag_suffix }}" if [ "${{ env.HAS_GHCR_TOKEN }}" = "true" ]; then TAGS="$TAGS - ghcr.io/${{ env.GHCR_OWNER }}/astrbot:nightly-latest - ghcr.io/${{ env.GHCR_OWNER }}/astrbot:nightly-${{ steps.test-meta.outputs.build_date }}-${{ steps.test-meta.outputs.short_sha }}" + ghcr.io/${{ env.GHCR_OWNER }}/astrbot:nightly-latest${{ matrix.tag_suffix }} + ghcr.io/${{ env.GHCR_OWNER }}/astrbot:nightly-${{ steps.test-meta.outputs.build_date }}-${{ steps.test-meta.outputs.short_sha }}${{ matrix.tag_suffix }}" fi echo "tags<> $GITHUB_OUTPUT echo "$TAGS" >> $GITHUB_OUTPUT @@ -101,6 +99,7 @@ jobs: uses: docker/build-push-action@v7.0.0 with: context: . + file: ${{ matrix.file }} platforms: linux/amd64,linux/arm64 push: true tags: ${{ steps.test-tags.outputs.tags }} @@ -116,6 +115,16 @@ jobs: GHCR_OWNER: astrbotdevs HAS_GHCR_TOKEN: ${{ secrets.GHCR_GITHUB_TOKEN != '' }} + strategy: + matrix: + include: + - type: standard + file: Dockerfile + tag_suffix: "" + - type: minimal + file: Dockerfile.minimal + tag_suffix: "-minimal" + steps: - name: Checkout uses: actions/checkout@v6 @@ -151,17 +160,6 @@ jobs: fi echo "version=$version" >> $GITHUB_OUTPUT - - name: Build Dashboard - run: | - cd dashboard - npm install - npm run build - mkdir -p dist/assets - echo $(git rev-parse HEAD) > dist/assets/version - cd .. - mkdir -p data - cp -r dashboard/dist data/ - - name: Set QEMU uses: docker/setup-qemu-action@v4.0.0 @@ -188,11 +186,12 @@ jobs: context: . platforms: linux/amd64,linux/arm64 push: true + file: ${{ matrix.file }} tags: | - ${{ steps.release-meta.outputs.is_prerelease == 'false' && format('{0}/astrbot:latest', env.DOCKER_HUB_USERNAME) || '' }} - ${{ steps.release-meta.outputs.is_prerelease == 'false' && env.HAS_GHCR_TOKEN == 'true' && format('ghcr.io/{0}/astrbot:latest', env.GHCR_OWNER) || '' }} - ${{ format('{0}/astrbot:{1}', env.DOCKER_HUB_USERNAME, steps.release-meta.outputs.version) }} - ${{ env.HAS_GHCR_TOKEN == 'true' && format('ghcr.io/{0}/astrbot:{1}', env.GHCR_OWNER, steps.release-meta.outputs.version) || '' }} + ${{ steps.release-meta.outputs.is_prerelease == 'false' && format('{0}/astrbot:latest{1}', env.DOCKER_HUB_USERNAME, matrix.tag_suffix) || '' }} + ${{ steps.release-meta.outputs.is_prerelease == 'false' && env.HAS_GHCR_TOKEN == 'true' && format('ghcr.io/{0}/astrbot:latest{1}', env.GHCR_OWNER, matrix.tag_suffix) || '' }} + ${{ format('{0}/astrbot:{1}{2}', env.DOCKER_HUB_USERNAME, steps.release-meta.outputs.version, matrix.tag_suffix) }} + ${{ env.HAS_GHCR_TOKEN == 'true' && format('ghcr.io/{0}/astrbot:{1}{2}', env.GHCR_OWNER, steps.release-meta.outputs.version, matrix.tag_suffix) || '' }} - name: Post build notifications run: echo "Release Docker image has been built and pushed successfully" diff --git a/Dockerfile.minimal b/Dockerfile.minimal new file mode 100644 index 0000000000..2a8a8afd63 --- /dev/null +++ b/Dockerfile.minimal @@ -0,0 +1,54 @@ +# Minimal Dockerfile for AstrBot +# Multi-stage: Build with uv; Run without node.js + +# Build stage +FROM python:3.12-slim AS builder + +WORKDIR /build + +# Install build dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + gcc \ + build-essential \ + python3-dev \ + libffi-dev \ + libssl-dev \ + ca-certificates \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Install uv +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uv/bin/uv + +# Copy requirements +COPY requirements.txt . + +# Install dependencies using uv +RUN /uv/bin/uv pip install --system --no-cache -r requirements.txt && \ + /uv/bin/uv pip install --system --no-cache socksio pilk + +# Runtime stage +FROM python:3.12-slim + +WORKDIR /AstrBot + +# Install runtime dependencies (only essential ones) +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates \ + bash \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +# Copy 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 code +COPY . /AstrBot/ + +# Cleanup Python cache +RUN find . -type f -name '*.pyc' -delete && \ + find . -type d -name '__pycache__' -delete + +EXPOSE 6185 + +CMD [ "python", "main.py" ] From 36e257e0186b39359d06c64cee2f505983602409 Mon Sep 17 00:00:00 2001 From: 404MaximWang Date: Thu, 9 Apr 2026 01:33:58 +0800 Subject: [PATCH 2/3] refactor: deduplicate strategy.matrix using anchor --- .github/workflows/docker-image.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 0b32f2a064..1bee1bc4a7 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -14,7 +14,7 @@ jobs: if: github.repository == 'AstrBotDevs/AstrBot' && github.event_name == 'schedule' runs-on: ubuntu-latest strategy: - matrix: + matrix: &docker_matrix include: - type: standard file: Dockerfile @@ -116,14 +116,7 @@ jobs: HAS_GHCR_TOKEN: ${{ secrets.GHCR_GITHUB_TOKEN != '' }} strategy: - matrix: - include: - - type: standard - file: Dockerfile - tag_suffix: "" - - type: minimal - file: Dockerfile.minimal - tag_suffix: "-minimal" + matrix: *docker_matrix steps: - name: Checkout From c0b09b9a263fa7e627706851564601517d7bac8b Mon Sep 17 00:00:00 2001 From: 404MaximWang Date: Thu, 9 Apr 2026 02:05:37 +0800 Subject: [PATCH 3/3] refactor: use venv instead of copying the entire /usr/local/bin for better robustness; deduplicate 'uv pip install' command; remove useless 'apt install' and 'find' commands --- Dockerfile.minimal | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/Dockerfile.minimal b/Dockerfile.minimal index 2a8a8afd63..8388a08e02 100644 --- a/Dockerfile.minimal +++ b/Dockerfile.minimal @@ -13,42 +13,30 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ python3-dev \ libffi-dev \ libssl-dev \ - ca-certificates \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* -# Install uv +# Install uv and create virtual environment COPY --from=ghcr.io/astral-sh/uv:latest /uv /uv/bin/uv - -# Copy requirements COPY requirements.txt . +RUN /uv/bin/uv venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" -# Install dependencies using uv -RUN /uv/bin/uv pip install --system --no-cache -r requirements.txt && \ - /uv/bin/uv pip install --system --no-cache socksio pilk +# Install dependencies +RUN /uv/bin/uv pip install --no-cache -r requirements.txt socksio pilk # Runtime stage FROM python:3.12-slim WORKDIR /AstrBot -# Install runtime dependencies (only essential ones) -RUN apt-get update && apt-get install -y --no-install-recommends \ - ca-certificates \ - bash \ - && apt-get clean && rm -rf /var/lib/apt/lists/* - -# Copy 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 virtual environment from builder +COPY --from=builder /opt/venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" # Copy application code COPY . /AstrBot/ -# Cleanup Python cache -RUN find . -type f -name '*.pyc' -delete && \ - find . -type d -name '__pycache__' -delete - EXPOSE 6185 CMD [ "python", "main.py" ]