feat(appstore): add service volumes and published ports

This commit is contained in:
2026-05-24 07:28:18 +00:00
parent e6ebac76b4
commit 5228eeaa23
26 changed files with 1790 additions and 348 deletions
+34 -1
View File
@@ -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();