Files
blender-docker/generate-image-repo.py
T

42 lines
1.4 KiB
Python

import docker
import os
def get_repo_container():
"""
- Check if a blender/csv image local exist
- If yes, check if a container exist
:return:
"""
client = docker.from_env()
if os.environ.get('docker_hub_password'):
client.login(username=os.environ['docker_hub_user'], password=os.environ['docker_hub_password'])
dk_tags = 'stilobique/csv'
dk_container_name = 'blender-cache-repo'
dk_images_local = client.images.list(name=dk_tags)
dk_containers_local = client.containers.list(filters={'label': dk_container_name})
volumes = ["/scripts/:/scripts"]
commandes = ['bash', '/scripts/set_all_repository.sh']
if dk_containers_local:
# The container cache exist, used-it
client.containers.run(image=dk_tags, name=dk_container_name)
pass
elif dk_images_local:
# No container, but the image are build, start a container cache
client.containers.run(image=dk_tags, name=dk_container_name)
pass
else:
# No container, no image ; build a new image and start this cache
client.images.build(path="image", dockerfile="Dockerfile-csv", tag=f'{dk_tags}:latest', rm=True)
client.containers.run(image=dk_tags, name=dk_container_name, volumes=volumes, command=commandes)
if __name__ == "__main__":
# Make or update the docker container
get_repo_container()
print('Blender repo set')