添加 cloudreve-aio Dockerfile,更新同步任务以支持 Dockerfile 构建
Some checks failed
Sync Container Images / sync-images (push) Failing after 39s

This commit is contained in:
远野千束 2025-04-20 15:21:07 +08:00
parent 364ee6e066
commit 450b83c3ef
4 changed files with 41 additions and 11 deletions

View File

@ -0,0 +1,9 @@
FROM cloudreve/cloudreve:latest
# Install ffmpeg LibreOffice and VIPS
RUN apk add --no-cache \
ffmpeg \
libreoffice \
vips \
&& rm -rf /var/cache/apk/*

View File

@ -24,4 +24,7 @@ images:
- "20"
- "20-slim"
- "18"
- "18-slim"
- "18-slim"
- dockerfile: "./dockerfiles/cloudreve-aio.Dockerfile"
target: "reg.liteyuki.icu/library/cloudreve-aio:latest"

View File

@ -8,7 +8,6 @@ dependencies = [
"aiofiles>=24.1.0",
"pydantic>=2.11.3",
"pyyaml>=6.0.2",
"test-pypi>=0.1.1",
]
@ -16,8 +15,3 @@ dependencies = [
name = "liteyuki"
url = "https://git.liteyuki.icu/api/packages/snowykami/pypi/simple"
explicit = true
[tool.uv.sources]
test-pypi = [
{ index = "liteyuki" },
]

32
sync.py
View File

@ -9,6 +9,7 @@ class Config(BaseModel):
images: list["Images"] = []
class Images(BaseModel):
dockerfile: str | None = None
source: str
target: str
tags: list[str] = []
@ -40,7 +41,11 @@ async def docker_push(image: str) -> int | None:
print(f"Pushing image {image}...")
return await run_command(f"docker push {image}")
async def docker_task(source: str, target: str) -> int | None:
async def docker_build(dockerfile: str, target: str) -> int | None:
print(f"Building image from {dockerfile}...")
return await run_command(f"docker build -t {target} -f {dockerfile} .")
async def docker_sync_task(source: str, target: str) -> int | None:
print(f"Pulling image {source}...")
if r := await docker_pull(source):
if r != 0:
@ -53,6 +58,16 @@ async def docker_task(source: str, target: str) -> int | None:
return r
return 0
async def docker_build_task(dockerfile: str, target: str) -> int | None:
print(f"Building image from {dockerfile}...")
if r := await docker_build(dockerfile, target):
if r != 0:
return r
if r := await docker_push(target):
if r != 0:
return r
return 0
semaphore = asyncio.Semaphore(5)
async def limited_task[T: Any](semaphore: asyncio.Semaphore, task: Callable[[], Coroutine[None, None, T]]) -> T:
@ -72,11 +87,20 @@ async def main():
tasks = []
for image in config.images:
if len(image.tags) > 0:
if image.dockerfile:
# 若有dockerfile提供則使用docker build
if len(image.tags) > 0:
# 若有tags提供則使用docker build和docker tag
for tag in image.tags:
tasks.append(limited_task(semaphore, partial(docker_build_task, image.dockerfile, f"{image.target}:{tag}")))
else:
tasks.append(limited_task(semaphore, partial(docker_build_task, image.dockerfile, image.target)))
elif len(image.tags) > 0:
# 若有tags提供則使用docker pull和docker tag
for tag in image.tags:
tasks.append(limited_task(semaphore, partial(docker_task, f"{image.source}:{tag}", f"{image.target}:{tag}")))
tasks.append(limited_task(semaphore, partial(docker_sync_task, f"{image.source}:{tag}", f"{image.target}:{tag}")))
else:
tasks.append(limited_task(semaphore, partial(docker_task, image.source, image.target)))
tasks.append(limited_task(semaphore, partial(docker_sync_task, image.source, image.target)))
results = await asyncio.gather(*tasks)
failed_tasks = sum(1 for result in results if result is not None and result != 0)