-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhealthcheck.ts
45 lines (38 loc) · 1.29 KB
/
healthcheck.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Cmd } from './cmd';
import { IDockerCommand, StageBuildContext } from '../stage';
export interface IHealthcheckOptions {
interval?: string;
timeout?: string;
startPeriod?: string;
retries?: number;
}
export class Healthcheck implements IDockerCommand {
constructor(public readonly command: Cmd | 'NONE',
public readonly options: IHealthcheckOptions = {}) {
}
protected getParameters() {
let parameters = '';
if (this.options.interval) {
parameters += ` --interval=${this.options.interval}`;
}
if (this.options.timeout) {
parameters += ` --timeout=${this.options.timeout}`;
}
if (this.options.startPeriod) {
parameters += ` --start-period=${this.options.startPeriod}`;
}
if (this.options.retries) {
parameters += ` --retries=${this.options.retries}`;
}
return parameters
}
toDockerCommand(context : StageBuildContext) {
if (this.command === 'NONE') {
return 'HEALTHCHECK NONE';
}
return `HEALTHCHECK${this.getParameters()} ${this.command.toDockerCommand(context)}`;
}
}
export function healthcheck(...args: ConstructorParameters<typeof Healthcheck>) {
return new Healthcheck(...args);
}