renovate/lib/manager/docker-compose/update.js
Rhys Arkins a0e2a18e7a
refactor(docker): rename docker manager to dockerfile (#2298)
"docker" in config now refers to the Docker "language", which is the parent of dockerfile, docker-compose and circleci managers.
2018-07-21 19:40:50 +02:00

29 lines
904 B
JavaScript

const { getNewFrom } = require('../dockerfile/update');
module.exports = {
updateDependency,
};
function updateDependency(fileContent, upgrade) {
try {
const newFrom = getNewFrom(upgrade);
logger.debug(`docker-compose.updateDependency(): ${newFrom}`);
const lines = fileContent.split('\n');
const lineToChange = lines[upgrade.lineNumber];
const imageLine = new RegExp(/^(\s*image:\s*'?"?)[^\s'"]+('?"?\s*)$/);
if (!lineToChange.match(imageLine)) {
logger.debug('No image line found');
return null;
}
const newLine = lineToChange.replace(imageLine, `$1${newFrom}$2`);
if (newLine === lineToChange) {
logger.debug('No changes necessary');
return fileContent;
}
lines[upgrade.lineNumber] = newLine;
return lines.join('\n');
} catch (err) {
logger.info({ err }, 'Error setting new Dockerfile value');
return null;
}
}