-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfiguration.ts
104 lines (84 loc) · 3.76 KB
/
configuration.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import * as log from "@std/log";
import { CheckedConfiguration, ConfigOption } from "./lib/env.ts";
import { CONTAINER_ACTIONS, ContainerAction } from "./lib/docker-api.ts";
const SUPERVISION_MODES = ["TAGGED", "UNTAGGED", "PREFIXED", "NOTPREFIXED", "ALL"] as const;
type SupervisorMode = (typeof SUPERVISION_MODES)[number];
type ActorIdentifier = "image" | "name";
function timewindow_converter(value: string): [Temporal.PlainTime, Temporal.PlainTime] {
const [start, end] = value.split("-").map((time) => Temporal.PlainTime.from(time));
if (start === undefined || end === undefined) {
throw new Error(`Invalid time window format: ${value}, should be HH[:MM[:SS]]-HH:[:MM[:SS]]`);
}
return [start, end];
}
export class Configuration extends CheckedConfiguration {
@ConfigOption({ env_variable: "DOLCE_LOG_LEVEL", one_of: log.LogLevelNames })
static readonly loglevel: log.LevelName = "INFO";
@ConfigOption()
static readonly docker_host?: string = "/var/run/docker.sock";
@ConfigOption({ one_of: ["unix", "tcp"] })
static readonly docker_transport: string = "unix";
@ConfigOption({ env_variable: "DOLCE_IDENTIFIER_LABEL" })
static readonly identifier_label: string = "dolce.identifier";
@ConfigOption({
env_variable: "DOLCE_SUPERVISION_MODE",
one_of: SUPERVISION_MODES,
})
static readonly supervision_mode: SupervisorMode = "ALL";
@ConfigOption({ env_variable: "DOLCE_SUPERVISION_LABEL" })
static readonly supervision_label: string = "dolce.enabled";
@ConfigOption({ env_variable: "DOLCE_SUPERVISION_PREFIX" })
static readonly supervision_prefix: string = "temp-";
@ConfigOption({ env_variable: "DOLCE_ACTOR_IDENTIFIER", one_of: ["image", "name"] })
static readonly actor_identifier: ActorIdentifier = "name";
@ConfigOption({ type: Array, env_variable: "DOLCE_EVENTS", some_of: CONTAINER_ACTIONS })
static readonly events: ContainerAction[] = [
"start",
"die",
"kill",
"oom",
"stop",
"pause",
"unpause",
"health_status",
];
@ConfigOption({ type: Number, env_variable: "DOLCE_MIN_TIMEOUT" })
static readonly min_timeout: number = 10;
@ConfigOption({ type: Number, env_variable: "DOLCE_MAX_TIMEOUT" })
static readonly max_timeout: number = 60 * 60 * 24;
@ConfigOption({ type: Number, env_variable: "DOLCE_MULTIPLIER" })
static readonly multiplier: number = 10;
@ConfigOption({ env_variable: "DOLCE_RUN_DIRECTORY" })
static readonly run_directory: string = "/var/run/dolce/";
@ConfigOption({ env_variable: "DOLCE_CUSTOM_TEMPLATE_PATH" })
static readonly custom_template_path: string = "/var/dolce-custom-templates/";
@ConfigOption({
type: Array,
env_variable: "DOLCE_BLACKOUT_WINDOWS",
transformer: (values: string[]) => values.map((value: string) => timewindow_converter(value)),
})
static readonly blackout_windows: [Temporal.PlainTime, Temporal.PlainTime][] = [];
@ConfigOption({ type: Boolean, env_variable: "DOLCE_DEBUG" })
static readonly debug: boolean = false;
static toString() {
return `\nConfiguration {
${
Object.entries(Configuration)
.map(([key, value]) => `\t${key}: ${value}`)
.join(",\n")
}
}`;
}
}
log.setup({
handlers: {
default: new log.ConsoleHandler(Configuration.loglevel, {
formatter: (record) => `${record.levelName}\t${record.loggerName}\t ${record.msg}`,
}),
},
loggers: {
main: { level: Configuration.loglevel, handlers: ["default"] },
notifier: { level: Configuration.loglevel, handlers: ["default"] },
lockfile: { level: Configuration.loglevel, handlers: ["default"] },
},
});