Skip to content

Conversation

@yeahdongcn
Copy link
Owner

@yeahdongcn yeahdongcn commented Jun 30, 2025

Summary by Sourcery

Add a new Go-based Docker Buildx frontend for Agentfile syntax that parses domain-specific Agentfile instructions and generates a Dockerfile with configuration files and framework-specific code. It introduces a CLI binary and a containerized image, along with documentation, build scripts, and example tests to demonstrate end-to-end usage.

New Features:

  • Introduce agentfile-frontend CLI in Go to parse Agentfile and emit a Dockerfile with custom Buildx frontend syntax
  • Support core Agentfile instructions and sub-instructions for defining secrets, MCP servers, agents, routers, chains, and orchestrators
  • Automatically generate JSON configuration files and framework-specific agent code (agno vs fast-agent) during Dockerfile generation
  • Package the frontend as both a standalone binary and a scratch-based Docker image

Build:

  • Add go.mod for dependencies and a multi-stage Dockerfile to build and package the frontend binary

Documentation:

  • Add user-facing README with installation steps, usage examples, architecture overview, and future enhancement roadmap
  • Include an implementation summary document detailing parser and generator design

Tests:

  • Provide demo scripts (demo.sh, full-demo.sh) and build validation script (build.sh) to showcase end-to-end Agentfile parsing and Docker image builds
  • Include test-build directory with sample Dockerfiles and supporting files for integration testing

@yeahdongcn yeahdongcn requested a review from Copilot June 30, 2025 05:43
@sourcery-ai
Copy link

sourcery-ai bot commented Jun 30, 2025

Reviewer's Guide

This PR introduces a new Go-based Docker Buildx frontend (“agentfile-frontend”) that parses Agentfile syntax, produces corresponding Dockerfile instructions and JSON configs, and wraps it with CLI, container build support, demos, and documentation.

Class diagram for Agentfile Frontend core types

classDiagram
    class AgentfileConfig {
        +string BaseImage
        +string Framework
        +string DefaultModel
        +[]Secret Secrets
        +map[string]MCPServer MCPServers
        +map[string]Agent Agents
        +map[string]Router Routers
        +map[string]Chain Chains
        +map[string]Orchestrator Orchestrators
        +[]int ExposePorts
        +[]string CMD
        +[]DockerInstruction DockerfileInstructions
    }
    class Secret {
        +string Name
        +string Value
    }
    class MCPServer {
        +string Name
        +string Command
        +[]string Args
        +string Transport
        +string URL
        +map[string]string Env
    }
    class Agent {
        +string Name
        +string Instruction
        +[]string Servers
        +string Model
        +bool UseHistory
        +bool HumanInput
        +bool Default
    }
    class Router {
        +string Name
        +[]string Agents
        +string Model
        +string Instruction
        +bool Default
    }
    class Chain {
        +string Name
        +[]string Sequence
        +string Instruction
        +bool Cumulative
        +bool Default
    }
    class Orchestrator {
        +string Name
        +string PlanType
        +int PlanIterations
        +bool Default
    }
    class DockerInstruction {
        +string Instruction
        +[]string Args
    }
    class AgentfileParser {
        -AgentfileConfig* config
        -string currentContext
        -string currentItem
        +ParseFile(filename string) (*AgentfileConfig, error)
        +ParseReader(reader io.Reader) (*AgentfileConfig, error)
    }
    AgentfileConfig o-- Secret
    AgentfileConfig o-- MCPServer
    AgentfileConfig o-- Agent
    AgentfileConfig o-- Router
    AgentfileConfig o-- Chain
    AgentfileConfig o-- Orchestrator
    AgentfileConfig o-- DockerInstruction
    AgentfileParser --> AgentfileConfig
Loading

Flow diagram for Agentfile to Docker image process

flowchart TD
    A[User provides Agentfile] --> B[agentfile-frontend parses Agentfile]
    B --> C[Generate Dockerfile]
    B --> D[Generate JSON config files]
    C --> E[Docker build process]
    D --> E
    E --> F[Docker image with agent system]
Loading

File-Level Changes

Change Details Files
Implement Agentfile parser and Dockerfile generator in Go
  • Define AgentfileConfig, Secret, MCPServer, Agent, Router, Chain, Orchestrator structs
  • Implement AgentfileParser with splitRespectingQuotes, parseLine and context-aware handlers
  • Handle multi-line continuations, quoted arguments, sub-instructions and error reporting
  • Generate final Dockerfile including syntax directive, config file creation and framework-specific code
agentfile-frontend/main.go
Add user and developer documentation
  • Create README.md explaining architecture, supported instructions and usage
  • Provide IMPLEMENTATION_SUMMARY.md detailing features, testing results and future enhancements
agentfile-frontend/README.md
agentfile-frontend/IMPLEMENTATION_SUMMARY.md
Include build, test and demo scripts with example artifacts
  • Add build.sh to compile binary, test examples and container image
  • Add demo.sh and full-demo.sh for manual and end-to-end demos
  • Include test-build context with sample Dockerfile and prompt.txt
