| 284 | } |
| 285 | |
| 286 | allocatePort(cfg: InstanceConfig) { |
| 287 | const globalCfg = globalConfiguration.config; |
| 288 | const [minPort, maxPort] = globalCfg.allocatablePortRange; |
| 289 | |
| 290 | cfg.basePort = globalCfg.currentAllocatablePort; |
| 291 | globalCfg.currentAllocatablePort += globalCfg.portAssignInterval; |
| 292 | |
| 293 | if (globalCfg.currentAllocatablePort > maxPort) { |
| 294 | globalCfg.currentAllocatablePort = minPort; |
| 295 | } |
| 296 | |
| 297 | // Avoid port overlap with Daemon. |
| 298 | if ( |
| 299 | cfg.basePort <= globalCfg.port && |
| 300 | cfg.basePort + globalCfg.portAssignInterval >= globalCfg.port |
| 301 | ) { |
| 302 | cfg.basePort = globalCfg.port + 1; |
| 303 | globalCfg.currentAllocatablePort = cfg.basePort + globalCfg.portAssignInterval; |
| 304 | } |
| 305 | |
| 306 | globalConfiguration.store(); |
| 307 | } |
| 308 | |
| 309 | resetConfigWithoutDocker() { |
| 310 | const newDockerCfg: IGlobalInstanceConfig["docker"] = JSON.parse( |