Code Block | ||
---|---|---|
| ||
"use strict";
const SOAJS_URL = process.env.SOAJS_URL;
const SOAJS_key = process.env.SOAJS_key;
const SOAJS_cd_auth = process.env.SOAJS_cd_auth;
const SOAJS_repo_auth = process.env.SOAJS_repo_auth;
const SOAJS_repo_tag = process.env.SOAJS_repo_tag;
const SOAJS_repo_commit = process.env.SOAJS_repo_commit;
const SOAJS_repo_branch = process.env.SOAJS_repo_branch;
const SOAJS_img_name = process.env.SOAJS_img_name;
const SOAJS_img_prefix = process.env.SOAJS_img_prefix;
const SOAJS_img_tag = process.env.SOAJS_img_tag;
let SOAJS_env_list;
var request = require("request");
var utils = {
"init": function (cb){
console.log("Initializing CD script");
if(!SOAJS_URL){
console.log("SOAJS_URL environment variable not found");
process.exit(0);
}
if(!SOAJS_key){
console.log("SOAJS_key environment variable not found");
process.exit(0);
}
if(!SOAJS_cd_auth){
console.log("SOAJS_cd_auth environment variable not found");
process.exit(0);
}
if (!SOAJS_repo_tag &&
(!SOAJS_repo_commit && !SOAJS_repo_branch) &&
(!SOAJS_img_name && !SOAJS_img_prefix && !SOAJS_img_tag)){
console.log("Missing CD Environment variable not found");
process.exit(0);
}
//example export SOAJS_env_list=dashboard,dev
if ( process.env.SOAJS_env_list){
try {
SOAJS_env_list= process.env.SOAJS_env_list.split(',');
}
catch (e) {
console.log("Malformed SOAJS_env_list environment variable!");
process.exit(0);
}
}
console.log("Launching CD call...");
utils.createRequest(function(params){
console.log(params.uri);
console.log(JSON.stringify(params, null, 2));
request.put(params, cb);
});
},
"createRequest": function(cb) {
var params = {};
params.uri = SOAJS_URL;
let soa;
try {
soa = require("./config.js");
}
catch (e) {
try {
soa = require("./soa.json");
}
catch (e) {
console.log("soa.json file not found, make sure the soajs.cd.js is on the same path as your soa.json");
process.exit(0);
}
}
if (soa.type === 'multi'){
console.log("Service of type multi is not supported!");
process.exit(0);
}
params.qs = {
token : SOAJS_cd_auth,
repo_token: SOAJS_repo_auth,
name: soa.serviceName || soa.name,
type: soa.type || soa.type,
version: soa.serviceVersion || soa.version,
};
params.body = {
config : {
from: {}
}
};
if (SOAJS_repo_tag){
params.body.config.from.tag = SOAJS_repo_tag;
if (SOAJS_img_tag){
params.body.config.from.image_tag = SOAJS_img_tag;
}
}
else if(SOAJS_repo_branch && SOAJS_repo_commit){
params.body.config.from.branch = SOAJS_repo_branch;
params.body.config.from.commit = SOAJS_repo_commit;
if (SOAJS_img_tag){
params.body.config.from.image_tag = SOAJS_img_tag;
}
}
else if(SOAJS_img_name && SOAJS_img_prefix && SOAJS_img_tag){
params.body.config.from.image_prefix = SOAJS_img_prefix;
params.body.config.from.image_name = SOAJS_img_name;
params.body.config.from.image_tag = SOAJS_img_tag;
}
if (SOAJS_env_list){
params.body.config.from.env = SOAJS_env_list;
}
params.headers = {
"key" : SOAJS_key,
"Content-Type": "application/json"
};
params.json = true;
return cb(params);
}
};
utils.init(function(err,response,body){
if (err) {
console.log(JSON.stringify (err, null, 2));
}
else {
console.log(JSON.stringify (body, null, 2));
}
});
|
Page Comparison
General
Content
Integrations