Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions dashboard/src/dashboard/BotCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ interface BotCardProps {
function getEffectiveStatus(bot: Bot): BotStatus {
const containerState = bot.container_status?.state;
if (containerState === 'running') {
// Check if recently started (within 8 seconds)
const startedAt = bot.container_status?.startedAt;
if (startedAt) {
const elapsed = Date.now() - new Date(startedAt).getTime();
if (elapsed < 8000) return 'starting';
// Use Docker health check status to determine if bot is ready
const health = bot.container_status?.health;
if (health === 'starting') {
return 'starting';
}
if (health === 'unhealthy') {
return 'error';
}
// 'healthy' or 'none' (no healthcheck configured) = running
return 'running';
}
if (containerState === 'exited' || containerState === 'dead') {
Expand Down
3 changes: 3 additions & 0 deletions dashboard/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
export type BotStatus = 'created' | 'starting' | 'running' | 'stopped' | 'error';

export type HealthStatus = 'none' | 'starting' | 'healthy' | 'unhealthy';

export interface ContainerStatus {
id: string;
state: string;
running: boolean;
exitCode: number;
startedAt: string;
finishedAt: string;
health: HealthStatus;
}

export interface Bot {
Expand Down
17 changes: 16 additions & 1 deletion src/services/DockerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ export class DockerService {
[LABEL_BOT_ID]: botId,
[LABEL_BOT_HOSTNAME]: hostname
},
Healthcheck: {
Test: ['CMD', 'wget', '-q', '--spider', `http://localhost:${config.port}/health`],
Interval: 2_000_000_000, // 2s in nanoseconds
Timeout: 3_000_000_000, // 3s in nanoseconds
Retries: 30,
StartPeriod: 5_000_000_000, // 5s in nanoseconds
},
HostConfig: {
Binds: [
`${config.hostSecretsPath}:/run/secrets:ro`,
Expand Down Expand Up @@ -182,13 +189,21 @@ export class DockerService {
const container = this.docker.getContainer(containerName);
const info = await container.inspect();

// Extract health status from Docker's Health field
const healthState = info.State.Health?.Status;
let health: ContainerStatus['health'] = 'none';
if (healthState === 'starting') health = 'starting';
else if (healthState === 'healthy') health = 'healthy';
else if (healthState === 'unhealthy') health = 'unhealthy';

return {
id: info.Id,
state: info.State.Status as ContainerStatus['state'],
running: info.State.Running,
exitCode: info.State.ExitCode,
startedAt: info.State.StartedAt,
finishedAt: info.State.FinishedAt
finishedAt: info.State.FinishedAt,
health
};
} catch (err) {
const dockerErr = err as { statusCode?: number };
Expand Down
4 changes: 4 additions & 0 deletions src/types/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export type ContainerState =
| 'removing'
| 'dead';

/** Docker health check status */
export type HealthStatus = 'none' | 'starting' | 'healthy' | 'unhealthy';

/** Container status from Docker inspect */
export interface ContainerStatus {
id: string;
Expand All @@ -22,6 +25,7 @@ export interface ContainerStatus {
exitCode: number;
startedAt: string;
finishedAt: string;
health: HealthStatus;
}

/** Container info from Docker list (human-readable) */
Expand Down