Skip to content

Commit

Permalink
Remove docker build tasks (#1001)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
soapy1 and pre-commit-ci[bot] authored Dec 6, 2024
1 parent 30f031b commit a77e625
Show file tree
Hide file tree
Showing 16 changed files with 18 additions and 224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
from conda_store_server._internal.action.download_packages import ( # noqa
action_fetch_and_extract_conda_packages,
)
from conda_store_server._internal.action.generate_conda_docker import ( # noqa
action_generate_conda_docker,
)
from conda_store_server._internal.action.generate_conda_export import ( # noqa
action_generate_conda_export,
)
Expand Down

This file was deleted.

16 changes: 1 addition & 15 deletions conda-store-server/conda_store_server/_internal/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import re
import sys
from typing import Annotated, Any, Callable, Dict, List, Optional, TypeAlias, Union
from typing import Annotated, Any, Dict, List, Optional, TypeAlias, Union

from conda_lock.lockfile.v1.models import Lockfile
from pydantic import (
Expand Down Expand Up @@ -346,25 +346,11 @@ class Settings(BaseModel):
BuildArtifactType.YAML,
BuildArtifactType.CONDA_PACK,
BuildArtifactType.CONSTRUCTOR_INSTALLER,
*(
[
BuildArtifactType.DOCKER_MANIFEST,
BuildArtifactType.CONTAINER_REGISTRY,
]
if sys.platform == "linux"
else []
),
],
description="artifacts to build in conda-store. By default all of the artifacts",
metadata={"global": False},
)

default_docker_base_image: Union[str, Callable] = Field(
"registry-1.docker.io/library/debian:sid-slim",
description="default base image used for the Dockerized environments. Make sure to have a proper glibc within image (highly discourage alpine/musl based images). Can also be callable function which takes the `orm.Build` object as input which has access to all attributes about the build such as install packages, requested packages, name, namespace, etc",
metadata={"global": False},
)


PipArg = Annotated[str, AfterValidator(lambda v: check_pip(v))]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import yaml
from celery.result import AsyncResult
from fastapi import APIRouter, Body, Depends, HTTPException, Query, Request
from fastapi.responses import PlainTextResponse, RedirectResponse
from fastapi.responses import JSONResponse, PlainTextResponse, RedirectResponse

