diff --git a/disco/alembic/versions/a1b2c3d4e5f6_add_no_cache.py b/disco/alembic/versions/a1b2c3d4e5f6_add_no_cache.py new file mode 100644 index 0000000..5b5b237 --- /dev/null +++ b/disco/alembic/versions/a1b2c3d4e5f6_add_no_cache.py @@ -0,0 +1,32 @@ +"""Add no_cache column to deployments + +Revision ID: a1b2c3d4e5f6 +Revises: d8adabff2804 +Create Date: 2026-03-25 00:00:00.000000 + +""" + +import sqlalchemy as sa +from alembic import op + +revision = "a1b2c3d4e5f6" +down_revision = "d8adabff2804" +branch_labels = None +depends_on = None + + +def upgrade(): + with op.batch_alter_table("deployments", schema=None) as batch_op: + batch_op.add_column( + sa.Column( + "no_cache", + sa.Boolean(), + nullable=False, + server_default="0", + ) + ) + + +def downgrade(): + with op.batch_alter_table("deployments", schema=None) as batch_op: + batch_op.drop_column("no_cache") diff --git a/disco/endpoints/deployments.py b/disco/endpoints/deployments.py index 9c84589..1e71d12 100644 --- a/disco/endpoints/deployments.py +++ b/disco/endpoints/deployments.py @@ -59,6 +59,7 @@ def deployments_get( class DeploymentRequestBody(BaseModel): commit: str = Field("_DEPLOY_LATEST_", pattern=r"^\S+$") disco_file: DiscoFile | None = Field(None, alias="discoFile") + no_cache: bool = Field(False, alias="noCache") @model_validator(mode="after") def commit_or_disco_file_required(self) -> "DeploymentRequestBody": @@ -91,6 +92,7 @@ async def deployments_post( commit_hash=req_body.commit if req_body.disco_file is None else None, disco_file=req_body.disco_file, by_api_key=api_key, + no_cache=req_body.no_cache, ) background_tasks.add_task(enqueue_deployment, deployment.id) return { diff --git a/disco/models/deployment.py b/disco/models/deployment.py index 884c51c..d04f669 100644 --- a/disco/models/deployment.py +++ b/disco/models/deployment.py @@ -4,7 +4,7 @@ from datetime import datetime, timezone from typing import TYPE_CHECKING -from sqlalchemy import ForeignKey, Integer, String, Unicode +from sqlalchemy import Boolean, ForeignKey, Integer, String, Unicode from sqlalchemy.orm import Mapped, mapped_column, relationship if TYPE_CHECKING: @@ -66,6 +66,12 @@ class Deployment(Base): String(32), nullable=True, ) + no_cache: Mapped[bool] = mapped_column( + Boolean, + default=False, + server_default="0", + nullable=False, + ) project: Mapped[Project] = relationship( "Project", diff --git a/disco/utils/deploymentflow.py b/disco/utils/deploymentflow.py index 7b051be..1290b30 100644 --- a/disco/utils/deploymentflow.py +++ b/disco/utils/deploymentflow.py @@ -66,6 +66,7 @@ class DeploymentInfo: disco_host: str env_variables: list[tuple[str, str]] scale: Mapping[str, int] + no_cache: bool @staticmethod async def from_deployment( @@ -96,6 +97,7 @@ async def from_deployment( (env_var.name, decrypt(env_var.value)) for env_var in env_variables ], scale=scale, + no_cache=deployment.no_cache, ) @@ -666,6 +668,7 @@ async def build_images( env_variables=env_variables, stdout=log_output, stderr=log_output, + no_cache=new_deployment_info.no_cache, ) for image_name, image in new_deployment_info.disco_file.images.items(): await log_output(f"Building image {image_name}\n") @@ -684,6 +687,7 @@ async def build_images( env_variables=env_variables, stdout=log_output, stderr=log_output, + no_cache=new_deployment_info.no_cache, ) return images diff --git a/disco/utils/deployments.py b/disco/utils/deployments.py index 1e54f4c..161df20 100644 --- a/disco/utils/deployments.py +++ b/disco/utils/deployments.py @@ -45,6 +45,7 @@ async def create_deployment( disco_file: DiscoFile | None, by_api_key: ApiKey | None, number: int | None = None, + no_cache: bool = False, ) -> Deployment: if number is not None: if len(await project.awaitable_attrs.deployments) > 0: @@ -72,6 +73,7 @@ async def create_deployment( else None, docker_registry=await keyvalues.get_value(dbsession, "REGISTRY"), by_api_key=by_api_key, + no_cache=no_cache, ) dbsession.add(deployment) for env_variable in await project.awaitable_attrs.env_variables: diff --git a/disco/utils/docker.py b/disco/utils/docker.py index 038fcf0..ae45aab 100644 --- a/disco/utils/docker.py +++ b/disco/utils/docker.py @@ -33,6 +33,7 @@ async def build_image( dockerfile_path: str | None = None, dockerfile_str: str | None = None, timeout: int = 3600, + no_cache: bool = False, ) -> None: log.info("Building Docker image %s", image) assert (dockerfile_path is None) != (dockerfile_str is None) @@ -53,9 +54,11 @@ async def build_image( # https://github.com/docker/buildx/issues/1881 ("BUILDX_GIT_INFO", "0"), ] + no_cache_args = ["--no-cache"] if no_cache else [] args = [ "docker", "build", + *no_cache_args, *env_var_args, "--cpu-period", "100000", # default