From 32397e0cc2c3b59fb9bab3db8298e239c59345d5 Mon Sep 17 00:00:00 2001 From: Cliff Hill Date: Tue, 28 Oct 2025 09:30:12 -0400 Subject: [PATCH] Optimizing build memory usage. Signed-off-by: Cliff Hill --- .dockerignore | 3 +++ Dockerfile.cicd | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index af98ce1..c6e9b4e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -28,6 +28,9 @@ secrets/ **/node_modules/ **/dist/ **/build/ +**/.yarn/cache/ +**/.yarn/install-state.gz +**/yarn-cache/ # IDE files .vscode/ diff --git a/Dockerfile.cicd b/Dockerfile.cicd index 9173013..2132ab6 100644 --- a/Dockerfile.cicd +++ b/Dockerfile.cicd @@ -38,6 +38,12 @@ RUN apt-fast update && apt-fast install -y \ tzdata \ && rm -rf /var/lib/apt/lists/* +# Configure system for memory-intensive builds +RUN echo "vm.overcommit_memory=1" >> /etc/sysctl.conf && \ + echo "vm.max_map_count=262144" >> /etc/sysctl.conf && \ + sysctl -w vm.overcommit_memory=1 && \ + sysctl -w vm.max_map_count=262144 + # Install Python 3.13 with retry and fallback mechanisms RUN for i in 1 2 3; do \ echo "Attempt $i: Adding deadsnakes PPA..." && \ @@ -75,6 +81,13 @@ RUN corepack enable \ && corepack prepare yarn@stable --activate \ && yarn set version berry +# Configure Yarn globally for CI performance +RUN yarn config set httpTimeout 60000 && \ + yarn config set networkTimeout 60000 && \ + yarn config set enableGlobalCache false && \ + yarn config set compressionLevel 0 && \ + export NODE_OPTIONS="--max-old-space-size=2048" + # Install uv package manager globally COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv @@ -117,7 +130,39 @@ RUN uv pip install -e . # Set up frontend dependencies WORKDIR /workspace/frontend -RUN yarn install --immutable + +# Create temporary swap file for memory-intensive yarn install +RUN dd if=/dev/zero of=/tmp/swapfile bs=1M count=1024 2>/dev/null && \ + mkswap /tmp/swapfile && \ + swapon /tmp/swapfile || echo "Swap setup failed, continuing without swap" + +# Configure Yarn for CI environment with memory optimizations +RUN echo "# CI optimizations" >> .yarnrc.yml && \ + echo "httpTimeout: 60000" >> .yarnrc.yml && \ + echo "networkTimeout: 60000" >> .yarnrc.yml && \ + echo "enableGlobalCache: false" >> .yarnrc.yml && \ + echo "compressionLevel: 0" >> .yarnrc.yml && \ + echo "nmMode: hardlinks-local" >> .yarnrc.yml + +# Install frontend dependencies with memory optimizations and retry mechanism +RUN export NODE_OPTIONS="--max-old-space-size=2048 --gc-interval=100" && \ + export YARN_ENABLE_NETWORK=1 && \ + for i in 1 2 3; do \ + echo "Attempt $i: Installing frontend dependencies..." && \ + yarn install --immutable \ + --network-timeout 60000 \ + --cache-folder /tmp/yarn-cache \ + --network-concurrency 1 \ + --verbose \ + && break || \ + (echo "Attempt $i failed, cleaning up and retrying..." && \ + rm -rf node_modules .yarn/cache .yarn/install-state.gz /tmp/yarn-cache && \ + yarn cache clean --all 2>/dev/null || true && \ + sleep 15); \ + done && \ + rm -rf /tmp/yarn-cache .yarn/cache && \ + swapoff /tmp/swapfile 2>/dev/null || true && \ + rm -f /tmp/swapfile # Verify all tools are working with the project RUN cd /workspace/backend && \