This commit is contained in:
parent
46e94a5d84
commit
7b32044803
44
sync.py
44
sync.py
@ -40,6 +40,19 @@ async def docker_push(image: str) -> int | None:
|
|||||||
print(f"Pushing image {image}...")
|
print(f"Pushing image {image}...")
|
||||||
return await run_command(f"docker push {image}")
|
return await run_command(f"docker push {image}")
|
||||||
|
|
||||||
|
async def docker_task(source: str, target: str) -> int | None:
|
||||||
|
print(f"Pulling image {source}...")
|
||||||
|
if r := await docker_pull(source):
|
||||||
|
if r != 0:
|
||||||
|
return r
|
||||||
|
if r := await docker_tag(source, target):
|
||||||
|
if r != 0:
|
||||||
|
return r
|
||||||
|
if r := await docker_push(target):
|
||||||
|
if r != 0:
|
||||||
|
return r
|
||||||
|
return 0
|
||||||
|
|
||||||
semaphore = asyncio.Semaphore(50)
|
semaphore = asyncio.Semaphore(50)
|
||||||
|
|
||||||
async def limited_task[T: Any](task: Callable[[], Coroutine[None, None, T]]) -> T:
|
async def limited_task[T: Any](task: Callable[[], Coroutine[None, None, T]]) -> T:
|
||||||
@ -61,38 +74,11 @@ async def main():
|
|||||||
for image in config.images:
|
for image in config.images:
|
||||||
if len(image.tags) > 0:
|
if len(image.tags) > 0:
|
||||||
for tag in image.tags:
|
for tag in image.tags:
|
||||||
# 定义任务函数
|
|
||||||
async def task():
|
|
||||||
print(f"Pulling image {image.source}:{tag}...")
|
|
||||||
if r := await docker_pull(f"{image.source}:{tag}"):
|
|
||||||
if r != 0:
|
|
||||||
return r
|
|
||||||
await docker_tag(f"{image.source}:{tag}", f"{image.target}:{tag}")
|
|
||||||
if r := await docker_push(f"{image.target}:{tag}"):
|
|
||||||
if r != 0:
|
|
||||||
return r
|
|
||||||
await docker_push(f"{image.target}:{tag}")
|
|
||||||
if r := await docker_push(image.target):
|
|
||||||
if r != 0:
|
|
||||||
return r
|
|
||||||
return 0
|
|
||||||
|
|
||||||
# 将协程对象添加到任务列表
|
# 将协程对象添加到任务列表
|
||||||
tasks.append(limited_task(task))
|
tasks.append(limited_task(docker_task(f"{image.target}:{tag}", f"{image.target}:{tag}")))
|
||||||
else:
|
else:
|
||||||
async def task():
|
tasks.append(limited_task(docker_task(image.source, image.target)))
|
||||||
print(f"Pulling image {image.source}...")
|
|
||||||
if r := await docker_pull(image.source):
|
|
||||||
if r != 0:
|
|
||||||
return r
|
|
||||||
if r:= await docker_tag(image.source, image.target):
|
|
||||||
if r != 0:
|
|
||||||
return r
|
|
||||||
if r := await docker_push(image.target):
|
|
||||||
if r != 0:
|
|
||||||
return r
|
|
||||||
return 0
|
|
||||||
tasks.append(limited_task(task))
|
|
||||||
|
|
||||||
results = await asyncio.gather(*tasks)
|
results = await asyncio.gather(*tasks)
|
||||||
failed_tasks = 0
|
failed_tasks = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user