diff --git a/__tests__/deploy-kustomization.yaml b/__tests__/deploy-kustomization.yaml index abda8c8..2c71969 100644 --- a/__tests__/deploy-kustomization.yaml +++ b/__tests__/deploy-kustomization.yaml @@ -5,10 +5,10 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization images: - name: gcr.io/kollate-218719/auth-service - newTag: 4284bc991c815591eddaf6034d0dfc171fdfa77d + newTag: latest - name: gcr.io/kollate-218719/frontend - newTag: 27c177e79511aa74a43a5dd319274910c8a3cc1d + newTag: latest - name: gcr.io/kollate-218719/gateway - newTag: a4349c2c93535f9db51e73e701f6aadb229e8ac3 + newTag: latest - name: gcr.io/kollate-218719/group-service - newTag: d45454cab2ff92c6e60e7af731639fbbfc3f79d9 + newTag: latest diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 2bf2489..6bf0f0c 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -1,6 +1,7 @@ const yargs = require("yargs"); const loadImages = require("../loadImages"); const getImageTag = require("../getImageTag"); +const { getImages } = require("../getImages"); // const temp = require("../temp"); // test("temp", done => { @@ -11,32 +12,32 @@ const getImageTag = require("../getImageTag"); // }); // }); -describe("load images", () => { - jest.setTimeout(60 * 1000); - test("Load all Images", async done => { - try { - loadImages({ - yamlFile: __dirname + "/kustomization.yaml", - cb: done - }); - } catch (e) { - console.log(e); - throw e; - } - }); - test("Load images with skip", async done => { - try { - loadImages({ - yamlFile: __dirname + "/kustomization.yaml", - cb: done, - skipImage: "hashicorp/http-echo" - }); - } catch (e) { - console.log(e); - throw e; - } - }); -}); +// describe("load images", () => { +// jest.setTimeout(60 * 1000); +// test("Load all Images", async done => { +// try { +// loadImages({ +// yamlFile: __dirname + "/kustomization.yaml", +// cb: done +// }); +// } catch (e) { +// console.log(e); +// throw e; +// } +// }); +// test("Load images with skip", async done => { +// try { +// loadImages({ +// yamlFile: __dirname + "/kustomization.yaml", +// cb: done, +// skipImage: "hashicorp/http-echo" +// }); +// } catch (e) { +// console.log(e); +// throw e; +// } +// }); +// }); // describe("loadImages parser", () => { // test("loadImages file", async done => { diff --git a/canIDeploy.test.ts b/canIDeploy.test.js similarity index 100% rename from canIDeploy.test.ts rename to canIDeploy.test.js diff --git a/createHooks.js b/createHooks.js index 50dff72..bb6b1fb 100644 --- a/createHooks.js +++ b/createHooks.js @@ -13,8 +13,9 @@ const PACT_BROKER_URL = process.env.PACT_BROKER_URL; const JENKINS_CRUMB = process.env.JENKINS_CRUMB; const providerMap = { - "auth-service": ["group-service"], - frontend: ["auth-service", "group-service", "file-service"] + "auth-service": ["group-service", "email-service"], + frontend: ["auth-service", "group-service", "file-service"], + "email-service": ["group-service"] // gateway: ["auth-service", "group-service"] }; diff --git a/createHooks.sh b/createHooks.sh new file mode 100755 index 0000000..109de62 --- /dev/null +++ b/createHooks.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +pact-broker create-webhook \ + $JENKINS_HTTPS_URL/job/gateway/job/master/buildWithParameters?PACT_VERIFY=true \ + --request=POST \ + --contract-content-changed \ + --consumer=AuthService \ + --provider=Gateway \ + --user=$JENKINS_USERNAME:$JENKINS_USERTOKEN \ + --broker-base-url=$PACT_BROKER_URL \ + --broker-token=$PACT_BROKER_TOKEN +# declare PROVIDER_JOB_MAP=(\ +# ["GroupService"]="group-service" \ +# ["AuthService"]="auth-service" +# ) +# consumer=AuthService +# providers=(GroupService AuthService) + +# for provider in ${providers[@]}; do +# echo $provider +# echo "${PROVIDER_JOB_MAP[provider]}"x +# done; +# for provider in ${providers[@]}; do +# pact-broker create-webhook \ +# $JENKINS_HTTPS_URL/job/test/buildWithParameters?PACT_VERIFY=true \ +# --request=POST \ +# --contract-content-changed \ +# --consumer=$consumer \ +# --provider=$provider \ +# --user=$JENKINS_USERNAME:$JENKINS_USERTOKEN \ +# --broker-base-url=$PACT_BROKER_URL \ +# --broker-token=$PACT_BROKER_TOKEN +# done; diff --git a/getImages.js b/getImages.js new file mode 100644 index 0000000..09d4654 --- /dev/null +++ b/getImages.js @@ -0,0 +1,9 @@ +const path = require("path"); +const fs = require("fs"); +const yaml = require("js-yaml"); + +exports.getImages = function(yamlFile) { + const doc = yaml.safeLoad(fs.readFileSync(path.resolve(yamlFile), "utf8")); + const images = doc.images.map(a => `${a.name}:${a.newTag}`); + return images.join(" "); +}; diff --git a/getImages.test.js b/getImages.test.js new file mode 100644 index 0000000..2934f12 --- /dev/null +++ b/getImages.test.js @@ -0,0 +1,12 @@ +const path = require("path"); + +const { getImages } = require("./getImages"); + +describe("getImages", () => { + test("getImages works", () => { + const r = getImages( + path.resolve(__dirname + "/__tests__/kustomization.yaml") + ); + expect(r).toMatchInlineSnapshot(`"alpine:3.7 hashicorp/http-echo:0.2.3"`); + }); +}); diff --git a/index.js b/index.js index c08560c..20a4b16 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ const yargs = require("yargs"); const loadImages = require("./loadImages"); const getImageTag = require("./getImageTag"); +const { getImages } = require("./getImages"); const { canIDeploy } = require("./canIDeploy"); // const temp = require("./temp"); @@ -43,6 +44,16 @@ yargs ); } ) + .command( + "getImages ", + "get all the images with tags in kustomize yaml file", + yargs => { + return yargs; + }, + argv => { + console.log(getImages(argv.filepath)); + } + ) .command( "canIDeploy ", "Check if the pacticipants in the kustomization file with tags pass the deployment test", diff --git a/jest.config.js b/jest.config.js index 2c1aa90..077934f 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,6 @@ module.exports = { + testEnvironment: "node", + moduleFileExtensions: ["js"], watchPlugins: [ "jest-watch-typeahead/filename", "jest-watch-typeahead/testname" diff --git a/package-lock.json b/package-lock.json index 7299930..6279149 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4709,6 +4709,12 @@ "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=" }, + "prettier": { + "version": "1.19.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", + "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "dev": true + }, "pretty-format": { "version": "25.1.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-25.1.0.tgz", diff --git a/package.json b/package.json index 8be129b..6377462 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,11 @@ "main": "index.js", "bin": "index.js", "scripts": { - "pretest": "KUBECONFIG=./config.yaml kind create cluster", - "test": "jest || :", + "test:kind": "", + "pretest:kind": "KUBECONFIG=./config.yaml kind create cluster", + "test": "jest", "test:watch": "jest --watch || :", - "posttest": "rm ./config.yaml && KUBECONFIG=./config.yaml kind delete cluster", + "posttest:kind": "rm ./config.yaml && KUBECONFIG=./config.yaml kind delete cluster", "package": "pkg -t node10-macos-x64,node10-linux-x64 -o=packages/utils ." }, "pkg": { @@ -34,6 +35,7 @@ "eslint": "^6.8.0", "jest": "^25.1.0", "jest-watch-typeahead": "^0.4.2", + "prettier": "^1.19.1", "uuid": "^3.4.0" } } diff --git a/packages/utils-linux b/packages/utils-linux index 29d1110..5477c3f 100755 Binary files a/packages/utils-linux and b/packages/utils-linux differ diff --git a/packages/utils-macos b/packages/utils-macos index d468ab6..c522c04 100755 Binary files a/packages/utils-macos and b/packages/utils-macos differ diff --git a/readme.md b/readme.md index 23bac1d..82fa472 100644 --- a/readme.md +++ b/readme.md @@ -32,5 +32,5 @@ pact-broker create-webhook http://myjenkins:8080/job/auth-service/job/master/bui pact-broker create-webhook \ http://myjenkins:8080/job/test/buildWithParameters?PACT_VERIFY=true \ --request=POST --contract-content-changed \ ---provider=AuthService --user=surajkeshri:11d68c6558003716571dd8f4a9b544b76b \ +--provider=AuthService --user=surajkeshri:password \ --broker-base-url=$PACT_BROKER_URL --broker-token=$PACT_BROKER_TOKEN