diff --git a/.github/actions/initialize-environment/action.yaml b/.github/actions/initialize-environment/action.yaml new file mode 100644 index 000000000..af229dbfa --- /dev/null +++ b/.github/actions/initialize-environment/action.yaml @@ -0,0 +1,61 @@ +name: Initialize Environment + +description: Initialization steps for kagent actions + +runs: + using: "composite" + steps: + - name: Cancel Previous Actions + uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # 0.12.1 + with: + access_token: ${{ github.token }} + - name: Free disk space + shell: bash + run: | + echo "Before clearing disk space:" + df -h + docker system df -v + + # https://github.com/actions/runner-images/discussions/3242 github runners are bad at cleanup + echo "Removing large packages" + sudo apt-get remove -y '^dotnet-.*' || true + sudo apt-get remove -y '^llvm-.*' || true + sudo apt-get remove -y 'php.*' || true + sudo apt-get remove -y '^mongodb-.*' || true + sudo apt-get remove -y '^mysql-.*' || true + sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri || true + sudo apt-get autoremove -y || true + sudo apt-get clean -y || true + echo "Done removing large packages" + + # Clean up pre-installed tools + # For some reason, GHA often takes minutes (up to 20min observed) to clean up somehow. + # Presumably this is due to a slow disk? + function clean-dir() { + echo "Cleaning $1" + time sudo rm -rf "$1" || true + } + # These two were found to take very very long. Even though its large, its not worth the cost + # clean-dir /usr/local/lib/android # 8.9gb + # clean-dir $AGENT_TOOLSDIRECTORY # 5.6gb + clean-dir /usr/share/dotnet # 3.4gb + clean-dir /usr/share/swift # 3.1gb + clean-dir /usr/local/.ghcup # 6.3gb + clean-dir /usr/local/share/powershell # 1.2gb + clean-dir /usr/local/share/chromium # 600mb + + # Clean up images + docker image rm node:18 || true + docker image rm node:18-alpine || true + docker image rm node:20 || true + docker image rm node:20-alpine || true + # remove the dangling images and containers + docker images | tail -n +2 | awk '$1 == "" {print $3}' | xargs --no-run-if-empty docker rmi + docker ps -a | tail -n +2 | awk '$2 ~ "^[0-9a-f]+$" {print $1}' | xargs --no-run-if-empty docker rm --volumes=true + + # Clean up Docker + docker system prune -f || true + + echo "After clearing disk space:" + df -h + docker system df -v diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5f941ecc4..97eea7bce 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -40,6 +40,8 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + - name: Initialize Environment + uses: ./.github/actions/initialize-environment - name: Set up QEMU uses: docker/setup-qemu-action@v3 with: diff --git a/python/samples/crewai/poem_flow/Dockerfile b/python/samples/crewai/poem_flow/Dockerfile index e29ddc1e2..c25697dab 100644 --- a/python/samples/crewai/poem_flow/Dockerfile +++ b/python/samples/crewai/poem_flow/Dockerfile @@ -8,7 +8,8 @@ WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ build-essential \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* \ + && apt-get clean # Copy project files COPY samples samples @@ -19,7 +20,8 @@ COPY .python-version .python-version COPY uv.lock uv.lock # Install dependencies -RUN uv venv && uv sync --locked --no-dev --package poem-flow +RUN uv venv && uv sync --locked --no-dev --package poem-flow \ + && uv cache clean # Set environment variables ENV PORT=8080 diff --git a/python/samples/crewai/research-crew/Dockerfile b/python/samples/crewai/research-crew/Dockerfile index 8fe33d48a..48f20cfa2 100644 --- a/python/samples/crewai/research-crew/Dockerfile +++ b/python/samples/crewai/research-crew/Dockerfile @@ -8,7 +8,8 @@ WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ build-essential \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* \ + && apt-get clean # Copy project files COPY samples samples @@ -19,7 +20,8 @@ COPY .python-version .python-version COPY uv.lock uv.lock # Install dependencies -RUN uv venv && uv sync --locked --no-dev --package research-crew +RUN uv venv && uv sync --locked --no-dev --package research-crew \ + && uv cache clean # Set environment variables ENV PORT=8080 diff --git a/python/samples/langgraph/currency/Dockerfile b/python/samples/langgraph/currency/Dockerfile index 809b1d1f5..bd0383ae7 100644 --- a/python/samples/langgraph/currency/Dockerfile +++ b/python/samples/langgraph/currency/Dockerfile @@ -8,7 +8,8 @@ WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ build-essential \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* \ + && apt-get clean # Copy project files COPY samples samples @@ -19,7 +20,8 @@ COPY .python-version .python-version COPY uv.lock uv.lock # Install dependencies -RUN uv sync --locked --no-dev +RUN uv sync --locked --no-dev \ + && uv cache clean # Set environment variables ENV PYTHONPATH=/app