-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetImageTag.js
More file actions
36 lines (32 loc) · 1.03 KB
/
getImageTag.js
File metadata and controls
36 lines (32 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const path = require("path");
const yaml = require("js-yaml");
const fs = require("fs");
const _ = require("lodash");
function getImage({ filePath, imageName }) {
const yamlFile = path.resolve(filePath);
const doc = yaml.safeLoad(fs.readFileSync(yamlFile, "utf8"));
const images = _.fromPairs(doc.images.map(a => [a.name, a.newTag]));
if (!images[imageName]) {
throw new Error(`Image ${imageName} not found`);
}
return images[imageName].toString();
}
module.exports = getImage;
// exports.handler = argv => {
// getImage({ filePath: argv._[0], imageName: argv._[1] });
// };
// exports.command = "<filename> <imageName>";
// exports.describe =
// "get the tag of the imageName in the kustomization file <filename>";
// module.exports = getImage;
// if (require.main === module) {
// console.log(
// getImage("../gitops/overlays/prod-images/kustomization.yaml", "frontend")
// );
// console.log(
// getImage(
// "../gitops/overlays/prod-images/kustomization.yaml",
// "doesnot-exist"
// )
// );
// }