Skip to content

Commit

Permalink
volumes cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Wokzy committed May 24, 2022
1 parent dd292f3 commit b9b3db6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
12 changes: 11 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ services:
pyserver:
build: pyserver_build
network_mode: host
volumes:
- hello:/app
ports:
- 1234:1234

Expand All @@ -12,9 +14,17 @@ services:
network_mode: 'host'
depends_on:
- pyserver
volumes:
- client:/client

pyclient2:
build: pyclient_build
network_mode: 'host'
depends_on:
- pyserver
- pyserver

volumes:
hello:
external: false
client:
external: false
28 changes: 23 additions & 5 deletions docker_cleaner
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ def docker_img_check(repo, tag, img_id):
return 1
return 0

def volumes_cleaning():
cntr = 0
volumes = subprocess_run('docker volume ls -f dangling=true').split('\n')[1::]
for volume_line in volumes:
if volume_line:
vol = volume_line.split(' ')[-1]
rs = subprocess_run(f'docker volume rm {vol}')
res.append(f'Removed volume: {vol}')

cntr += 1

return cntr

images = subprocess_run('docker images')
counter = 0
log(images)
Expand All @@ -52,15 +65,20 @@ for image in images.split('\n')[1::]:
data = list(filter(('').__ne__, image.split(' ')))
if len(data) > 0:
counter += docker_img_check(data[0], data[1], data[2])


if counter:
print(f'successfully cleaned {counter}')
print(f'successfully cleaned {counter} images')
log('\n')
for i in res:
log(i)
else:
print('nothing to clean')
print('no images to clean')

vol_res = volumes_cleaning()
if vol_res:
print(f'cleaned {vol_res} volume(s)')

for i in res:
log(i)

images = subprocess_run('docker images')
log('\nFinal state: \n')
Expand Down
4 changes: 2 additions & 2 deletions pyclient_build/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

c = datetime.now()

while (datetime.now() - c).total_seconds() < 26:
while (datetime.now() - c).total_seconds() < 16:
time_passed = int((datetime.now() - c).total_seconds())
if time_passed % 5 == 0:
sock.send(bytes(f'time passed: {time_passed}\n'.encode('ascii')))
Expand All @@ -16,4 +16,4 @@

sock.shutdown(socket.SHUT_RDWR)
time.sleep(0.1)
sock.close()
sock.close() #45646
2 changes: 1 addition & 1 deletion pyserver_build/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
inputs = [sock]
outputs = []

messages = {}
messages = {}#1234

print('binded')

Expand Down

0 comments on commit b9b3db6

Please sign in to comment.