Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions disco/alembic/versions/a1b2c3d4e5f6_add_no_cache.py
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 2 additions & 0 deletions disco/endpoints/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion disco/models/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions disco/utils/deploymentflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
)


Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions disco/utils/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions disco/utils/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down