Skip to content

Commit a0f2541

Browse files
authored
fix(ci): Clean up GH environment so there is more disk space for workflows (#1108)
# Changes - Add reusable environment cleanup action. - Clean up environment before running CI to avoid - or at least lessen - space issues. - Added uv + apt-get cache cleanup. - May not be necessary with the environment cleanups, but couldn't be too cleared of cache. # Context I have recently seen instances ([1](https://github.com/kagent-dev/kagent/actions/runs/19438427104/job/55615392952?pr=1104), [2](https://github.com/kagent-dev/kagent/actions/runs/19435624387/job/55614362470?pr=1059), +2 others), where `test-e2e` is failing when setting up the test agents, since it runs out of space during a build. this PR is meant to _hopefully_ completely mitigate that by clearing up space. ## Note(s) The cleanup action is lifted from [kgateway go prep action](https://github.com/kgateway-dev/kgateway/blob/0b703049e4786fc524f428b6de3d01d8724c6c9e/.github/actions/prep-go-runner/action.yaml), without the additional setup there, since this PR is currently focused on clearing space before before running workflows. This is similar to others actions in solo(org)-managed products, so it's a pattern followed. # Before & After **Before clearing disk space:** Filesystem Size Used Avail Use% Mounted on /dev/root 72G 53G 19G 74% / tmpfs 7.9G 84K 7.9G 1% /dev/shm tmpfs 3.2G 1.1M 3.2G 1% /run tmpfs 5.0M 0 5.0M 0% /run/lock /dev/sdb16 881M 62M 758M 8% /boot /dev/sdb15 105M 6.2M 99M 6% /boot/efi /dev/sda1 74G 4.1G 66G 6% /mnt tmpfs 1.6G 12K 1.6G 1% /run/user/1001 **After clearing disk space:** Filesystem Size Used Avail Use% Mounted on /dev/root 72G 34G 38G 48% / tmpfs 7.9G 84K 7.9G 1% /dev/shm tmpfs 3.2G 1.1M 3.2G 1% /run tmpfs 5.0M 0 5.0M 0% /run/lock /dev/sdb16 881M 62M 758M 8% /boot /dev/sdb15 105M 6.2M 99M 6% /boot/efi /dev/sda1 74G 4.1G 66G 6% /mnt tmpfs 1.6G 12K 1.6G 1% /run/user/1001 **Summary:** - Total disk freed: ~19 GB --------- Signed-off-by: Fabian Gonzalez <[email protected]>
1 parent 3e6a2df commit a0f2541

5 files changed

Lines changed: 75 additions & 6 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Initialize Environment
2+
3+
description: Initialization steps for kagent actions
4+
5+
runs:
6+
using: "composite"
7+
steps:
8+
- name: Cancel Previous Actions
9+
uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # 0.12.1
10+
with:
11+
access_token: ${{ github.token }}
12+
- name: Free disk space
13+
shell: bash
14+
run: |
15+
echo "Before clearing disk space:"
16+
df -h
17+
docker system df -v
18+
19+
# https://github.com/actions/runner-images/discussions/3242 github runners are bad at cleanup
20+
echo "Removing large packages"
21+
sudo apt-get remove -y '^dotnet-.*' || true
22+
sudo apt-get remove -y '^llvm-.*' || true
23+
sudo apt-get remove -y 'php.*' || true
24+
sudo apt-get remove -y '^mongodb-.*' || true
25+
sudo apt-get remove -y '^mysql-.*' || true
26+
sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri || true
27+
sudo apt-get autoremove -y || true
28+
sudo apt-get clean -y || true
29+
echo "Done removing large packages"
30+
31+
# Clean up pre-installed tools
32+
# For some reason, GHA often takes minutes (up to 20min observed) to clean up somehow.
33+
# Presumably this is due to a slow disk?
34+
function clean-dir() {
35+
echo "Cleaning $1"
36+
time sudo rm -rf "$1" || true
37+
}
38+
# These two were found to take very very long. Even though its large, its not worth the cost
39+
# clean-dir /usr/local/lib/android # 8.9gb
40+
# clean-dir $AGENT_TOOLSDIRECTORY # 5.6gb
41+
clean-dir /usr/share/dotnet # 3.4gb
42+
clean-dir /usr/share/swift # 3.1gb
43+
clean-dir /usr/local/.ghcup # 6.3gb
44+
clean-dir /usr/local/share/powershell # 1.2gb
45+
clean-dir /usr/local/share/chromium # 600mb
46+
47+
# Clean up images
48+
docker image rm node:18 || true
49+
docker image rm node:18-alpine || true
50+
docker image rm node:20 || true
51+
docker image rm node:20-alpine || true
52+
# remove the dangling images and containers
53+
docker images | tail -n +2 | awk '$1 == "<none>" {print $3}' | xargs --no-run-if-empty docker rmi
54+
docker ps -a | tail -n +2 | awk '$2 ~ "^[0-9a-f]+$" {print $1}' | xargs --no-run-if-empty docker rm --volumes=true
55+
56+
# Clean up Docker
57+
docker system prune -f || true
58+
59+
echo "After clearing disk space:"
60+
df -h
61+
docker system df -v

.github/workflows/ci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ jobs:
4040
steps:
4141
- name: Checkout repository
4242
uses: actions/checkout@v4
43+
- name: Initialize Environment
44+
uses: ./.github/actions/initialize-environment
4345
- name: Set up QEMU
4446
uses: docker/setup-qemu-action@v3
4547
with:

python/samples/crewai/poem_flow/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ WORKDIR /app
88
# Install system dependencies
99
RUN apt-get update && apt-get install -y \
1010
build-essential \
11-
&& rm -rf /var/lib/apt/lists/*
11+
&& rm -rf /var/lib/apt/lists/* \
12+
&& apt-get clean
1213

1314
# Copy project files
1415
COPY samples samples
@@ -19,7 +20,8 @@ COPY .python-version .python-version
1920
COPY uv.lock uv.lock
2021

2122
# Install dependencies
22-
RUN uv venv && uv sync --locked --no-dev --package poem-flow
23+
RUN uv venv && uv sync --locked --no-dev --package poem-flow \
24+
&& uv cache clean
2325

2426
# Set environment variables
2527
ENV PORT=8080

python/samples/crewai/research-crew/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ WORKDIR /app
88
# Install system dependencies
99
RUN apt-get update && apt-get install -y \
1010
build-essential \
11-
&& rm -rf /var/lib/apt/lists/*
11+
&& rm -rf /var/lib/apt/lists/* \
12+
&& apt-get clean
1213

1314
# Copy project files
1415
COPY samples samples
@@ -19,7 +20,8 @@ COPY .python-version .python-version
1920
COPY uv.lock uv.lock
2021

2122
# Install dependencies
22-
RUN uv venv && uv sync --locked --no-dev --package research-crew
23+
RUN uv venv && uv sync --locked --no-dev --package research-crew \
24+
&& uv cache clean
2325

2426
# Set environment variables
2527
ENV PORT=8080

python/samples/langgraph/currency/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ WORKDIR /app
88
# Install system dependencies
99
RUN apt-get update && apt-get install -y \
1010
build-essential \
11-
&& rm -rf /var/lib/apt/lists/*
11+
&& rm -rf /var/lib/apt/lists/* \
12+
&& apt-get clean
1213

1314
# Copy project files
1415
COPY samples samples
@@ -19,7 +20,8 @@ COPY .python-version .python-version
1920
COPY uv.lock uv.lock
2021

2122
# Install dependencies
22-
RUN uv sync --locked --no-dev
23+
RUN uv sync --locked --no-dev \
24+
&& uv cache clean
2325

2426
# Set environment variables
2527
ENV PYTHONPATH=/app

0 commit comments

Comments
 (0)