2023-02-24 01:31:05 +01:00
|
|
|
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'])
|
|
|
|
|
|
2023-02-24 02:05:46 +01:00
|
|
|
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})
|
2023-02-24 02:22:59 +01:00
|
|
|
volumes = ["/scripts/:/scripts"]
|
|
|
|
|
commandes = ['bash', '/scripts/set_all_repository.sh']
|
2023-02-24 02:05:46 +01:00
|
|
|
|
|
|
|
|
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
|
2023-02-24 01:31:05 +01:00
|
|
|
|
|
|
|
|
else:
|
2023-02-24 02:05:46 +01:00
|
|
|
# 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)
|
2023-02-24 02:22:59 +01:00
|
|
|
client.containers.run(image=dk_tags, name=dk_container_name, volumes=volumes, command=commandes)
|
2023-02-24 01:31:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
# Make or update the docker container
|
|
|
|
|
get_repo_container()
|
|
|
|
|
print('Blender repo set')
|