(ctx context.Context, cmd string, opts models.SetupOptions)
| 1164 | } |
| 1165 | |
| 1166 | func (a *AgentClient) Setup(ctx context.Context, cmd string, opts models.SetupOptions) error { |
| 1167 | isDockerCmd := utils.IsDockerCmd(utils.CmdType(opts.CommandType)) |
| 1168 | opts.IsDocker = isDockerCmd |
| 1169 | |
| 1170 | agentPort, err := utils.GetAvailablePort() |
| 1171 | if err != nil { |
| 1172 | utils.LogError(a.logger, err, "failed to find available port for agent") |
| 1173 | return err |
| 1174 | } |
| 1175 | |
| 1176 | // Check and allocate available ports for proxy and DNS |
| 1177 | proxyPort, err := utils.EnsureAvailablePorts(a.conf.ProxyPort) // check if the proxy port provided by user is unused |
| 1178 | if err != nil { |
| 1179 | utils.LogError(a.logger, err, "failed to ensure available ports for proxy") |
| 1180 | return err |
| 1181 | } |
| 1182 | |
| 1183 | dnsPort, err := utils.EnsureAvailablePorts(a.conf.DNSPort) // check if the dns port provided by user is unused |
| 1184 | if err != nil { |
| 1185 | utils.LogError(a.logger, err, "failed to ensure available ports for DNS") |
| 1186 | return err |
| 1187 | } |
| 1188 | |
| 1189 | opts.AgentPort = agentPort |
| 1190 | opts.ProxyPort = proxyPort |
| 1191 | opts.DnsPort = dnsPort |
| 1192 | opts.AgentURI = fmt.Sprintf("http://localhost:%d/agent", agentPort) |
| 1193 | |
| 1194 | // Update the ports in the configuration |
| 1195 | a.conf.Agent.AgentPort = agentPort |
| 1196 | a.conf.Agent.ProxyPort = proxyPort |
| 1197 | a.conf.Agent.DnsPort = dnsPort |
| 1198 | a.conf.ProxyPort = proxyPort |
| 1199 | a.conf.DNSPort = dnsPort |
| 1200 | a.conf.Agent.AgentURI = opts.AgentURI |
| 1201 | |
| 1202 | a.logger.Debug("Using available ports", |
| 1203 | zap.Uint32("agent-port", agentPort), |
| 1204 | zap.Uint32("proxy-port", proxyPort), |
| 1205 | zap.Uint32("dns-port", dnsPort)) |
| 1206 | |
| 1207 | if isDockerCmd { |
| 1208 | |
| 1209 | var origCmd = cmd |
| 1210 | a.logger.Debug("Application command provided :", zap.String("cmd", cmd)) |
| 1211 | |
| 1212 | opts.KeployContainer = agentUtils.GenerateRandomContainerName(a.logger, "keploy-v3-") |
| 1213 | a.conf.KeployContainer = opts.KeployContainer |
| 1214 | |
| 1215 | var appPorts, appNetworks []string |
| 1216 | cmd, appPorts, appNetworks = agentUtils.ExtractDockerFlags(cmd) |
| 1217 | |
| 1218 | opts.AppPorts = appPorts |
| 1219 | if len(appNetworks) > 0 { |
| 1220 | opts.AppNetworks = appNetworks |
| 1221 | a.logger.Debug("Found docker networks", zap.Strings("networks", opts.AppNetworks)) |
| 1222 | } |
| 1223 |
nothing calls this directly
no test coverage detected