Skip to content

Conversation

@endersonmaia
Copy link
Contributor

@endersonmaia endersonmaia commented Jul 11, 2025

This pull request refines the functionality of Docker image handling and machine booting processes in the CLI application. The changes improve error handling, provide more detailed error messages, and ensure better handling of Docker image information and entrypoints.

Docker Image Handling Improvements:

  • apps/cli/src/builder/docker.ts: Enhanced the logic for obtaining Docker image information by introducing a try-catch block to handle errors when fetching image info after pulling or building an image. This ensures robust handling of scenarios where the image info retrieval might fail initially.

Machine Booting Enhancements:

  • apps/cli/src/machine.ts: Refactored the logic for determining the machine's entrypoint, adding checks for cases where entrypoint or cmd are empty arrays. Improved the error message to guide users on how to resolve undefined entrypoints by updating their configuration or Dockerfile.

@endersonmaia endersonmaia requested review from Copilot and tuler July 11, 2025 19:25
@endersonmaia endersonmaia self-assigned this Jul 11, 2025
@changeset-bot
Copy link

changeset-bot bot commented Jul 11, 2025

🦋 Changeset detected

Latest commit: b56a72f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cartesi/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This comment was marked as outdated.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 11, 2025

Coverage Report for ./apps/cli

Status Category Percentage Covered / Total
🔵 Lines 27.07% 300 / 1108
🔵 Statements 26.96% 305 / 1131
🔵 Functions 26.98% 51 / 189
🔵 Branches 23.8% 119 / 500
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
apps/cli/src/config.ts 90.85% 84.26% 96.77% 90.68% 66-67, 220, 228, 238, 258, 271, 281, 284, 294, 335, 346-350, 362
apps/cli/src/machine.ts 0% 0% 0% 0% 4-117
apps/cli/src/builder/docker.ts 92.68% 78.57% 75% 95% 40, 134-140
Generated in workflow #609 for commit b56a72f by the Vitest Coverage Report Action

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the image handling logic in the build function to only pull images when they don't exist and enhances the entrypoint determination and error messaging in the machine bootstrap.

  • In builder/docker.ts, the code now inspects an existing image first, pulls it only on inspection failure, and retrieves image information immediately after.
  • In machine.ts, entrypoint assignment is refactored into explicit if/else blocks with a more descriptive error when no entrypoint is found.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
apps/cli/src/builder/docker.ts Wrapped getImageInfo in try/catch to pull missing images, moved subsequent getImageInfo calls into both branches.
apps/cli/src/machine.ts Expanded entrypoint logic from a ?? expression to explicit if/else, and updated the error message for clarity.
Comments suppressed due to low confidence (1)

apps/cli/src/builder/docker.ts:102

  • Add tests to cover the flow where getImageInfo initially fails and triggers a pull followed by a successful inspect, to ensure this retry logic behaves correctly.
            imageInfo = await getImageInfo(image);

Comment on lines +101 to +102
await execa("docker", ["image", "pull", image]);
imageInfo = await getImageInfo(image);
Copy link

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

Catching all errors from getImageInfo may hide failures other than a missing image (for example, an architecture mismatch). Consider narrowing the catch block to only handle "image not found" errors before attempting to pull the image.

Suggested change
await execa("docker", ["image", "pull", image]);
imageInfo = await getImageInfo(image);
if (error instanceof Error && error.message.includes("No such image")) {
await execa("docker", ["image", "pull", image]);
imageInfo = await getImageInfo(image);
} else {
throw error;
}

Copilot uses AI. Check for mistakes.
@endersonmaia endersonmaia changed the title fix(cli): only pull image when it doesn't exists Fix cli build issues Jul 11, 2025
Copy link
Member

@tuler tuler left a comment

Choose a reason for hiding this comment

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

include a changeset

@endersonmaia
Copy link
Contributor Author

@tuler I'll consider you changeset enough for the entrypoint issue

and addes a fixup with a changest for the pull image issue

@endersonmaia endersonmaia merged commit e3df410 into prerelease/v2-alpha Jul 15, 2025
4 checks passed
@endersonmaia endersonmaia deleted the fix/pull-image branch July 15, 2025 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants