Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 26, 2026

Plan: Support devcontainer.json with "build" field

  • Add "build" field to DevcontainerConfig struct
  • Update ensureDevcontainerConfig to preserve "build" field when updating existing config
  • Add test for devcontainer with "build" instead of "image"
  • Verify changes with existing tests
  • Run make agent-finish for final validation
  • Revert .devcontainer/devcontainer.json to original state

Summary

Successfully added support for devcontainer.json files that use the "build" field instead of the "image" field.

Changes Made:

  1. Added DevcontainerBuild struct to represent build configuration:

    • dockerfile: Path to Dockerfile
    • context: Build context path
    • args: Build arguments
  2. Updated DevcontainerConfig struct:

    • Added Build *DevcontainerBuild field with omitempty tag
    • Changed Image field to use omitempty tag to avoid empty string in JSON
  3. Added comprehensive test (TestEnsureDevcontainerConfigWithBuildField):

    • Validates that existing build field is preserved when updating
    • Verifies that image field is not set when build is present
    • Confirms all other devcontainer features are merged correctly
  4. Restored .devcontainer/devcontainer.json:

    • Reverted accidental modification of repository's devcontainer.json
    • Original "build" field is now preserved

How It Works:

  • When reading an existing devcontainer.json, the parser now recognizes both "image" and "build" fields
  • The existing update logic already preserves all fields by copying the entire config (config = *existingConfig)
  • The omitempty JSON tags ensure clean serialization (no empty fields in output)
  • When creating a new devcontainer.json from scratch, we still use the "image" field as before

Test Results:

All devcontainer tests pass:

  • ✅ TestEnsureDevcontainerConfig
  • ✅ TestEnsureDevcontainerConfigWithAdditionalRepos
  • ✅ TestEnsureDevcontainerConfigWithCurrentRepo
  • ✅ TestEnsureDevcontainerConfigWithOwnerValidation
  • ✅ TestEnsureDevcontainerConfigUpdatesOldVersion
  • ✅ TestEnsureDevcontainerConfigMergesWithExisting
  • ✅ TestEnsureDevcontainerConfigWithBuildField (NEW)
Original prompt

Update the devcontainer.json update code to handle case where the "image" field is missing and the "build" field is used instead:

  "build": {
    "dockerfile": "Dockerfile"
  },

See current devcontainer.json


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 26, 2026 21:13
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Update devcontainer.json to handle missing image field Support devcontainer.json with build field Jan 26, 2026
Copilot AI requested a review from pelikhan January 26, 2026 21:24
@pelikhan pelikhan marked this pull request as ready for review January 26, 2026 21:30
@pelikhan pelikhan merged commit 0d0e7ac into main Jan 26, 2026
50 checks passed
@pelikhan pelikhan deleted the copilot/update-devcontainer-code branch January 26, 2026 21:31
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