Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding a TTL to autoclose gates #1

Open
JohannesRudolph opened this issue Oct 20, 2018 · 1 comment
Open

Consider adding a TTL to autoclose gates #1

JohannesRudolph opened this issue Oct 20, 2018 · 1 comment

Comments

@JohannesRudolph
Copy link
Member

Our CI pipeline builds feature branches using autoclose gates. It is expected that builds on feature branches fail from time to time and may be corrected by developers. This leaves autoclose gates open and "stranded".

When processing autoclose items, the gate resource should probably perform a cleanup of gates after a configurable TTL. Thinking of it, there might be value to having a TTL for gates in general (i.e. reduced git checkout size and less load on the filesystem). This might be best delegated to a "sidecar" task that runs on the gate-repo

@JohannesRudolph
Copy link
Member Author

JohannesRudolph commented Apr 15, 2020

I've experimented with a script like this to clean up gate files older than 7 days

#!/bin/bash

set -o errexit
set -o errtrace
set -o pipefail
set -o nounset

function cleanup()
{
  stamp=$(date +%s)
  day=$((60*60*24))
  old=$(($stamp - 7*$day))

  echo "cleaning any file commited older than $old"
  
  while read FILE; do
    
    modified=$(git log --pretty="%ad" --date=unix -1 -- "$FILE")
    if [ $modified -lt $old ]; then
      echo "$FILE $modified is old, cleaning"
      rm "$FILE"
    else
      echo "$FILE $modified is not old"
    fi;

  done < <( git ls-files )
}

cleanup

When commiting to the gate repository, use something like git commit -am "[ci skip] cleanup old gates" so that the commit is not picked up accidentally as a valid gate-modifying commit. Otherwise you'll see errors like could not determine passed file in version ... in your gate resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant