mirror of
				https://github.com/suyiiyii/nonebot-bison.git
				synced 2025-11-04 13:34:52 +08:00 
			
		
		
		
	🚀 优化 dockerfile
This commit is contained in:
		
							parent
							
								
									5a5b27d285
								
							
						
					
					
						commit
						93b6055391
					
				@ -12,6 +12,9 @@ htmlcov
 | 
				
			|||||||
docker
 | 
					docker
 | 
				
			||||||
dist
 | 
					dist
 | 
				
			||||||
docs
 | 
					docs
 | 
				
			||||||
 | 
					venv
 | 
				
			||||||
 | 
					.venv
 | 
				
			||||||
 | 
					/admin-frontend/node_modules
 | 
				
			||||||
/LICENSE
 | 
					/LICENSE
 | 
				
			||||||
/.editorconfig
 | 
					/.editorconfig
 | 
				
			||||||
/.gitattributes
 | 
					/.gitattributes
 | 
				
			||||||
 | 
				
			|||||||
@ -79,6 +79,21 @@ RUN echo "🏗️ Starting frontend build..." && \
 | 
				
			|||||||
    pnpm run build && \
 | 
					    pnpm run build && \
 | 
				
			||||||
    echo "✅ Frontend build completed"
 | 
					    echo "✅ Frontend build completed"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					FROM python:3.12-slim AS playwright-stage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					WORKDIR /tmp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ENV DEBIAN_FRONTEND=noninteractive \
 | 
				
			||||||
 | 
					    PYTHONUNBUFFERED=1 \
 | 
				
			||||||
 | 
					    TZ=Asia/Shanghai
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RUN echo "📦 Installing playwright..." && \
 | 
				
			||||||
 | 
					    uvx playwright install --with-deps chromium && \
 | 
				
			||||||
 | 
					    echo "✅ Playwright installed successfully"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FROM python:3.12-slim AS production
 | 
					FROM python:3.12-slim AS production
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WORKDIR /app
 | 
					WORKDIR /app
 | 
				
			||||||
