fix(ci): add disk cleanup, replace sudo with su for LXC runner

LXC runner lacks sudo — use su - postgres instead.
Runner disks accumulate Docker images and temp files from prior CI
runs. Add pre-build and post-build cleanup steps (docker system prune,
apt-get clean, rm -rf /tmp /var/tmp) to both build-and-test and
docker-build jobs, with if: always() on post steps.
This commit is contained in:
Arnaud Dartois committed 2026-07-22 07:20:22 +00:00
1 parent 716eaf0470
commit b727e5b672
1 file changed
+41 -10
+41 -10
View File
@@ -34,31 +34,47 @@ jobs:
with:
fetch-depth: 0
# ── Housekeeping before the build ──────────────────────────
- name: Pre-build cleanup
run: |
echo "=== Disk before cleanup ==="
df -h / /var/lib/docker 2>/dev/null || df -h /
# Remove leftover Docker images from previous runs
docker system prune -af 2>/dev/null || true
# Clean apt cache
apt-get clean 2>/dev/null || true
rm -rf /var/lib/apt/lists/* 2>/dev/null || true
# Remove temp files from previous CI runs
rm -rf /tmp/* /var/tmp/* 2>/dev/null || true
# Clean .NET temporary files
rm -rf /tmp/NuGetScratch 2>/dev/null || true
echo "=== Disk after cleanup ==="
df -h /
- name: Start PostgreSQL
# LXC runners have limited disk space. Store PostgreSQL data on
# /dev/shm (tmpfs/RAM) to avoid "No space left on device" errors
# from EnsureCreated() / Migrate() creating tables per test class.
# Runner: Debian 12 LXC — sudo is NOT available (use su - postgres).
# Store data on /dev/shm (tmpfs/RAM) to avoid disk space limits.
run: |
apt-get -qq update
apt-get install -y -qq --no-install-recommends postgresql-15 postgresql-client-15
PGDATA=/dev/shm/pgdata
rm -rf "$PGDATA"
sudo -u postgres /usr/lib/postgresql/15/bin/initdb -D "$PGDATA" --auth=trust --no-locale --encoding=UTF8
su - postgres -c "/usr/lib/postgresql/15/bin/initdb -D $PGDATA --auth=trust --no-locale --encoding=UTF8"
# Configure password auth for the heimdall user (md5 for non-local socket)
cat >> "$PGDATA/pg_hba.conf" << 'EOF'
su - postgres -c "cat >> $PGDATA/pg_hba.conf << 'EOF'
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
EOF
EOF"
# Start PostgreSQL
sudo -u postgres /usr/lib/postgresql/15/bin/pg_ctl -D "$PGDATA" -l /dev/shm/pgdata.log start
su - postgres -c "/usr/lib/postgresql/15/bin/pg_ctl -D $PGDATA -l /dev/shm/pgdata.log start"
# Wait for startup
for i in $(seq 1 15); do
sudo -u postgres /usr/lib/postgresql/15/bin/pg_isready -h localhost > /dev/null 2>&1 && break
su - postgres -c "/usr/lib/postgresql/15/bin/pg_isready -h localhost" > /dev/null 2>&1 && break
sleep 1
done
# Create user and database
sudo -u postgres psql -c "CREATE USER heimdall WITH PASSWORD 'heimdall';" 2>/dev/null || true
sudo -u postgres psql -c "CREATE DATABASE heimdall_test OWNER heimdall;" 2>/dev/null || true
su - postgres -c "psql -c \"CREATE USER heimdall WITH PASSWORD 'heimdall';\"" 2>/dev/null || true
su - postgres -c "psql -c \"CREATE DATABASE heimdall_test OWNER heimdall;\"" 2>/dev/null || true
# Verify connectivity
PGPASSWORD=heimdall psql -U heimdall -d heimdall_test -h localhost -c "SELECT 1" > /dev/null 2>&1 || \
(echo "ERROR: Cannot connect to PostgreSQL"; exit 1)
@@ -88,6 +104,15 @@ jobs:
env:
DATABASE_URL: "Host=localhost;Port=5432;Database=heimdall_test;Username=heimdall;Password=heimdall"
# ── Housekeeping after the build ──────────────────────────
- name: Post-build cleanup
if: always()
run: |
docker system prune -af 2>/dev/null || true
apt-get clean 2>/dev/null || true
rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/* 2>/dev/null || true
rm -rf /root/.dotnet/**/debug/*.log 2>/dev/null || true
docker-build:
needs: build-and-test
runs-on: debian-12
@@ -154,3 +179,9 @@ jobs:
${{ secrets.DOCKER_USERNAME }}/heimdall-agent:latest
docker push ${{ secrets.DOCKER_USERNAME }}/heimdall-agent:${{ forgejo.sha }}
docker push ${{ secrets.DOCKER_USERNAME }}/heimdall-agent:latest
- name: Post-build cleanup (docker-build)
if: always()
run: |
docker system prune -af 2>/dev/null || true
df -h /