mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 14:36:25 +00:00
feat: enable docker by default (#1026)
Docker does now not need to be explicitly enabled. Closes #942
This commit is contained in:
parent
b2f35fef44
commit
9c16565a2d
6 changed files with 61 additions and 65 deletions
|
@ -602,7 +602,7 @@ const options = [
|
|||
stage: 'repository',
|
||||
type: 'json',
|
||||
default: {
|
||||
enabled: false,
|
||||
enabled: true,
|
||||
branchName: template('branchName', 'docker'),
|
||||
commitMessage: template('commitMessage', 'docker'),
|
||||
prTitle: template('prTitle', 'docker'),
|
||||
|
|
|
@ -227,58 +227,47 @@ async function mergeRenovateJson(config, branchName) {
|
|||
return returnConfig;
|
||||
}
|
||||
|
||||
async function detectPackageFiles(input, detectAllLanguages = false) {
|
||||
async function detectPackageFiles(input) {
|
||||
const config = { ...input };
|
||||
const { logger } = config;
|
||||
logger.debug({ config }, 'detectPackageFiles');
|
||||
config.types = {};
|
||||
if (detectAllLanguages || config.npm.enabled) {
|
||||
config.packageFiles = await config.api.findFilePaths('package.json');
|
||||
logger.debug(
|
||||
{ packageFiles: config.packageFiles },
|
||||
`Found ${config.packageFiles.length} package file(s)`
|
||||
);
|
||||
if (Array.isArray(config.ignorePaths)) {
|
||||
function filterIgnorePaths(packageFiles, ignorePaths) {
|
||||
logger.debug('Checking ignorePaths');
|
||||
const skippedPackageFiles = [];
|
||||
config.packageFiles = config.packageFiles.filter(packageFile => {
|
||||
return packageFiles.filter(packageFile => {
|
||||
logger.trace(`Checking ${packageFile}`);
|
||||
if (
|
||||
config.ignorePaths.some(ignorePath => {
|
||||
ignorePaths.some(ignorePath => {
|
||||
logger.trace(` ..against ${ignorePath}`);
|
||||
return packageFile.includes(ignorePath);
|
||||
})
|
||||
) {
|
||||
logger.trace('Filtered out');
|
||||
skippedPackageFiles.push(packageFile);
|
||||
return false;
|
||||
}
|
||||
logger.trace('Included');
|
||||
return true;
|
||||
});
|
||||
if (skippedPackageFiles.length) {
|
||||
logger.debug(
|
||||
{ skippedPackageFiles },
|
||||
`Skipped ${skippedPackageFiles.length} file(s)`
|
||||
);
|
||||
config.foundIgnoredPaths = true;
|
||||
config.warnings.push({
|
||||
depName: 'packageFiles',
|
||||
message: `Skipped package.json files found within ignored paths: \`${skippedPackageFiles}\``,
|
||||
});
|
||||
logger.debug(
|
||||
`Now have ${config.packageFiles
|
||||
.length} package file(s) after filtering`
|
||||
);
|
||||
}
|
||||
}
|
||||
logger.debug({ config }, 'detectPackageFiles');
|
||||
config.types = {};
|
||||
if (config.npm.enabled) {
|
||||
config.packageFiles = filterIgnorePaths(
|
||||
await config.api.findFilePaths('package.json'),
|
||||
config.ignorePaths
|
||||
);
|
||||
logger.debug(
|
||||
{ packageFiles: config.packageFiles },
|
||||
`Found ${config.packageFiles.length} package.json file(s)`
|
||||
);
|
||||
if (config.packageFiles.length) {
|
||||
config.types.npm = true;
|
||||
}
|
||||
}
|
||||
if (detectAllLanguages || config.meteor.enabled) {
|
||||
if (config.meteor.enabled) {
|
||||
logger.debug('Detecting meteor package.js files');
|
||||
const allPackageJs = await config.api.findFilePaths('package.js');
|
||||
const allPackageJs = filterIgnorePaths(
|
||||
await config.api.findFilePaths('package.js'),
|
||||
config.ignorePaths
|
||||
);
|
||||
const meteorPackageFiles = [];
|
||||
for (const mFile of allPackageJs) {
|
||||
const packageJsContent = await config.api.getFileContent(mFile);
|
||||
|
@ -298,13 +287,24 @@ async function detectPackageFiles(input, detectAllLanguages = false) {
|
|||
config.packageFiles = config.packageFiles.concat(meteorPackageFiles);
|
||||
}
|
||||
}
|
||||
if (detectAllLanguages || config.docker.enabled) {
|
||||
if (config.docker.enabled) {
|
||||
logger.debug('Detecting Dockerfiles');
|
||||
const dockerFiles = await config.api.findFilePaths('Dockerfile');
|
||||
if (dockerFiles.length) {
|
||||
logger.info({ count: dockerFiles.length }, `Found Dockerfiles`);
|
||||
const files = filterIgnorePaths(
|
||||
await config.api.findFilePaths('Dockerfile'),
|
||||
config.ignorePaths
|
||||
);
|
||||
for (const file of files) {
|
||||
const content = await config.api.getFileContent(file);
|
||||
const strippedComment = content.replace(/^(#.*?\n)+/, '');
|
||||
// This means we skip ones with ARG for now
|
||||
const fromMatch = strippedComment.startsWith('FROM ');
|
||||
if (fromMatch) {
|
||||
config.packageFiles.push(file);
|
||||
config.types.docker = true;
|
||||
config.packageFiles = config.packageFiles.concat(dockerFiles);
|
||||
}
|
||||
}
|
||||
if (config.types.docker) {
|
||||
logger.info(`Found Dockerfiles`);
|
||||
}
|
||||
}
|
||||
return config;
|
||||
|
|
|
@ -26,8 +26,7 @@ async function createOnboardingBranch(inputConfig) {
|
|||
let config = { ...inputConfig };
|
||||
const { logger } = config;
|
||||
logger.debug('Creating onboarding branch');
|
||||
const detectAllLanguages = true;
|
||||
config = await apis.detectPackageFiles(config, detectAllLanguages);
|
||||
config = await apis.detectPackageFiles(config);
|
||||
if (config.packageFiles.length === 0) {
|
||||
throw new Error('no package files');
|
||||
}
|
||||
|
@ -46,9 +45,6 @@ async function createOnboardingBranch(inputConfig) {
|
|||
} else {
|
||||
renovateJson.extends.push('config:base');
|
||||
}
|
||||
if (config.types.docker) {
|
||||
renovateJson.extends.push(':docker');
|
||||
}
|
||||
logger.info({ renovateJson }, 'Creating onboarding branch');
|
||||
await config.api.commitFilesToBranch(
|
||||
config.onboardingBranch,
|
||||
|
|
|
@ -55,16 +55,9 @@ Array [
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`workers/repository/apis detectPackageFiles(config) ignores node modules 2`] = `true`;
|
||||
exports[`workers/repository/apis detectPackageFiles(config) ignores node modules 2`] = `undefined`;
|
||||
|
||||
exports[`workers/repository/apis detectPackageFiles(config) ignores node modules 3`] = `
|
||||
Array [
|
||||
Object {
|
||||
"depName": "packageFiles",
|
||||
"message": "Skipped package.json files found within ignored paths: \`node_modules/backend/package.json\`",
|
||||
},
|
||||
]
|
||||
`;
|
||||
exports[`workers/repository/apis detectPackageFiles(config) ignores node modules 3`] = `Array []`;
|
||||
|
||||
exports[`workers/repository/apis detectPackageFiles(config) skips meteor package files with no json 1`] = `Array []`;
|
||||
|
||||
|
|
|
@ -413,8 +413,7 @@ Array [
|
|||
Object {
|
||||
"contents": "{
|
||||
\\"extends\\": [
|
||||
\\"config:base\\",
|
||||
\\":docker\\"
|
||||
\\"config:base\\"
|
||||
]
|
||||
}
|
||||
",
|
||||
|
|
|
@ -302,8 +302,16 @@ describe('workers/repository/apis', () => {
|
|||
it('finds Dockerfiles', async () => {
|
||||
config.api.findFilePaths.mockReturnValueOnce([]);
|
||||
config.api.findFilePaths.mockReturnValueOnce([]);
|
||||
config.api.findFilePaths.mockReturnValueOnce(['Dockerfile']);
|
||||
config.docker.enabled = true;
|
||||
config.api.findFilePaths.mockReturnValueOnce([
|
||||
'Dockerfile',
|
||||
'other/Dockerfile',
|
||||
]);
|
||||
config.api.getFileContent.mockReturnValueOnce(
|
||||
'### comment\nFROM something\nRUN something'
|
||||
);
|
||||
config.api.getFileContent.mockReturnValueOnce(
|
||||
'ARG foo\nFROM something\nRUN something'
|
||||
);
|
||||
const res = await apis.detectPackageFiles(config);
|
||||
expect(res.packageFiles).toMatchSnapshot();
|
||||
expect(res.packageFiles).toHaveLength(1);
|
||||
|
|
Loading…
Reference in a new issue