added cleanup of build folders
This commit is contained in:
parent
8b96eaa7b0
commit
511a828ca2
3 changed files with 39 additions and 1 deletions
|
@ -1,6 +1,16 @@
|
||||||
FROM nginx:1.17
|
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
|
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 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"]
|
CMD ["/scripts/run_nginx.sh"]
|
26
containers/nginx-results/clean_results.py
Executable file
26
containers/nginx-results/clean_results.py
Executable 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)
|
2
containers/nginx-results/crontab
Normal file
2
containers/nginx-results/crontab
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
* * * * * /scripty/clean_results.py
|
||||||
|
# Mandatory blank line
|
Loading…
Reference in a new issue