Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RunOnFluxBot committed Jan 30, 2025
1 parent fc22a45 commit d25e67f
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions services/dockerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,23 @@ async function obtainPayloadFromStorage(url, appName) {
}
}

const getContainerIP = async (containerName) => {
try {
const container = await docker.getContainer(containerName).inspect();
const networks = Object.keys(container.NetworkSettings.Networks);

if (networks.length === 0) {
throw new Error('No networks found for container');
}

const networkName = networks[0]; // Use the first (and only) network
return container.NetworkSettings.Networks[networkName].IPAddress;
} catch (error) {
log.error(`Failed to retrieve IP for ${containerName}: ${error.message}`);
return null;
}
};

/**
* Creates an app container.
*
Expand Down Expand Up @@ -648,21 +665,26 @@ async function appDockerCreate(appSpecifications, appName, isComponent, fullAppS
}
});

// Identify apps with LOG=SEND
const isRemoteLog = envParams?.some((env) => env.startsWith('LOG=SEND'));
// Find target app with LOG=COLLECT
const isSender = envParams?.some((env) => env.startsWith('LOG=SEND'));

let syslogTarget = null;
if (fullAppSpecs && fullAppSpecs.compose) {
let syslogIP = null;

if (fullAppSpecs && fullAppSpecs?.compose) {
syslogTarget = fullAppSpecs.compose.find((app) => app.environmentParameters?.some((env) => env.startsWith('LOG=COLLECT')))?.name;
}

log.info(`isRemoteLog=${isRemoteLog}, syslogTarget=${syslogTarget}`);
if (syslogTarget) {
syslogIP = await getContainerIP(`flux${syslogTarget}_${appName}`);
}

log.info(`isSender=${isSender}, syslogTarget=${syslogTarget}, syslogIP=${syslogIP}`);

const logConfig = isRemoteLog && syslogTarget
const logConfig = isSender && syslogTarget && syslogIP
? {
Type: 'syslog',
Config: {
'syslog-address': `udp://${syslogTarget}:514`,
'syslog-address': `udp://${syslogIP}:514`,
'syslog-facility': 'local0',
tag: `${appSpecifications.name}`,
},
Expand Down

0 comments on commit d25e67f

Please sign in to comment.