from conda_store_server import __version__, api, app
from conda_store_server._internal import orm, schema, utils
Expand Down Expand Up @@ -1059,7 +1059,6 @@ async def api_put_build_cancel(
[
f"build-{build_id}-conda-env-export",
f"build-{build_id}-conda-pack",
f"build-{build_id}-docker",
f"build-{build_id}-constructor-installer",
f"build-{build_id}-environment",
],
Expand Down Expand Up @@ -1341,14 +1340,15 @@ async def api_get_build_archive(
return RedirectResponse(conda_store.storage.get_url(build.conda_pack_key))


@router_api.get("/build/{build_id}/docker/")
@router_api.get("/build/{build_id}/docker/", deprecated=True)
async def api_get_build_docker_image_url(
build_id: int,
request: Request,
conda_store=Depends(dependencies.get_conda_store),
server=Depends(dependencies.get_server),
auth=Depends(dependencies.get_auth),
):
response_headers = {"Deprecation": "True"}
with conda_store.get_db() as db:
build = api.get_build(db, build_id)
auth.authorize_request(
Expand All @@ -1360,12 +1360,15 @@ async def api_get_build_docker_image_url(

if build.has_docker_manifest:
url = f"{server.registry_external_url}/{build.environment.namespace.name}/{build.environment.name}:{build.build_key}"
return PlainTextResponse(url)
return PlainTextResponse(url, headers=response_headers)

else:
raise HTTPException(
status_code=400,
detail=f"Build {build_id} doesn't have a docker manifest",
content = {
"status": "error",
"message": f"Build {build_id} doesn't have a docker manifest",
}
return JSONResponse(
status_code=400, content=content, headers=response_headers
)


Expand Down
48 changes: 2 additions & 46 deletions conda-store-server/conda_store_server/_internal/worker/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,55 +418,11 @@ def build_conda_docker(db: Session, conda_store, build: orm.Build):
import warnings

warnings.warn(
"Generating Docker images is currently not supported, see "
"https://github.com/conda-incubator/conda-store/issues/666"
"Generating Docker images is not supported and will be removed "
"in a future release"
)
return

conda_prefix = build.build_path(conda_store)
settings = conda_store.get_settings(
db=db,
namespace=build.environment.namespace.name,
environment_name=build.environment.name,
)

try:
with utils.timer(
conda_store.log,
f"packaging docker image of conda environment={conda_prefix}",
):
context = action.action_generate_conda_docker(
conda_prefix=conda_prefix,
default_docker_image=utils.callable_or_value(
settings.default_docker_base_image, None
),
container_registry=conda_store.container_registry,
output_image_name=build.specification.name,
output_image_tag=build.build_key,
)
append_to_logs(
db,
conda_store,
build,
"::group::action_generate_conda_docker\n"
+ context.stdout.getvalue()
+ "\n::endgroup::\n",
)

image = context.result

if schema.BuildArtifactType.DOCKER_MANIFEST in settings.build_artifacts:
conda_store.container_registry.store_image(
db, conda_store, build, image
)

if schema.BuildArtifactType.CONTAINER_REGISTRY in settings.build_artifacts:
conda_store.container_registry.push_image(db, build, image)
except Exception as e:
conda_store.log.exception(e)
append_to_logs(db, conda_store, build, traceback.format_exc())
raise e


def build_constructor_installer(db: Session, conda_store, build: orm.Build):
conda_prefix = build.build_path(conda_store)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from conda_store_server._internal.worker.app import CondaStoreWorker
from conda_store_server._internal.worker.build import (
build_cleanup,
build_conda_docker,
build_conda_env_export,
build_conda_environment,
build_conda_pack,
Expand Down Expand Up @@ -241,14 +240,6 @@ def task_build_conda_pack(self, build_id):
build_conda_pack(db, conda_store, build)


@shared_task(base=WorkerTask, name="task_build_conda_docker", bind=True)
def task_build_conda_docker(self, build_id):
conda_store = self.worker.conda_store
with conda_store.session_factory() as db:
build = api.get_build(db, build_id)
build_conda_docker(db, conda_store, build)


@shared_task(base=WorkerTask, name="task_build_constructor_installer", bind=True)
def task_build_constructor_installer(self, build_id):
conda_store = self.worker.conda_store
Expand Down
8 changes: 0 additions & 8 deletions conda-store-server/conda_store_server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,6 @@ def list_environments(
query = query.filter(orm.Build.status == status)

if artifact:
# DOCKER_BLOB can return multiple results
# use DOCKER_MANIFEST instead
if artifact == schema.BuildArtifactType.DOCKER_BLOB:
artifact = schema.BuildArtifactType.DOCKER_MANIFEST
query = query.join(orm.Build.build_artifacts).filter(
orm.BuildArtifact.artifact_type == artifact
)
Expand Down Expand Up @@ -511,10 +507,6 @@ def list_builds(
query = query.filter(orm.Build.deleted_on == null())

if artifact:
# DOCKER_BLOB can return multiple results
# use DOCKER_MANIFEST instead
if artifact == schema.BuildArtifactType.DOCKER_BLOB:
artifact = schema.BuildArtifactType.DOCKER_MANIFEST
query = query.join(orm.Build.build_artifacts).filter(
orm.BuildArtifact.artifact_type == artifact
)
Expand Down
33 changes: 0 additions & 33 deletions conda-store-server/conda_store_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
TraitError,
Type,
Unicode,
Union,
default,
validate,
)
Expand Down Expand Up @@ -273,14 +272,6 @@ def _check_redis(self, proposal):
schema.BuildArtifactType.YAML,
schema.BuildArtifactType.CONDA_PACK,
schema.BuildArtifactType.CONSTRUCTOR_INSTALLER,
*(
[
schema.BuildArtifactType.DOCKER_MANIFEST,
schema.BuildArtifactType.CONTAINER_REGISTRY,
]
if sys.platform == "linux"
else []
),
],
help="artifacts to build in conda-store. By default all of the artifacts",
config=True,
Expand Down Expand Up @@ -353,19 +344,6 @@ def _default_celery_results_backend(self):
allow_none=True,
)

default_docker_base_image = Union(
[Unicode(), Callable()],
help="default base image used for the Dockerized environments. Make sure to have a proper glibc within image (highly discourage alpine/musl based images). Can also be callable function which takes the `orm.Build` object as input which has access to all attributes about the build such as install packages, requested packages, name, namespace, etc",
config=True,
)

@default("default_docker_base_image")
def _default_docker_base_image(self):
def _docker_base_image(build: orm.Build):
return "registry-1.docker.io/library/debian:sid-slim"

return _docker_base_image

validate_specification = Callable(
conda_store_validate_specification,
help="callable function taking conda_store, namespace, and specification as input arguments to apply for validating and modifying a given specification. If there are validation issues with the environment ValueError with message should be raised. If changed you may need to call the default function to preseve many of the trait effects e.g. `c.CondaStore.default_channels` etc",
Expand Down Expand Up @@ -525,7 +503,6 @@ def ensure_settings(self, db: Session):
pypi_required_packages=self.pypi_required_packages,
pypi_included_packages=self.pypi_included_packages,
build_artifacts=self.build_artifacts,
# default_docker_base_image=self.default_docker_base_image,
)
api.set_kvstore_key_values(db, "setting", settings.model_dump(), update=False)

Expand Down Expand Up @@ -755,16 +732,6 @@ def create_build(self, db: Session, environment_id: int, specification_sha256: s
)
)

if (
schema.BuildArtifactType.DOCKER_MANIFEST in settings.build_artifacts
or schema.BuildArtifactType.CONTAINER_REGISTRY in settings.build_artifacts
):
artifact_tasks.append(
tasks.task_build_conda_docker.subtask(
args=(build.id,), task_id=f"build-{build.id}-docker", immutable=True
)
)

if schema.BuildArtifactType.CONSTRUCTOR_INSTALLER in settings.build_artifacts:
artifact_tasks.append(
tasks.task_build_constructor_installer.subtask(
Expand Down
21 changes: 1 addition & 20 deletions conda-store-server/tests/_internal/action/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from traitlets import TraitError

from conda_store_server import BuildKey, api
from conda_store_server._internal import action, conda_utils, orm, schema, server, utils
from conda_store_server._internal import action, conda_utils, orm, schema, server
from conda_store_server._internal.action import (
generate_constructor_installer,
)
Expand Down Expand Up @@ -204,25 +204,6 @@ def test_generate_conda_pack(tmp_path, conda_prefix):
assert output_filename.exists()


@pytest.mark.xfail(
reason=(
"Generating Docker images is currently not supported, see "
"https://github.com/conda-incubator/conda-store/issues/666"
)
)
@pytest.mark.long_running_test
def test_generate_conda_docker(conda_store, conda_prefix):
action.action_generate_conda_docker(
conda_prefix=conda_prefix,
default_docker_image=utils.callable_or_value(
conda_store.default_docker_base_image, None
),
container_registry=conda_store.container_registry,
output_image_name="test",
output_image_tag="tag",
)


def test_remove_not_conda_prefix(tmp_path):
fake_conda_prefix = tmp_path / "test"
fake_conda_prefix.mkdir()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,6 @@ def test_get_settings_auth(testclient, authenticate, route):
"pypi_required_packages",
"pypi_included_packages",
"build_artifacts",
"default_docker_base_image",
} <= r.data.keys()


Expand Down
2 changes: 0 additions & 2 deletions conda-store-server/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,5 +391,3 @@ def _create_build_artifacts(db: Session, conda_store, build: orm.Build):
content_type="application/gzip",
artifact_type=schema.BuildArtifactType.CONDA_PACK,
)

# have not included docker at the moment
6 changes: 0 additions & 6 deletions conda-store-server/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

import sys

import pytest
from celery.result import AsyncResult
Expand Down Expand Up @@ -69,7 +68,6 @@ def test_conda_store_register_environment_workflow(

# wait for task to complete
# build: environment, export, archive
# docker is expected to fail will be fixed soon

task = AsyncResult(f"build-{build.id}-environment")
task.wait(timeout=60)
Expand All @@ -80,10 +78,6 @@ def test_conda_store_register_environment_workflow(
task = AsyncResult(f"build-{build.id}-conda-pack")
task.wait(timeout=60)

if sys.platform == "linux":
task = AsyncResult(f"build-{build.id}-docker")
task.wait(timeout=2 * 60)

task = AsyncResult(f"build-{build.id}-constructor-installer")
task.wait(timeout=5 * 60)

Expand Down
Loading

0 comments on commit a77e625

Please sign in to comment.