mirror of
https://gitlab.com/stilobique/blender-docker.git
synced 2026-05-28 04:37:47 +02:00
40 lines
1.3 KiB
Python
40 lines
1.3 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})
|
|
|
|
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)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Make or update the docker container
|
|
get_repo_container()
|
|
print('Blender repo set')
|