Skip to content

Commit 1fe5553

Browse files
space testing
1 parent d11e925 commit 1fe5553

File tree

2 files changed

+239
-0
lines changed

2 files changed

+239
-0
lines changed
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
name: "Agressivly Maximize Space"
2+
description: "Maximize the available disk space for your build job"
3+
branding:
4+
icon: "crop"
5+
color: "orange"
6+
inputs:
7+
root-reserve-mb:
8+
description: "Space to be left free on the root filesystem, in Megabytes."
9+
required: false
10+
default: "1024"
11+
swap-size-mb:
12+
description: "Swap space to create, in Megabytes."
13+
required: false
14+
default: "4096"
15+
build-mount-path:
16+
description: "Absolute path to the mount point where the build space will be available, defaults to $GITHUB_WORKSPACE if unset."
17+
required: false
18+
build-mount-path-ownership:
19+
description: 'Ownership of the mount point path, defaults to standard "runner" user and group.'
20+
required: false
21+
default: "runner:runner"
22+
pv-loop-path:
23+
description: "Absolute file path for the LVM image created on the root filesystem, the default is usually fine."
24+
required: false
25+
default: "/pv.img"
26+
tmp-pv-loop-path:
27+
description: "Absolute file path for the LVM image created on the temp filesystem, the default is usually fine. Must reside on /mnt"
28+
required: false
29+
default: "/mnt/tmp-pv.img"
30+
boot-pv-loop-path:
31+
description: "Absolute file path for the LVM image created on the boot filesystem, the default is usually fine. Must reside on /boot"
32+
required: false
33+
default: "/boot/boot-pv.img"
34+
35+
runs:
36+
using: "composite"
37+
steps:
38+
- name: Disk space report before modification
39+
shell: bash
40+
run: |
41+
echo "Memory and swap:"
42+
sudo free -h
43+
echo
44+
sudo swapon --show
45+
echo
46+
47+
echo "Available storage:"
48+
sudo df -h
49+
echo
50+
51+
- name: Show info
52+
shell: bash
53+
run: |
54+
set -euo pipefail
55+
56+
BUILD_MOUNT_PATH="${{ inputs.build-mount-path }}"
57+
if [[ -z "${BUILD_MOUNT_PATH}" ]]; then
58+
BUILD_MOUNT_PATH="${GITHUB_WORKSPACE}"
59+
fi
60+
61+
echo "Arguments:"
62+
echo
63+
echo " Root reserve: ${{ inputs.root-reserve-mb }} MiB"
64+
echo " Swap space: ${{ inputs.swap-size-mb }} MiB"
65+
echo " Mount path: ${BUILD_MOUNT_PATH}"
66+
echo " Root PV loop path: ${{ inputs.pv-loop-path }}"
67+
echo " Temp PV loop path: ${{ inputs.tmp-pv-loop-path }}"
68+
echo " Boot PV loop path: ${{ inputs.boot-pv-loop-path }}"
69+
echo " EFI PV loop path: ${{ inputs.efi-pv-loop-path }}"
70+
71+
- name: Prune Docker
72+
shell: bash
73+
run: sudo docker image prune --all --force
74+
75+
- name: Remove apt packages
76+
shell: bash
77+
run: |
78+
echo "Removing packages from apt"
79+
PACKAGES=(
80+
'microsoft-edge-stable'
81+
'azure-cli'
82+
'^google.*'
83+
'^temurin.*'
84+
'powershell'
85+
'^llvm.*'
86+
'snapd'
87+
'.*python.*'
88+
'containerd.io'
89+
'^docker-ce.*'
90+
'podman'
91+
'kubectl'
92+
'^clang.*'
93+
'^cpp.*'
94+
'.*postgres.*'
95+
'.*mysql.*'
96+
'.*sqlite.*'
97+
'mecab-ipadic'
98+
'.*gfortran.*'
99+
'apache2-bin'
100+
'shellcheck'
101+
'git-lfs'
102+
'mercurial'
103+
'adwaita-icon-theme'
104+
'^php.*'
105+
'ant'
106+
'shim-signed'
107+
)
108+
sudo apt-get remove --purge -y --allow-remove-essential ${PACKAGES[@]}
109+
sudo apt-get autoremove -y
110+
sudo apt-get clean -y
111+
112+
- name: Remove biggest directories
113+
shell: bash
114+
run: |
115+
echo "Removing directories"
116+
DIRS=(
117+
'/usr/local/lib/android'
118+
'/usr/local/.ghcup'
119+
'/opt/hostedtoolcache'
120+
'/usr/share/dotnet'
121+
'/usr/share/swift'
122+
'/usr/local/share/powershell'
123+
'/usr/share/miniconda'
124+
/usr/share/gradle*
125+
/usr/local/julia*
126+
'/home/runner/.rustup'
127+
'/home/runner/.cargo'
128+
'/home/runner/.dotnet'
129+
'/home/runner/.nvm'
130+
'/usr/local/share/chromium'
131+
'/opt/pipx'
132+
'/usr/local/aws-cli'
133+
'/home/packer'
134+
/root/*
135+
'/etc/skel'
136+
'/usr/local/aws-sam-cli'
137+
'/usr/libexec/docker'
138+
'/home/linuxbrew'
139+
'/usr/share/kotlinc'
140+
/usr/share/apache-maven*
141+
/boot/efi/*
142+
/boot/initrd*
143+
/boot/vmlinuz*
144+
)
145+
sudo rm -rf ${DIRS[@]}
146+
147+
- name: Remove Swap
148+
shell: bash
149+
run: |
150+
echo 'Removing Swap'
151+
sudo swapoff -a
152+
sudo rm -f /mnt/swapfile
153+
154+
- name: Create LVM Volume
155+
shell: bash
156+
run: |
157+
set -euo pipefail
158+
159+
BUILD_MOUNT_PATH="${{ inputs.build-mount-path }}"
160+
if [[ -z "${BUILD_MOUNT_PATH}" ]]; then
161+
BUILD_MOUNT_PATH="${GITHUB_WORKSPACE}"
162+
fi
163+
164+
VG_NAME=buildvg
165+
166+
echo "Creating LVM Volume."
167+
echo " Creating LVM PV on root fs."
168+
# create loop pv image on root fs
169+
ROOT_RESERVE_KB=$(expr ${{ inputs.root-reserve-mb }} \* 1024)
170+
ROOT_FREE_KB=$(df --block-size=1024 --output=avail / | tail -1)
171+
ROOT_LVM_SIZE_KB=$(expr $ROOT_FREE_KB - $ROOT_RESERVE_KB)
172+
ROOT_LVM_SIZE_BYTES=$(expr $ROOT_LVM_SIZE_KB \* 1024)
173+
sudo touch "${{ inputs.pv-loop-path }}" && sudo fallocate -z -l "${ROOT_LVM_SIZE_BYTES}" "${{ inputs.pv-loop-path }}"
174+
export ROOT_LOOP_DEV=$(sudo losetup --find --show "${{ inputs.pv-loop-path }}")
175+
sudo pvcreate -f "${ROOT_LOOP_DEV}"
176+
177+
# create pv on temp disk
178+
echo " Creating LVM PV on temp fs."
179+
TMP_FREE_KB=$(df --block-size=1024 --output=avail /mnt | tail -1)
180+
TMP_LVM_SIZE_KB=$TMP_FREE_KB
181+
TMP_LVM_SIZE_BYTES=$(expr $TMP_LVM_SIZE_KB \* 1024)
182+
sudo touch "${{ inputs.tmp-pv-loop-path }}" && sudo fallocate -z -l "${TMP_LVM_SIZE_BYTES}" "${{ inputs.tmp-pv-loop-path }}"
183+
export TMP_LOOP_DEV=$(sudo losetup --find --show "${{ inputs.tmp-pv-loop-path }}")
184+
sudo pvcreate -f "${TMP_LOOP_DEV}"
185+
186+
# create pv on boot disk
187+
echo " Creating LVM PV on boot fs."
188+
BOOT_FREE_KB=$(df --block-size=1024 --output=avail /boot | tail -1)
189+
BOOT_LVM_SIZE_KB=$BOOT_FREE_KB
190+
BOOT_LVM_SIZE_BYTES=$(expr $BOOT_LVM_SIZE_KB \* 1024)
191+
sudo touch "${{ inputs.boot-pv-loop-path }}" && sudo fallocate -z -l "${BOOT_LVM_SIZE_BYTES}" "${{ inputs.boot-pv-loop-path }}"
192+
export BOOT_LOOP_DEV=$(sudo losetup --find --show "${{ inputs.boot-pv-loop-path }}")
193+
sudo pvcreate -f "${BOOT_LOOP_DEV}"
194+
195+
# create volume group from these pvs
196+
sudo vgcreate "${VG_NAME}" "${TMP_LOOP_DEV}" "${ROOT_LOOP_DEV}" "${BOOT_LOOP_DEV}"
197+
198+
echo "Recreating swap"
199+
# create and activate swap
200+
sudo lvcreate -L "${{ inputs.swap-size-mb }}M" -n swap "${VG_NAME}"
201+
sudo mkswap "/dev/mapper/${VG_NAME}-swap"
202+
sudo swapon "/dev/mapper/${VG_NAME}-swap"
203+
204+
echo "Creating build volume"
205+
# create and mount build volume
206+
sudo lvcreate -l 100%FREE -n buildlv "${VG_NAME}"
207+
sudo mkfs.btrfs -K --compress zstd:5 "/dev/mapper/${VG_NAME}-buildlv"
208+
sudo mount -o compress=zstd,noatime "/dev/mapper/${VG_NAME}-buildlv" "${BUILD_MOUNT_PATH}"
209+
sudo chown -R "${{ inputs.build-mount-path-ownership }}" "${BUILD_MOUNT_PATH}"
210+
211+
# if build mount path is a parent of $GITHUB_WORKSPACE, and has been deleted, recreate it
212+
if [[ ! -d "${GITHUB_WORKSPACE}" ]]; then
213+
sudo mkdir -p "${GITHUB_WORKSPACE}"
214+
sudo chown -R "${WORKSPACE_OWNER}" "${GITHUB_WORKSPACE}"
215+
fi
216+
217+
- name: Disk space report after modification
218+
shell: bash
219+
run: |
220+
echo "Memory and swap:"
221+
sudo free -h
222+
echo
223+
sudo swapon --show
224+
echo
225+
226+
echo "Available storage:"
227+
sudo df -h

.github/workflows/space.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
on:
2+
workflow_dispatch:
3+
4+
jobs:
5+
test:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: "actions/checkout@v6"
9+
- uses: "./.github/actions/aggressive-space"
10+
with:
11+
swap-size-mb: "1024"
12+
build-mount-path: /nix/store

0 commit comments

Comments
 (0)