-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1c80ff
commit d2f0a30
Showing
11 changed files
with
899 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules/* | ||
.git | ||
.git | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
resources: | ||
- ../../base | ||
|
||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
images: | ||
- name: gcr.io/kollate-218719/auth-service | ||
newTag: 4284bc991c815591eddaf6034d0dfc171fdfa77d | ||
- name: gcr.io/kollate-218719/frontend | ||
newTag: 27c177e79511aa74a43a5dd319274910c8a3cc1d | ||
- name: gcr.io/kollate-218719/gateway | ||
newTag: a4349c2c93535f9db51e73e701f6aadb229e8ac3 | ||
- name: gcr.io/kollate-218719/group-service | ||
newTag: d45454cab2ff92c6e60e7af731639fbbfc3f79d9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require("dotenv").config(); | ||
const path = require("path"); | ||
const { getPacticipant } = require("./getPacticipant"); | ||
const fs = require("fs"); | ||
const yaml = require("js-yaml"); | ||
const _ = require("lodash"); | ||
const pact = require("@pact-foundation/pact-node"); | ||
|
||
exports.canIDeploy = function({ | ||
kustomizeFile, | ||
retryTimes, | ||
retryInterval, | ||
brokerUrl, | ||
brokerToken | ||
// verbose | ||
}) { | ||
const yamlFile = path.resolve(kustomizeFile); | ||
const doc = yaml.safeLoad(fs.readFileSync(yamlFile, "utf8")); | ||
|
||
const imageTagPairs = _.fromPairs( | ||
doc.images.map(a => [getPacticipant(a.name), a.newTag]) | ||
); | ||
|
||
const pacticipants = Object.entries(imageTagPairs).map(([name, version]) => ({ | ||
name, | ||
version | ||
})); | ||
|
||
const canDeployOptions = { | ||
pacticipants, | ||
pactBroker: brokerUrl || process.env.PACT_BROKER_URL, | ||
pactBrokerToken: brokerToken || process.env.PACT_BROKER_TOKEN, | ||
retryWhileUnknown: retryTimes || 5, | ||
retryInterval: retryInterval || 30 | ||
}; | ||
|
||
// console.log(!!verbose); | ||
|
||
return pact | ||
.canDeploy(canDeployOptions) | ||
.then(console.log) | ||
.catch(e => { | ||
throw e; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const path = require("path"); | ||
const { canIDeploy } = require("./canIDeploy"); | ||
|
||
jest.setTimeout(60000); | ||
describe("canIDeploy", () => { | ||
test("canIDeploy", async () => { | ||
const filePath = path.resolve( | ||
__dirname, | ||
"./__tests__/deploy-kustomization.yaml" | ||
); | ||
await canIDeploy({ | ||
kustomizeFile: filePath, | ||
retryTimes: 1, | ||
retryInterval: 10 | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require("dotenv").config(); | ||
|
||
const { getPacticipant } = require("./getPacticipant"); | ||
const _ = require("lodash"); | ||
const util = require("util"); | ||
const exec = util.promisify(require("child_process").exec); | ||
|
||
const JENKINS_USERNAME = process.env.JENKINS_USERNAME; | ||
const JENKINS_USERTOKEN = process.env.JENKINS_USERTOKEN; | ||
const JENKINS_HTTPS_URL = process.env.JENKINS_HTTPS_URL; | ||
const PACT_BROKER_TOKEN = process.env.PACT_BROKER_TOKEN; | ||
const PACT_BROKER_URL = process.env.PACT_BROKER_URL; | ||
|
||
const providerMap = { | ||
"auth-service": ["group-service"], | ||
frontend: ["gateway"], | ||
gateway: ["auth-service", "group-service"] | ||
}; | ||
|
||
async function createWebhook(consumer, provider) { | ||
const { stdout, stderr } = await exec(` | ||
pact-broker create-webhook \ | ||
${JENKINS_HTTPS_URL}/job/${provider}/job/master/buildWithParameters?PACT_VERIFY=true \ | ||
--request=POST \ | ||
--contract-content-changed \ | ||
--consumer=${getPacticipant(consumer)} \ | ||
--provider=${getPacticipant(provider)} \ | ||
--user=${JENKINS_USERNAME}:${JENKINS_USERTOKEN} \ | ||
--broker-base-url="${PACT_BROKER_URL}" \ | ||
--broker-token="${PACT_BROKER_TOKEN}" | ||
`); | ||
if (stderr) throw stderr; | ||
console.log(stdout); | ||
} | ||
|
||
(async () => { | ||
await Promise.all( | ||
_.flatten( | ||
Object.entries(providerMap).map(([consumer, providers]) => { | ||
return providers.map(p => createWebhook(consumer, p)); | ||
}) | ||
) | ||
); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const capitalize = require("capitalize"); | ||
const _ = require("lodash"); | ||
|
||
exports.getPacticipant = service => | ||
capitalize | ||
.words( | ||
_.last(service.split("/")) | ||
.split("-") | ||
.join(" ") | ||
) | ||
.split(" ") | ||
.join(""); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.