Add support for init field from compose

Init supports boolean values, and is not included in the config when
not defined.

Change-type: patch
Signed-off-by: Christina Ying Wang <christina@balena.io>
This commit is contained in:
Christina Ying Wang
2024-09-09 14:39:42 -07:00
committed by Felipe Lalanne
parent e01aaaaafb
commit ed1c18e369
7 changed files with 412 additions and 3 deletions

View File

@ -337,6 +337,13 @@ class ServiceImpl implements Service {
config.tty = Boolean(config.tty);
}
// Only keep init field if it's a boolean
if (config.init != null) {
config.init = Boolean(config.init);
} else {
delete config.init;
}
if (Array.isArray(config.sysctls)) {
config.sysctls = _.fromPairs(
_.map(config.sysctls, (v) => _.split(v, '=')),
@ -598,6 +605,11 @@ class ServiceImpl implements Service {
tty: container.Config.Tty || false,
};
// Only add `init` if true or false, otherwise leave blank
if (typeof container.HostConfig.Init === 'boolean') {
svc.config.init = container.HostConfig.Init;
}
const appId = checkInt(svc.config.labels['io.balena.app-id']);
if (appId == null) {
throw new InternalInconsistencyError(
@ -739,6 +751,7 @@ class ServiceImpl implements Service {
UsernsMode: this.config.usernsMode,
NanoCpus: this.config.cpus,
IpcMode: this.config.ipc,
Init: this.config.init,
} as Dockerode.ContainerCreateOptions['HostConfig'],
Healthcheck: ComposeUtils.serviceHealthcheckToDockerHealthcheck(
this.config.healthcheck,

View File

@ -183,7 +183,7 @@ export interface ServiceComposeConfig {
groupAdd?: string[];
healthcheck?: ComposeHealthcheck;
image: string;
init?: string | boolean;
init?: boolean;
labels?: { [labelName: string]: string };
running?: boolean;
networkMode?: string;
@ -272,6 +272,7 @@ export interface ServiceConfig {
domainname: string;
hostname: string;
ipc: string;
init?: boolean;
macAddress: string;
memLimit: number;
memReservation: number;