1
0
Fork 0

added cleanup of build folders

This commit is contained in:
Christian Kühnel 2019-10-05 12:15:16 +02:00
parent 8b96eaa7b0
commit 511a828ca2
3 changed files with 39 additions and 1 deletions

View file

@ -1,6 +1,16 @@
FROM nginx:1.17
RUN set -e ;\
apt-get update ;\
apt-get install -y --no-install-recommends python3 cron;\
apt-get clean
RUN mkdir -p /scripts
COPY index.html run_nginx.sh /scripts/
COPY index.html run_nginx.sh clean_results.py /scripts/
COPY default.conf /etc/nginx/conf.d/
COPY crontab /etc/cron.d/clean_results
RUN chmod 0644 /etc/cron.d/clean_results
RUN service cron start
CMD ["/scripts/run_nginx.sh"]

View file

@ -0,0 +1,26 @@
#!/usr/bin/python3
import datetime
import os
import shutil
ROOT_DIR = '/mnt/nfs/results'
MAX_AGE = datetime.timedelta(days=90)
MAX_AGE_BIN = datetime.timedelta(days=3)
now = datetime.datetime.now()
for folder in [f for f in os.listdir(ROOT_DIR)]:
fullpath = os.path.join(ROOT_DIR, folder)
if not os.path.isdir(fullpath):
continue
print(fullpath)
binpath = os.path.join(ROOT_DIR, folder, 'binaries')
stats=os.stat('/tmp')
created = datetime.datetime.fromtimestamp(stats.st_mtime)
print(created)
if created + MAX_AGE < now:
print("Deleting all results: {}".format(fullpath))
shutil.rmtree(fullpath)
elif os.path.exists(binpath) and created + MAX_AGE_BIN < now:
print("Deleting binaries: {}".format(binaries))
shutil.rmtree(binpath)

View file

@ -0,0 +1,2 @@
* * * * * /scripty/clean_results.py
# Mandatory blank line