@ -107,29 +122,37 @@ RUN echo "📦 Installing system dependencies..." && \
 | 
				
			|||||||
        fonts-liberation \
 | 
					        fonts-liberation \
 | 
				
			||||||
        fonts-ipafont-gothic \
 | 
					        fonts-ipafont-gothic \
 | 
				
			||||||
        fonts-wqy-zenhei \
 | 
					        fonts-wqy-zenhei \
 | 
				
			||||||
        fonts-tlwg-loma-otf && \
 | 
					        fonts-tlwg-loma-otf \
 | 
				
			||||||
    mkdir -p /etc/apt/keyrings && \
 | 
					        at-spi2-common \
 | 
				
			||||||
    curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
 | 
					        fonts-freefont-ttf \
 | 
				
			||||||
    apt-get install -y nodejs && \
 | 
					        libasound2 \
 | 
				
			||||||
    echo "🔔 Verifying Node.js installation..." && \
 | 
					        libasound2-data \
 | 
				
			||||||
    if NODE_VERSION=$(node --version 2>&1); then \
 | 
					        libatk-bridge2.0-0 \
 | 
				
			||||||
        echo "✅ Node.js version ${NODE_VERSION} installed successfully"; \
 | 
					        libatk1.0-0 \
 | 
				
			||||||
    else \
 | 
					        libatspi2.0-0 \
 | 
				
			||||||
        echo "❌ Node.js installation failed" && exit 1; \
 | 
					        libavahi-client3 \
 | 
				
			||||||
    fi && \
 | 
					        libavahi-common-data \
 | 
				
			||||||
    mkdir -p "${PNPM_HOME}" && \
 | 
					        libavahi-common3 \
 | 
				
			||||||
    npm install -g pnpm@9.15.1 && \
 | 
					        libcairo2 \
 | 
				
			||||||
    # 预下载 pnpm 包到全局存储
 | 
					        libcups2 \
 | 
				
			||||||
    curl -fsSL https://registry.npmjs.org/pnpm/-/pnpm-9.15.1.tgz -o /tmp/pnpm.tgz && \
 | 
					        libdatrie1 \
 | 
				
			||||||
    mkdir -p /root/.local/share/pnpm/store/v3 && \
 | 
					        libdbus-1-3 \
 | 
				
			||||||
    pnpm store add /tmp/pnpm.tgz && \
 | 
					        libfribidi0 \
 | 
				
			||||||
    rm /tmp/pnpm.tgz && \
 | 
					        libgbm1 \
 | 
				
			||||||
    echo "🔔 Verifying pnpm installation..." && \
 | 
					        libglib2.0-0 \
 | 
				
			||||||
    if PNPM_VERSION=$(pnpm --version 2>&1); then \
 | 
					        libgraphite2-3 \
 | 
				
			||||||
        echo "✅ pnpm version ${PNPM_VERSION} installed successfully"; \
 | 
					        libharfbuzz0b \
 | 
				
			||||||
    else \
 | 
					        libnspr4 \
 | 
				
			||||||
        echo "❌ pnpm installation failed" && exit 1; \
 | 
					        libnss3 \
 | 
				
			||||||
    fi && \
 | 
					        libpango-1.0-0 \
 | 
				
			||||||
 | 
					        libthai-data \
 | 
				
			||||||
 | 
					        libthai0 \
 | 
				
			||||||
 | 
					        libwayland-server0 \
 | 
				
			||||||
 | 
					        libxcb-render0 \
 | 
				
			||||||
 | 
					        libxcomposite1 \
 | 
				
			||||||
 | 
					        libxdamage1 \
 | 
				
			||||||
 | 
					        libxi6 \
 | 
				
			||||||
 | 
					        libxkbcommon0 && \
 | 
				
			||||||
    fc-cache -fv && \
 | 
					    fc-cache -fv && \
 | 
				
			||||||
    apt-get clean && \
 | 
					    apt-get clean && \
 | 
				
			||||||
    rm -rf /var/lib/apt/lists/* && \
 | 
					    rm -rf /var/lib/apt/lists/* && \
 | 
				
			||||||
@ -146,48 +169,26 @@ RUN echo "🔔 Verifying uv installation..." && \
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
COPY ./pyproject.toml ./uv.lock ./
 | 
					COPY ./pyproject.toml ./uv.lock ./
 | 
				
			||||||
 | 
					
 | 
				
			||||||
RUN echo "📦 Installing bison dependencies..." && \
 | 
					RUN --mount=type=cache,target=/root/.cache/ \
 | 
				
			||||||
 | 
					    --mount=type=cache,target=/root/.uv \
 | 
				
			||||||
 | 
					    echo "📦 Installing bison dependencies..." && \
 | 
				
			||||||
    uv pip install --extra=docker --requirement pyproject.toml --no-cache && \
 | 
					    uv pip install --extra=docker --requirement pyproject.toml --no-cache && \
 | 
				
			||||||
    echo "✅ Dependencies installed successfully" && \
 | 
					    echo "✅ Dependencies installed successfully" && \
 | 
				
			||||||
    echo "🔔 Cleaning up uv..." && \
 | 
					    echo "🔔 Cleaning up uv..." && \
 | 
				
			||||||
    rm -rf /bin/uv /bin/uvx && \
 | 
					    rm -rf /bin/uv /bin/uvx && \
 | 
				
			||||||
    rm -rf /root/.cache/ && \
 | 
					 | 
				
			||||||
    rm -rf /root/.uv && \
 | 
					 | 
				
			||||||
    echo "✅ UV cleanup completed"
 | 
					    echo "✅ UV cleanup completed"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
COPY --from=metadata-stage /tmp/VERSION /app/VERSION
 | 
					COPY --from=metadata-stage /tmp/VERSION /app/VERSION
 | 
				
			||||||
COPY . .
 | 
					COPY nonebot_bison/ /app/nonebot_bison/
 | 
				
			||||||
COPY --from=frontend-stage /tmp/nonebot_bison/admin_page/dist ./dist
 | 
					COPY --from=frontend-stage /tmp/nonebot_bison/admin_page/dist ./nonebot_bison/admin_page/dist
 | 
				
			||||||
COPY --from=frontend-stage /tmp/admin-frontend/package.json ./
 | 
					COPY --from=playwright-stage /root/.cache/ms-playwright /root/.cache/ms-playwright
 | 
				
			||||||
COPY --from=frontend-stage /tmp/admin-frontend/pnpm-lock.yaml ./
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					EXPOSE 8080
 | 
				
			||||||
#RUN echo "📦 Installing frontend dependencies..." && \
 | 
					 | 
				
			||||||
#    cd /app/admin-frontend && \
 | 
					 | 
				
			||||||
#    SHELL="/bin/bash" pnpm install --offline --prod --frozen-lockfile && \
 | 
					 | 
				
			||||||
#    rm -rf /root/.cache/ && \
 | 
					 | 
				
			||||||
#    echo "✅ Frontend dependencies installed successfully"
 | 
					 | 
				
			||||||
RUN echo "📦 Installing frontend dependencies..." && \
 | 
					 | 
				
			||||||
    cd /app/admin-frontend && \
 | 
					 | 
				
			||||||
    SHELL="/bin/bash" pnpm install --prod --frozen-lockfile --no-verify-store-integrity && \
 | 
					 | 
				
			||||||
    rm -rf /root/.cache/ /root/.local/share/pnpm/store/v3/* /root/.pnpm-store && \
 | 
					 | 
				
			||||||
    echo "✅ Frontend dependencies installed successfully"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
RUN echo "🎭 Installing Playwright..." && \
 | 
					 | 
				
			||||||
    playwright install --with-deps chromium && \
 | 
					 | 
				
			||||||
    rm -rf /var/lib/apt/lists/* /tmp/* && \
 | 
					 | 
				
			||||||
    mv docker.env.prod .env.prod && \
 | 
					 | 
				
			||||||
    echo "✅ Playwright installed successfully"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
EXPOSE 3000 8080
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
RUN echo '#!/bin/bash' > /app/start.sh && \
 | 
					RUN echo '#!/bin/bash' > /app/start.sh && \
 | 
				
			||||||
    echo 'echo "📌 Current bison Version: $(cat /app/VERSION)"' >> /app/start.sh && \
 | 
					    echo 'echo "📌 Current bison Version: $(cat /app/VERSION)"' >> /app/start.sh && \
 | 
				
			||||||
    echo 'echo "🚀 Starting backend service..."' >> /app/start.sh && \
 | 
					    echo 'echo "🚀 Starting service..."' >> /app/start.sh && \
 | 
				
			||||||
    echo 'nb run &' >> /app/start.sh && \
 | 
					    echo 'nb run' >> /app/start.sh && \
 | 
				
			||||||
    echo 'echo "🚀 Starting frontend service..."' >> /app/start.sh && \
 | 
					 | 
				
			||||||
    echo 'cd /app/admin-frontend && SHELL=/bin/bash exec pnpm start' >> /app/start.sh && \
 | 
					 | 
				
			||||||
    chmod +x /app/start.sh
 | 
					    chmod +x /app/start.sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CMD ["/app/start.sh"]
 | 
					CMD ["/app/start.sh"]
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user