feat(appstore): add service volumes and published ports
This commit is contained in:
@@ -175,8 +175,10 @@ export class SmartProxyManager {
|
||||
throw new Error(`Failed to create SmartProxy service: HTTP ${response.statusCode} - ${JSON.stringify(response.body)}`);
|
||||
}
|
||||
|
||||
logger.info(`SmartProxy service created: ${response.body.ID}`);
|
||||
const serviceId = response.body.ID;
|
||||
logger.info(`SmartProxy service created: ${serviceId}`);
|
||||
|
||||
await this.waitForServiceTaskRunning(serviceId);
|
||||
await this.waitForReady();
|
||||
this.serviceRunning = true;
|
||||
await this.reloadConfig({ skipRunningCheck: true });
|
||||
@@ -232,6 +234,37 @@ export class SmartProxyManager {
|
||||
throw new Error('SmartProxy service failed to start within timeout');
|
||||
}
|
||||
|
||||
private async waitForServiceTaskRunning(
|
||||
serviceIdArg: string,
|
||||
maxAttempts = 30,
|
||||
intervalMs = 1000,
|
||||
): Promise<void> {
|
||||
let lastState = 'unknown';
|
||||
|
||||
for (let i = 0; i < maxAttempts; i++) {
|
||||
const tasksResponse = await this.dockerClient!.request(
|
||||
'GET',
|
||||
`/tasks?filters=${encodeURIComponent(JSON.stringify({ service: [serviceIdArg] }))}`,
|
||||
{},
|
||||
);
|
||||
|
||||
if (tasksResponse.statusCode === 200 && Array.isArray(tasksResponse.body)) {
|
||||
const tasks = tasksResponse.body;
|
||||
const runningTask = tasks.find((task: any) => task.Status?.State === 'running');
|
||||
if (runningTask) {
|
||||
return;
|
||||
}
|
||||
|
||||
const latestTask = tasks[0];
|
||||
lastState = latestTask?.Status?.State || lastState;
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
||||
}
|
||||
|
||||
throw new Error(`SmartProxy service task did not reach running state (last state: ${lastState})`);
|
||||
}
|
||||
|
||||
async stop(): Promise<void> {
|
||||
try {
|
||||
await this.ensureDockerClient();
|
||||
|
||||
Reference in New Issue
Block a user