agentfile-frontend/build.sh
agentfile-frontend/demo.sh
agentfile-frontend/full-demo.sh
agentfile-frontend/test-build/Dockerfile
agentfile-frontend/test-build/prompt.txt
Containerize the frontend with Dockerfile and Go module
  • Add multi-stage Dockerfile to build and package the binary
  • Define go.mod requiring BuildKit dependency
agentfile-frontend/Dockerfile
agentfile-frontend/go.mod

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @yeahdongcn - I've reviewed your changes and they look great!

Blocking issues:

  • By not specifying a USER, a program in the container may run as 'root'. This is a security hazard. If an attacker can control a process running as root, they may have control over the container. Ensure that the last USER in a Dockerfile is a USER other than 'root'. (link)
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `agentfile-frontend/README.md:59` </location>
<code_context>
+   - Fast-Agent: Generates Fast-Agent-compatible code
+
+4. **Handles secrets as build arguments**:
+   - Converts SECRET instructions to ARG instructions
+   - Supports both named secrets and secret with values
+
+## Installation
</code_context>

<issue_to_address>
Use plural form: 'secrets with values' instead of 'secret with values'.

Change to 'secrets with values' for consistency and correct grammar.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
   - Converts SECRET instructions to ARG instructions
   - Supports both named secrets and secret with values
=======
   - Converts SECRET instructions to ARG instructions
   - Supports both named secrets and secrets with values
>>>>>>> REPLACE

</suggested_fix>

## Security Issues

### Issue 1
<location> `agentfile-frontend/Dockerfile:12` </location>

<issue_to_address>
**security (opengrep-rules.dockerfile.security.missing-user-entrypoint):** By not specifying a USER, a program in the container may run as 'root'. This is a security hazard. If an attacker can control a process running as root, they may have control over the container. Ensure that the last USER in a Dockerfile is a USER other than 'root'.

```suggestion
USER non-root
ENTRYPOINT ["/usr/bin/agentfile-frontend"]
```

*Source: opengrep*
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +59 to +60
- Converts SECRET instructions to ARG instructions
- Supports both named secrets and secret with values
Copy link

Choose a reason for hiding this comment

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

nitpick (typo): Use plural form: 'secrets with values' instead of 'secret with values'.

Change to 'secrets with values' for consistency and correct grammar.

Suggested change
- Converts SECRET instructions to ARG instructions
- Supports both named secrets and secret with values
- Converts SECRET instructions to ARG instructions
- Supports both named secrets and secrets with values


FROM scratch
COPY --from=builder /src/agentfile-frontend /usr/bin/agentfile-frontend
ENTRYPOINT ["/usr/bin/agentfile-frontend"]
Copy link

Choose a reason for hiding this comment

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

security (opengrep-rules.dockerfile.security.missing-user-entrypoint): By not specifying a USER, a program in the container may run as 'root'. This is a security hazard. If an attacker can control a process running as root, they may have control over the container. Ensure that the last USER in a Dockerfile is a USER other than 'root'.

Suggested change
ENTRYPOINT ["/usr/bin/agentfile-frontend"]
USER non-root
ENTRYPOINT ["/usr/bin/agentfile-frontend"]

Source: opengrep

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 introduces a new Docker Buildx frontend for Agentfile syntax, enabling direct conversion from Agentfile to Dockerfile and streamlined image builds.

  • Adds a Go-based AgentfileParser and generateDockerfile to parse Agentfiles and emit Dockerfiles.
  • Includes build, demo, and full-demo scripts to showcase local and Buildx integration.
  • Updates documentation (README, examples) to explain installation, usage, and architecture.

Reviewed Changes

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

Show a summary per file
File Description
main.go New Go parser and Dockerfile generator for Agentfile frontend
Dockerfile Multi-stage build image for the Go binary
build.sh, demo.sh, full-demo.sh Scripts for building, testing, and demoing the frontend
README.md Detailed documentation on usage, features, and future plans
test-build/Dockerfile(.bak), prompt.txt Sample build context and prompt for testing frontend behavior
go.mod Module definition and BuildKit dependency
Comments suppressed due to low confidence (3)

agentfile-frontend/main.go:103

  • Add unit tests for AgentfileParser.ParseFile, ParseReader, and generateDockerfile to verify parser logic and output correctness, and to prevent future regressions.
func (p *AgentfileParser) ParseFile(filename string) (*AgentfileConfig, error) {

agentfile-frontend/README.md:78

  • [nitpick] The syntax directive example is inconsistent. Standardize on the full registry identifier (e.g., # syntax=yeahdongcn/agentfile-frontend:latest) across all README examples.
# syntax=yeahdongcn/agentfile-frontend:latest

agentfile-frontend/test-build/Dockerfile.bak:1

  • [nitpick] Remove the backup file Dockerfile.bak from the test-build directory to avoid confusion and keep only the active Dockerfile.
# syntax=agentfile-frontend


// Generate framework-specific code
dockerfile.WriteString("# Generate framework-specific code\n")
if config.Framework == "agno" {
Copy link

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

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

The comparison against "agno" is case-sensitive. Consider normalizing config.Framework (e.g., strings.ToLower) or using a case-insensitive compare to handle inputs like "AGNO" correctly.

Suggested change
if config.Framework == "agno" {
if strings.ToLower(config.Framework) == "agno" {

Copilot uses AI. Check for mistakes.
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