Exemple #1
0
def api_get_build_packages(
    build_id: int,
    request: Request,
    search: Optional[str] = None,
    exact: Optional[str] = None,
    build: Optional[str] = None,
    conda_store=Depends(dependencies.get_conda_store),
    auth=Depends(dependencies.get_auth),
    paginated_args=Depends(get_paginated_args),
):
    build_orm = api.get_build(conda_store.db, build_id)
    if build_orm is None:
        raise HTTPException(status_code=404, detail="build id does not exist")

    auth.authorize_request(
        request,
        f"{build_orm.environment.namespace.name}/{build_orm.environment.name}",
        {Permissions.ENVIRONMENT_READ},
        require=True,
    )
    orm_packages = api.get_build_packages(
        conda_store.db, build_orm.id, search=search, exact=exact, build=build
    )
    return paginated_api_response(
        orm_packages,
        paginated_args,
        schema.CondaPackage,
        allowed_sort_bys={
            "channel": orm.CondaChannel.name,
            "name": orm.CondaPackage.name,
        },
        default_sort_by=["channel", "name"],
        exclude={"channel": {"last_update"}},
    )
Exemple #2
0
    def update_environment_build(self, namespace, name, build_id):
        build = api.get_build(self.db, build_id)
        if build is None:
            raise utils.CondaStoreError(f"build id={build_id} does not exist")

        environment = api.get_environment(self.db,
                                          namespace=namespace,
                                          name=name)
        if environment is None:
            raise utils.CondaStoreError(
                f"environment namespace={namespace} name={name} does not exist"
            )

        if build.status != schema.BuildStatus.COMPLETED:
            raise utils.CondaStoreError(
                "cannot update environment to build id since not completed")

        if build.specification.name != name:
            raise utils.CondaStoreError(
                "cannot update environment to build id since specification does not match environment name"
            )

        environment.current_build_id = build.id
        self.db.commit()

        self.celery_app
        # must import tasks after a celery app has been initialized
        from conda_store_server.worker import tasks

        tasks.task_update_environment_build.si(environment.id).apply_async()
Exemple #3
0
def api_put_build(
    build_id: int,
    request: Request,
    conda_store=Depends(dependencies.get_conda_store),
    auth=Depends(dependencies.get_auth),
):
    build = api.get_build(conda_store.db, build_id)
    if build is None:
        raise HTTPException(status_code=404, detail="build id does not exist")

    auth.authorize_request(
        request,
        f"{build.environment.namespace.name}/{build.environment.name}",
        {Permissions.ENVIRONMENT_UPDATE},
        require=True,
    )

    new_build = conda_store.create_build(
        build.environment_id, build.specification.sha256
    )
    return {
        "status": "ok",
        "message": "rebuild triggered",
        "data": {"build_id": new_build.id},
    }
Exemple #4
0
def get_docker_image_manifest(conda_store, image, tag, timeout=10 * 60):
    namespace, *image_name = image.split("/")

    # /v2/<image-name>/manifest/<tag>
    if len(image_name) == 0:
        return docker_error_message(schema.DockerRegistryError.NAME_UNKNOWN)

    if namespace == "conda-store-dynamic":
        environment_name = dynamic_conda_store_environment(
            conda_store, image_name)
    elif len(image_name) > 1:
        return docker_error_message(schema.DockerRegistryError.NAME_UNKNOWN)
    else:
        environment_name = image_name[0]

    # check that namespace/environment_name exist
    environment = api.get_environment(conda_store.db,
                                      namespace=namespace,
                                      name=environment_name)
    if environment is None:
        return docker_error_message(schema.DockerRegistryError.NAME_UNKNOWN)

    if tag == "latest":
        build_key = environment.current_build.build_key
    elif tag.startswith("sha256:"):
        # looking for sha256 of docker manifest
        manifests_key = f"docker/manifest/{tag}"
        return RedirectResponse(conda_store.storage.get_url(manifests_key))
    else:
        build_key = tag

    build_id = orm.Build.parse_build_key(build_key)
    if build_id is None:
        return docker_error_message(
            schema.DockerRegistryError.MANIFEST_UNKNOWN)

    build = api.get_build(conda_store.db, build_id)
    if build is None:
        return docker_error_message(
            schema.DockerRegistryError.MANIFEST_UNKNOWN)

    # waiting for image to be built by conda-store
    start_time = time.time()
    while not build.has_docker_manifest:
        conda_store.db.refresh(build)
        time.sleep(10)
        if time.time() - start_time > timeout:
            return docker_error_message(
                schema.DockerRegistryError.MANIFEST_UNKNOWN)

    manifests_key = f"docker/manifest/{build_key}"
    return RedirectResponse(conda_store.storage.get_url(manifests_key))
Exemple #5
0
def task_delete_build(self, build_id):
    conda_store = self.worker.conda_store
    build = api.get_build(conda_store.db, build_id)

    conda_store.log.info(f"deleting artifacts for build={build.id}")
    for build_artifact in api.list_build_artifacts(
            conda_store.db,
            build_id=build_id,
            excluded_artifact_types=conda_store.
            build_artifacts_kept_on_deletion,
    ).all():
        delete_build_artifact(conda_store, build_artifact)
    conda_store.db.commit()
