Skip to content

Commit 4aa66fc

Browse files
committed
Add BuildArgs support to TemplateData and all templates
- Add BuildArgs field to TemplateData struct for baking required CLI arguments into container ENTRYPOINT at build time - Update npx.tmpl to insert BuildArgs before "$@" - Update uvx.tmpl to insert BuildArgs before "$@" - Update go.tmpl to insert BuildArgs in JSON array format BuildArgs are for required subcommands (e.g., 'start') while runtime args passed via '-- <args>' append after. This prevents duplication issues that led to MCPArgs removal in PR #2630. Related to: stacklok/dockyard#189
1 parent 832c968 commit 4aa66fc

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

pkg/container/templates/go.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,4 @@ COPY --from=builder --chown=appuser:appgroup /build/ /app/
9999
USER appuser
100100

101101
# Run the pre-built MCP server binary
102-
ENTRYPOINT ["/app/mcp-server"]
102+
ENTRYPOINT ["/app/mcp-server"{{range .BuildArgs}}, "{{.}}{{end}}"]

pkg/container/templates/npx.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ USER appuser
9898
# `MCPPackage` may include a version suffix (e.g., `[email protected]`), which we cannot use here.
9999
# Create a small wrapper script to handle this.
100100
RUN echo "#!/bin/sh" >> entrypoint.sh && \
101-
echo "exec npx {{.MCPPackage}} \"\$@\"" >> entrypoint.sh && \
101+
echo "exec npx {{.MCPPackage}}{{range .BuildArgs}} {{.}}{{end}} \"\$@\"" >> entrypoint.sh && \
102102
chmod +x entrypoint.sh
103103

104104
# Run the preinstalled MCP package directly using npx.

pkg/container/templates/templates.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ type TemplateData struct {
2020
CACertContent string
2121
// IsLocalPath indicates if the MCPPackage is a local path that should be copied into the container.
2222
IsLocalPath bool
23+
// BuildArgs are the arguments to bake into the container's ENTRYPOINT at build time.
24+
// These are typically required subcommands (e.g., "start") that must always be present.
25+
// Runtime arguments passed via "-- <args>" will be appended after these build args.
26+
BuildArgs []string
2327
}
2428

2529
// TransportType represents the type of transport to use.

pkg/container/templates/uvx.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,4 @@ USER appuser
118118
# We use sh -c to allow the package name to be resolved from PATH
119119
# Strip version specifier (if present) from package name for execution
120120
# Handles format like package@version
121-
ENTRYPOINT ["sh", "-c", "package='{{.MCPPackage}}'; exec \"${package%%@*}\"", "--"]
121+
ENTRYPOINT ["sh", "-c", "package='{{.MCPPackage}}'; exec \"${package%%@*}\"{{range .BuildArgs}} \"{{.}}\"{{end}}", "--"]

0 commit comments

Comments
 (0)