nf-core / modules

Repository to host tool-specific module files for the Nextflow DSL2 community!
https://nf-co.re/modules
MIT License
276 stars 690 forks source link

[FEATURE] Build automation for fetching Seqera Containers #6694

Open ewels opened 2 days ago

ewels commented 2 days ago

Follow on to https://github.com/nf-core/modules/issues/5832 to discuss specifically the automation for fetching Seqera Containers.

ewels commented 2 days ago

Before I forget, here is the code snippet used for https://seqera.io/containers/ that fetches the https download link for Singularity containers (instead of the default oras container name).

url = f"{wave_api_url}/v1alpha1/inspect"
logger.info(f"Calling image inspect at {url} for image URL {image_url}")
data = {"containerImage": image_url}
if platform_pat:
    data["towerAccessToken"] = platform_pat
else:
    logger.warning("'PLATFORM_PAT' not set, no auth to Wave back end")
async with httpx.AsyncClient() as client:
    response = await client.post(
        url=url,
        json=data,
        headers={"Content-Type": "application/json"},
    )

    if response.is_success:
        data = response.json()
        layers = data.get("container", {}).get("manifest", {}).get("layers", [])
        is_singularity = len(layers) == 1 and layers[0].get("mediaType", "").endswith(".sif")
        if not is_singularity:
            raise HTTPException(status_code=400, detail="Not a singularity image")
        if "digest" not in layers[0]:
            raise HTTPException(status_code=400, detail="No 'digest' in first layer found")
        digest = layers[0]["digest"].replace("sha256:", "")
        url = f"https://community-cr-prod.seqera.io/docker/registry/v2/blobs/sha256/{digest[:2]}/{digest}/data"
        return url

    else:
        raise HTTPException(status_code=response.status_code, detail=response.text)

We should be able to reuse this to get the HTTP links as well.