diff --git a/Dockerfile b/Dockerfile index a24bcf552..9df2a7238 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,8 +3,12 @@ FROM node:22-bookworm-slim AS frontend-builder WORKDIR /app/frontend +# Copy package files first for better caching COPY frontend/package*.json ./ -RUN npm ci + +# Use cache mount for npm +RUN --mount=type=cache,target=/root/.npm \ + npm ci COPY frontend/ ./ RUN npm run build @@ -21,9 +25,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ ffmpeg \ && rm -rf /var/lib/apt/lists/* -# Install Python dependencies +# Install Python dependencies with cache mount COPY requirements.txt ./ -RUN pip install --no-cache-dir --root-user-action=ignore -r requirements.txt +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install --root-user-action=ignore -r requirements.txt # Copy backend COPY backend/ ./backend/ @@ -46,4 +51,5 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \ CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1 # Run the application -CMD ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "8000"] +# Use standard asyncio loop (uvloop has permission issues in some Docker environments) +CMD ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "8000", "--loop", "asyncio"] diff --git a/README.md b/README.md index f1bad46e1..c1c9af0ec 100644 --- a/README.md +++ b/README.md @@ -255,6 +255,8 @@ Open **http://localhost:8000** in your browser. > **Multi-architecture support:** Pre-built images are available for `linux/amd64` and `linux/arm64` (Raspberry Pi 4/5). +> **macOS/Windows users:** Docker Desktop doesn't support `network_mode: host`. Edit docker-compose.yml: comment out `network_mode: host` and uncomment the `ports:` section. Printer discovery won't work - add printers manually by IP. +
Docker Configuration & Commands diff --git a/docker-compose.yml b/docker-compose.yml index 990d4873f..56f74136c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,13 +6,13 @@ services: # docker compose up -d → pulls pre-built image from ghcr.io # docker compose up -d --build → builds locally from source container_name: bambuddy - # Network mode options: - # - Default (bridge): Works for basic usage, but printer discovery and - # camera streaming may not work since container can't reach LAN directly. - # - Host mode: Required for printer discovery scanning and camera streaming. - # Uncomment "network_mode: host" and remove "ports:" section below. # + # LINUX: Use host mode for printer discovery and camera streaming network_mode: host + # + # macOS/WINDOWS: Docker Desktop doesn't support host mode. + # Comment out "network_mode: host" above and uncomment "ports:" below. + # Note: Printer discovery won't work - add printers manually by IP. #ports: # - "8000:8000" volumes: diff --git a/docker-publish.sh b/docker-publish.sh index e35480dd9..44018676e 100755 --- a/docker-publish.sh +++ b/docker-publish.sh @@ -91,13 +91,18 @@ fi # Setup buildx builder if not exists echo -e "${BLUE}[1/4] Setting up Docker Buildx...${NC}" if ! docker buildx inspect "$BUILDER_NAME" >/dev/null 2>&1; then - echo "Creating new buildx builder: $BUILDER_NAME" + echo "Creating new buildx builder: $BUILDER_NAME (optimized for ${CPU_COUNT} cores)" docker buildx create \ --name "$BUILDER_NAME" \ --driver docker-container \ --driver-opt network=host \ - --buildkitd-flags '--allow-insecure-entitlement network.host' \ - --bootstrap + --driver-opt "env.BUILDKIT_STEP_LOG_MAX_SIZE=10000000" \ + --buildkitd-flags "--allow-insecure-entitlement network.host --oci-worker-gc=false" \ + --config /dev/stdin <&1 | sed 's/^/[amd64] /' echo -e "${GREEN}[amd64] Complete!${NC}" @@ -140,7 +151,9 @@ if [ "$PARALLEL" = true ]; then docker buildx build \ --platform linux/arm64 \ -t "${FULL_IMAGE}:${VERSION}-arm64" \ - --provenance=false \ + ${BUILD_ARGS} \ + --cache-from type=registry,ref=${FULL_IMAGE}:cache-arm64 \ + --cache-to type=registry,ref=${FULL_IMAGE}:cache-arm64,mode=max \ --push \ . 2>&1 | sed 's/^/[arm64] /' echo -e "${GREEN}[arm64] Complete!${NC}" @@ -167,10 +180,11 @@ if [ "$PARALLEL" = true ]; then fi else # Sequential build (default): Build both platforms in one command + echo -e "${YELLOW}Building sequentially with ${CPU_COUNT} cores...${NC}" DOCKER_BUILDKIT=1 docker buildx build \ --platform "$PLATFORMS" \ - --build-arg BUILDKIT_INLINE_CACHE=1 \ - --provenance=false \ + ${BUILD_ARGS} \ + ${CACHE_ARGS} \ $TAGS \ --push \ .