-
Notifications
You must be signed in to change notification settings - Fork 2
/
entrypoint.py
51 lines (33 loc) · 990 Bytes
/
entrypoint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
import os
import stat
import subprocess
import time
import schedule
from envparse import env
env.read_envfile()
socket = env('DOCKER_SOCK', default='/var/run/docker.sock')
def validate_socket():
"""Validate if we have access to the socket, die otherwise"""
mode = os.stat(socket).st_mode
assert stat.S_ISSOCK(mode)
print(socket, 'ok')
def docker(*args):
return subprocess.check_output(['docker', f'-Hunix://{socket}', *args]).decode()
def prune():
print('Running docker system prune..')
print(
docker('system', 'prune', '--volumes', '--all', '--force'),
)
print('Running docker volume prune...')
print(
docker('volume', 'prune', '--force'),
)
if __name__ == '__main__':
validate_socket()
at = env('AT', default='05:44')
print(f'Scheduling periodic prune at {at}...')
schedule.every().day.at(at).do(prune)
while True:
schedule.run_pending()
time.sleep(1)