-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: clean up old runs on the server (#357)
* ci: clean up old logs on the server * ci: start the interop run after the cleanup job
- Loading branch information
1 parent
149e197
commit cc58623
Showing
2 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: cleanup | ||
on: | ||
schedule: | ||
- cron: "0 */8 * * *" # every 8h | ||
|
||
jobs: | ||
cleanup: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Delete old logs on the server | ||
uses: appleboy/ssh-action@8f949198563a347a01c65ffc60399aef2b59d4ab # v1.0.1 | ||
with: | ||
host: interop.seemann.io | ||
username: ${{ secrets.INTEROP_SEEMANN_IO_USER }} | ||
key: ${{ secrets.INTEROP_SEEMANN_IO_SSH_KEY }} | ||
script: | | ||
delete_oldest_folder() { | ||
OLDEST_DIR=$(find "${{ vars.LOG_DIR }}" -mindepth 1 -maxdepth 1 -type d -printf '%T+ %p\n' | sort | head -n 1 | cut -d" " -f2-) | ||
if [[ -n "$OLDEST_DIR" ]]; then | ||
echo "Deleting oldest directory: $OLDEST_DIR" | ||
rm -rf "$OLDEST_DIR" | ||
fi | ||
} | ||
# Loop until enough space is available or no directories left to delete | ||
while true; do | ||
AVAILABLE_SPACE_GB=$(df -BG "${{ vars.LOG_DIR }}" | tail -n 1 | awk '{print $4}' | sed 's/G//') | ||
echo "Available Space: $AVAILABLE_SPACE_GB GB" | ||
if [[ "$AVAILABLE_SPACE_GB" -lt 50 ]]; then | ||
echo "Less than 50 GB available. Trying to clean up..." | ||
delete_oldest_folder | ||
else | ||
echo "Enough space available." | ||
break | ||
fi | ||
done | ||
TEMP_FILE=$(mktemp) | ||
find "${{ vars.LOG_DIR }}" -mindepth 1 -maxdepth 1 -type d -not -name 'lost+found' -exec basename {} \; | sort > "$TEMP_FILE" | ||
jq -R -s 'split("\n") | map(select(. != ""))' "$TEMP_FILE" > "${{ vars.LOG_DIR }}/logs.json" | ||
rm -f "$TEMP_FILE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters