修正 docker_tag 和 docker_push 函数的返回类型,优化主函数中的任务处理逻辑
Some checks failed
Sync Container Images / sync-images (push) Failing after 50s
Some checks failed
Sync Container Images / sync-images (push) Failing after 50s
This commit is contained in:
parent
945150d0ad
commit
cf6771f945
18
sync.py
18
sync.py
@ -31,29 +31,25 @@ async def docker_pull(image: str) -> int | None:
|
||||
print(f"Pulling image {image}...")
|
||||
return await run_command(f"docker pull {image}")
|
||||
|
||||
async def docker_tag(source: str, target: str):
|
||||
async def docker_tag(source: str, target: str) -> int | None:
|
||||
print(f"Tagging image {source} as {target}...")
|
||||
return await run_command(f"docker tag {source} {target}")
|
||||
|
||||
async def docker_push(image: str):
|
||||
async def docker_push(image: str) -> int | None:
|
||||
print(f"Pushing image {image}...")
|
||||
return await run_command(f"docker push {image}")
|
||||
|
||||
async def main():
|
||||
# Load the YAML file
|
||||
async with aiofiles.open('images.yaml', 'r') as file:
|
||||
config = await file.read()
|
||||
# Parse the YAML file
|
||||
|
||||
config = yaml.safe_load(config)
|
||||
|
||||
config = Config(**config)
|
||||
|
||||
# Print the loaded configuration
|
||||
print("Loaded configuration:")
|
||||
print(config)
|
||||
|
||||
tasks = []
|
||||
|
||||
for image in config.images:
|
||||
if len(image.tags) > 0:
|
||||
for tag in image.tags:
|
||||
@ -69,8 +65,12 @@ async def main():
|
||||
await docker_push(image.target)
|
||||
tasks.append(task())
|
||||
|
||||
# Run all tasks concurrently
|
||||
await asyncio.gather(*tasks)
|
||||
results = await asyncio.gather(*tasks)
|
||||
failed_tasks = 0
|
||||
for result in results:
|
||||
if result is not None and result != 0:
|
||||
failed_tasks += 1
|
||||
print(f"{len(results)} tasks completed. {len(result) - failed_tasks} succeed, {failed_tasks} failed.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
Loading…
x
Reference in New Issue
Block a user