import os
import shutil

docker_reg = 'localhost:5000'
DOCKER_COMPOSE_NAME = "Dockerfile"

paths = []
for r, _, f in os.walk('./'):
    for file in f:
        if DOCKER_COMPOSE_NAME == file:
            paths.append(os.path.join(r, ''))

command_args = [{'path': path,
    'name': str(path).split('/')[-2]}
    for path
    in paths]

for command_arg in command_args:
    path = command_arg['path']
    image_name = f"{docker_reg}/{command_arg['name']}"

    # copy Dockerfile into root dir to have access to modules folder
    shutil.copy2(os.path.join(path, DOCKER_COMPOSE_NAME), './')
    os.system(f"docker image build -t {image_name} .")
    os.remove(DOCKER_COMPOSE_NAME)

    os.system(f"docker push {image_name}")

print(f"Found {len(command_args)} images")