-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcanIDeploy.js
More file actions
61 lines (56 loc) · 1.68 KB
/
canIDeploy.js
File metadata and controls
61 lines (56 loc) · 1.68 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require("dotenv").config();
const path = require("path");
const { getPacticipant, getPacticipantForImage } = require("./getPacticipant");
const fs = require("fs");
const yaml = require("js-yaml");
const _ = require("lodash");
const pact = require("@pact-foundation/pact-node");
function getPacticipants({ kustomizeFile, serviceNames }) {
const yamlFile = path.resolve(kustomizeFile);
const doc = yaml.safeLoad(fs.readFileSync(yamlFile, "utf8"));
const imageTagPairs = _.fromPairs(
doc.images
.filter((a) => serviceNames.indexOf(_.last(a.name.split("/"))) > -1)
.map((a) => [getPacticipantForImage(a.name), a.newTag])
);
const pacticipants = Object.entries(imageTagPairs).map(([name, version]) => ({
name,
version,
}));
return pacticipants;
}
exports.getPacticipants = getPacticipants;
exports.canIDeploy = function({
kustomizeFile,
retryTimes,
retryInterval,
brokerUrl,
brokerToken,
consumer,
providers,
// verbose
}) {
const defaultOptions = {
pactBroker: brokerUrl || process.env.PACT_BROKER_URL,
pactBrokerToken: brokerToken || process.env.PACT_BROKER_TOKEN,
retryWhileUnknown: retryTimes || 5,
retryInterval: retryInterval || 30,
output: "table",
};
const promises = providers.map((provider) => {
const pacticipants = getPacticipants({
kustomizeFile,
serviceNames: [consumer, provider],
});
const canDeployOptions = { pacticipants, ...defaultOptions };
return pact.canDeploy(canDeployOptions).catch(
async () =>
await pact.canDeploy({
...canDeployOptions,
retryWhileUnknown: 0,
retryInterval: 0,
})
);
});
return Promise.all(promises);
};