Skip to content

Environments: an inline build context for foreignDockerfile - #41

Merged
echarles merged 1 commit into
mainfrom
feat/foreign-build-context
Nov 1, 2026
Merged

echarles merged 1 commit into
mainfrom
feat/foreign-build-context

Conversation

@echarles

Copy link
Copy Markdown
Member

A foreignDockerfile could not COPY from a build context. This takes one inline, in build.dockerfile.context, the way dependencyFile already keeps its file in the spec.

  • Bounded at 1 MiB: it is stored with the version. Its bytes are in the spec's digest, so a version names exactly what it built.
  • Each file goes through validate_build_context: no absolute path, no .., no symlink (a file here has no way to be one). Paths the build itself writes are reserved.
  • write_build_context checks each target again against the folder, because that is the step that writes.
  • COPY is allowed only for what the context holds. With none, it is refused as before.
  • context is left out of the dump when unset, so no existing spec's digest moves. dockerfile sources refuse it.

Tested: unit tests, and a real build copying and running a context file, with DATALAYER_ENVIRONMENT_DOCKER_TESTS=1. A local image stood in for the approved base.

Copilot AI balanced review requested due to automatic review settings October 30, 2026 17:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Context validation bypasses allow generated Dockerfiles and resolved locks to be overwritten, while valid JSON-form and wildcard COPY sources are incorrectly rejected.

4 open issues
What changed in this PR

Adds inline build-context files for foreignDockerfile environments, enabling Dockerfile COPY instructions to use files stored with the environment version and covered by its spec digest.

Changes:

  • Adds context-file models, validation, and a 1 MiB decoded-content limit while preserving digests when context is unset.
  • Adds context-aware source checks and writes supplied files into the Datalayer build directory.
  • Updates the schema, documentation, unit tests, and Docker integration coverage.
File Description
tests/​test_environment_foreign_contract_layer.py Tests context validation, digests, file writing, and image copying.
schemas/​environment-v1alpha1.json Defines inline context files and the optional context field.
docs/​docs/​environments/​specification.mdx Documents inline context support and its size limit.
code_sandboxes/​environments/​spec.py Models and validates context files; omits unset context from serialization.
code_sandboxes/​environments/​contract.py Adds context limits, reserved paths, and source-membership checks.
code_sandboxes/​environments/​adapters/​datalayer.py Writes context files and permissions before building.

Review effort: Balanced

Checked again here, against the folder itself, because this is the step
that writes to disk: nothing validated elsewhere is taken on trust.
"""
dockerfile = environment.spec.build.dockerfile
findings.append(SpecFinding(field, f"`{item.path}` is not base64"))
continue
entries.append(BuildContextEntry(path=item.path, size_bytes=size))
if item.path in RESERVED_CONTEXT_PATHS:
name = source.strip("/").removeprefix("./")
if name in ("", "."):
return bool(context)
return any(path == name or path.startswith(f"{name}/") for path in context)
continue
sources = [t for t in tokens if not t.startswith("--")][:-1]
local = [s for s in sources if not re.match(r"^(https?|git)://|^git@", s, re.IGNORECASE)]
local = [s for s in local if not _in_context(s, context)]
@echarles
echarles merged commit ccd52e5 into main Nov 1, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants