(opts buildMCPGatewayContainerCommandOptions)
| 700 | } |
| 701 | |
| 702 | func buildMCPGatewayContainerCommand(opts buildMCPGatewayContainerCommandOptions) string { |
| 703 | engine := opts.engine |
| 704 | workflowData := opts.workflowData |
| 705 | gatewayConfig := opts.gatewayConfig |
| 706 | mcpEnvVars := opts.mcpEnvVars |
| 707 | payloadDir := opts.payloadDir |
| 708 | payloadPathPrefix := opts.payloadPathPrefix |
| 709 | hasGitHub := opts.hasGitHub |
| 710 | githubTool := opts.githubTool |
| 711 | tools := opts.tools |
| 712 | containerImage := gatewayConfig.Container |
| 713 | if gatewayConfig.Version != "" { |
| 714 | containerImage += ":" + gatewayConfig.Version |
| 715 | } else { |
| 716 | containerImage += ":" + string(constants.DefaultMCPGatewayVersion) |
| 717 | } |
| 718 | var containerCmd strings.Builder |
| 719 | // Pre-size the builder to avoid reallocations. The base flags from |
| 720 | // appendMCPGatewayBaseEnvFlags alone write ~2KB of -e flags; allocating |
| 721 | // 2048 bytes upfront covers the common case without overcommitting. |
| 722 | containerCmd.Grow(2048) |
| 723 | containerCmd.WriteString("docker run -i --rm") |
| 724 | if isAWFNetworkIsolationEnabled(workflowData) { |
| 725 | containerCmd.WriteString(" --network bridge") |
| 726 | // Publish the gateway port to the host so host-side clients (e.g. Gemini CLI) |
| 727 | // can reach the gateway at localhost:${MCP_GATEWAY_PORT}. |
| 728 | containerCmd.WriteString(" -p 127.0.0.1:${MCP_GATEWAY_PORT}:${MCP_GATEWAY_PORT}") |
| 729 | } else { |
| 730 | containerCmd.WriteString(" --network host") |
| 731 | } |
| 732 | containerCmd.WriteString(" --name awmg-mcpg") |
| 733 | if !isAWFNetworkIsolationEnabled(workflowData) { |
| 734 | containerCmd.WriteString(" --add-host host.docker.internal:127.0.0.1") |
| 735 | } |
| 736 | containerCmd.WriteString(" --user ${MCP_GATEWAY_UID}:${MCP_GATEWAY_GID}") |
| 737 | containerCmd.WriteString(" --group-add ${DOCKER_SOCK_GID}") |
| 738 | containerCmd.WriteString(" -v ${DOCKER_SOCK_PATH}:/var/run/docker.sock") |
| 739 | appendMCPGatewayBaseEnvFlags(&containerCmd, payloadPathPrefix) |
| 740 | appendMCPGatewayConditionalEnvFlags(&containerCmd, workflowData, engine, hasGitHub, githubTool, tools) |
| 741 | appendMCPGatewayCustomAndHTTPEnvFlags(&containerCmd, workflowData, gatewayConfig, mcpEnvVars, hasGitHub, githubTool, tools, engine) |
| 742 | if payloadDir != "" { |
| 743 | containerCmd.WriteString(" -v " + payloadDir + ":" + payloadDir + ":rw") |
| 744 | } |
| 745 | for _, mount := range gatewayConfig.Mounts { |
| 746 | containerCmd.WriteString(" -v " + mount) |
| 747 | } |
| 748 | if gatewayConfig.Entrypoint != "" { |
| 749 | containerCmd.WriteString(" --entrypoint " + shellEscapeArg(gatewayConfig.Entrypoint)) |
| 750 | } |
| 751 | containerCmd.WriteString(" " + containerImage) |
| 752 | for _, arg := range gatewayConfig.EntrypointArgs { |
| 753 | containerCmd.WriteString(" " + shellEscapeArg(arg)) |
| 754 | } |
| 755 | for _, arg := range gatewayConfig.Args { |
| 756 | containerCmd.WriteString(" " + shellEscapeArg(arg)) |
| 757 | } |
| 758 | return containerCmd.String() |
| 759 | } |
no test coverage detected