Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
suraj-keshri committed Mar 5, 2020
1 parent b9206c7 commit bedd4f0
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 36 deletions.
8 changes: 4 additions & 4 deletions __tests__/deploy-kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
53 changes: 27 additions & 26 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -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 => {
Expand All @@ -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 => {
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions createHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
};

Expand Down
33 changes: 33 additions & 0 deletions createHooks.sh
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 9 additions & 0 deletions getImages.js
Original file line number Diff line number Diff line change
@@ -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(" ");
};
12 changes: 12 additions & 0 deletions getImages.test.js
Original file line number Diff line number Diff line change
@@ -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"`);
});
});
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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");

Expand Down Expand Up @@ -43,6 +44,16 @@ yargs
);
}
)
.command(
"getImages <filepath>",
"get all the images with tags in kustomize yaml file",
yargs => {
return yargs;
},
argv => {
console.log(getImages(argv.filepath));
}
)
.command(
"canIDeploy <filepath>",
"Check if the pacticipants in the kustomization file with tags pass the deployment test",
Expand Down
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
testEnvironment: "node",
moduleFileExtensions: ["js"],
watchPlugins: [
"jest-watch-typeahead/filename",
"jest-watch-typeahead/testname"
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bedd4f0

Please sign in to comment.