Skip to content

Instantly share code, notes, and snippets.

@brurucy
Last active June 30, 2022 10:59
Show Gist options
  • Save brurucy/51ea9e4c7025064f5bb3c9d88d59e813 to your computer and use it in GitHub Desktop.
Save brurucy/51ea9e4c7025064f5bb3c9d88d59e813 to your computer and use it in GitHub Desktop.
dora-snippet-example
module.exports = async function (config) {
try {
// Negative Lookahead on comments line
const key = `^(?!#)${config.param}`;
// Get Base image from Dockerfile.CI
const dockerfileCIResults = await findStringByKey(config, key);
const dockerFileConfig = { path: 'Dockerfile', param: config.param };
const dockerfileResults = await findStringByKey(dockerFileConfig, key);
if (dockerfileCIResults.length > 0) {
// Compare the last FROM ocurrency for both files
const baseImageCI = dockerfileCIResults.slice(-1)[0].line.value;
if (dockerfileResults.length > 0) {
// Image found in both files
const baseDevImage = dockerfileResults.slice(-1)[0].line.value.trim();
if (baseImageCI !== baseDevImage && `${baseImageCI}-dev` !== baseDevImage && !isGoService()) {
await reporter.report(config, dockerfileCIResults.slice(-1)[0].line);
}
} else {
// Image found only in Dockerfile.CI
await reporter.report(config, dockerfileCIResults.slice(-1)[0].line);
}
} else {
if (dockerfileResults.length > 0) {
// Image found only in Dockerfile
await reporter.report(config, dockerfileResults.slice(-1)[0].line);
}
}
} catch (err) {
const error = `Error message: ${err}`;
await reporter.reportError(error, config);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment