From cf6771f945dd27967fe0c0585d63f4bb48977a4a Mon Sep 17 00:00:00 2001 From: Snowykami Date: Thu, 17 Apr 2025 20:57:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20docker=5Ftag=20=E5=92=8C?= =?UTF-8?q?=20docker=5Fpush=20=E5=87=BD=E6=95=B0=E7=9A=84=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=B1=BB=E5=9E=8B=EF=BC=8C=E4=BC=98=E5=8C=96=E4=B8=BB?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E4=B8=AD=E7=9A=84=E4=BB=BB=E5=8A=A1=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sync.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sync.py b/sync.py index 705b0d3..596cf63 100644 --- a/sync.py +++ b/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()) \ No newline at end of file