Exemple #6
0
def api_get_build_archive(
    build_id: int,
    request: Request,
    conda_store=Depends(dependencies.get_conda_store),
    auth=Depends(dependencies.get_auth),
):
    build = api.get_build(conda_store.db, build_id)
    auth.authorize_request(
        request,
        f"{build.environment.namespace.name}/{build.environment.name}",
        {Permissions.ENVIRONMENT_READ},
        require=True,
    )

    return RedirectResponse(conda_store.storage.get_url(build.conda_pack_key))
Exemple #7
0
def api_get_build_lockfile(
    build_id: int,
    request: Request,
    conda_store=Depends(dependencies.get_conda_store),
    auth=Depends(dependencies.get_auth),
):
    build = api.get_build(conda_store.db, build_id)
    auth.authorize_request(
        request,
        f"{build.environment.namespace.name}/{build.environment.name}",
        {Permissions.ENVIRONMENT_READ},
        require=True,
    )

    lockfile = api.get_build_lockfile(conda_store.db, build_id)
    return lockfile
Exemple #8
0
def api_get_build_yaml(
    build_id: int,
    request: Request,
    conda_store=Depends(dependencies.get_conda_store),
    auth=Depends(dependencies.get_auth),
):
    build = api.get_build(conda_store.db, build_id)
    if build is None:
        raise HTTPException(status_code=404, detail="build id does not exist")

    auth.authorize_request(
        request,
        f"{build.environment.namespace.name}/{build.environment.name}",
        {Permissions.ENVIRONMENT_READ},
        require=True,
    )
    return RedirectResponse(conda_store.storage.get_url(build.conda_env_export_key))
Exemple #9
0
    def delete_build(self, build_id):
        build = api.get_build(self.db, build_id)
        if build.status not in [
                schema.BuildStatus.FAILED,
                schema.BuildStatus.COMPLETED,
        ]:
            raise utils.CondaStoreError(
                "cannot delete build since not finished building")

        build.deleted_on = datetime.datetime.utcnow()
        self.db.commit()

        self.celery_app

        # must import tasks after a celery app has been initialized
        from conda_store_server.worker import tasks

        tasks.task_delete_build.si(build.id).apply_async()
Exemple #10
0
def api_get_build(
    build_id: int,
    request: Request,
    conda_store=Depends(dependencies.get_conda_store),
    auth=Depends(dependencies.get_auth),
):
    build = api.get_build(conda_store.db, build_id)
    if build is None:
        raise HTTPException(status_code=404, detail="build id does not exist")

    auth.authorize_request(
        request,
        f"{build.environment.namespace.name}/{build.environment.name}",
        {Permissions.ENVIRONMENT_READ},
        require=True,
    )

    return {
        "status": "ok",
        "data": schema.Build.from_orm(build).dict(exclude={"packages"}),
    }
Exemple #11
0
def api_delete_build(
    build_id: int,
    request: Request,
    conda_store=Depends(dependencies.get_conda_store),
    auth=Depends(dependencies.get_auth),
):
    build = api.get_build(conda_store.db, build_id)
    if build is None:
        raise HTTPException(status_code=404, detail="build id does not exist")

    auth.authorize_request(
        request,
        f"{build.environment.namespace.name}/{build.environment.name}",
        {Permissions.BUILD_DELETE},
        require=True,
    )

    try:
        conda_store.delete_build(build_id)
    except utils.CondaStoreError as e:
        raise HTTPException(status_code=400, detail=e.message)

    return {"status": "ok"}
Exemple #12
0
def ui_get_build(
    build_id: int,
    request: Request,
    templates=Depends(dependencies.get_templates),
    conda_store=Depends(dependencies.get_conda_store),
    auth=Depends(dependencies.get_auth),
    server=Depends(dependencies.get_server),
    entity=Depends(dependencies.get_entity),
):
    build = api.get_build(conda_store.db, build_id)
    if build is None:
        return templates.TemplateResponse(
            "404.html",
            {
                "request": request,
                "message": f"build id={build_id} not found",
            },
            status_code=404,
        )

    auth.authorize_request(
        request,
        f"{build.environment.namespace.name}/{build.environment.name}",
        {Permissions.ENVIRONMENT_READ},
        require=True,
    )

    context = {
        "request": request,
        "build": build,
        "registry_external_url": server.registry_external_url,
        "entity": entity,
        "platform": conda_platform(),
        "spec": yaml.dump(build.specification.spec),
    }

    return templates.TemplateResponse("build.html", context)
Exemple #13
0
def api_get_build_archive(build_id):
    conda_store = get_conda_store()
    conda_pack_key = api.get_build(conda_store.db, build_id).conda_pack_key
    return redirect(conda_store.storage.get_url(conda_pack_key))
Exemple #14
0
def ui_get_build(build_id):
    conda_store = get_conda_store()
    build = api.get_build(conda_store.db, build_id)
    return render_template("build.html", build=build)
Exemple #15
0
def task_build_conda_environment(self, build_id):
    conda_store = self.worker.conda_store
    build = api.get_build(conda_store.db, build_id)
    build_conda_environment(conda_store, build)
Exemple #16
0
def api_get_build(build_id):
    conda_store = get_conda_store()
    build = schema.Build.from_orm(api.get_build(conda_store.db, build_id))
    return jsonify(build.dict())
Exemple #17
0
def api_get_build_logs(build_id):
    conda_store = get_conda_store()
    log_key = api.get_build(conda_store.db, build_id).log_key
    return redirect(conda_store.storage.get_url(log_key))
Exemple #18
0
def task_build_conda_docker(self, build_id):
    conda_store = self.worker.conda_store
    build = api.get_build(conda_store.db, build_id)
    build_conda_docker(conda_store, build)