UNPKG

@vroomlabs/gsdk-deploy

Version:

Google Cloud deployment script for kubernetes clusters using Global Load Balancer

89 lines (78 loc) 4.13 kB
'use strict'; /****************************************************************************** * MIT License * Copyright (c) 2017 https://github.com/vroomlabs * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Created by vroomlabs on 7/2/17. ******************************************************************************/Object.defineProperty(exports,'__esModule',{value:true});exports.Arguments=undefined;var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if('value'in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}(); var _path=require('path');var path=_interopRequireWildcard(_path); var _artifacts=require('../util/artifacts'); var _templateArg=require('../util/templateArg');function _interopRequireWildcard(obj){if(obj&&obj.__esModule){return obj}else{var newObj={};if(obj!=null){for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key))newObj[key]=obj[key]}}newObj.default=obj;return newObj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}var Arguments=exports.Arguments=function(){ function Arguments(){_classCallCheck(this,Arguments); this.command=''; this.branch=''; this.artifacts=''; this.image='user/build'; this.authEnv=null;// parsed as auth-env this.authFile=null;// parsed as auth-file this.config='./deploy.yaml'; this.baseDir=process.cwd();// parsed as base-dir // TOOLS: this.gcloud='gcloud'; if(Arguments.isCircleCI()){ this.gcloud='sudo /opt/google-cloud-sdk/bin/gcloud'; } this.gcloud=process.env.GCLOUD_COMMAND||this.gcloud; this.autoUpgrade=process.env.AUTO_UPDATE_SDK==='true'||Arguments.isCircleCI(); } /** * @param {string[]} params */_createClass(Arguments,[{key:'parse',value:function parse( params){var _this=this; for(var ix=0;ix<params.length;ix++){ var param=params[ix]; var m=param.match(/^--?([?\w_-]+)([:=](.*))?$/); if(m){ var name=m[1].toLowerCase(); var val=m[3]; while(m=name.match(/-(\w)/)){ name=name.replace(/-\w/g,m[1].toUpperCase()); } this[name]=val; }else { if(this.command){ throw new Error('Unable to process both commands: '+this.command+' and '+param); } this.command=param.toLowerCase(); } } Object.keys(this).forEach(function(k){ _this[k]=typeof _this[k]!=='string'?_this[k]:(0,_templateArg.replaceInText)(_this[k]); }); this.config=path.resolve(this.baseDir,this.config); this.artifacts=(0,_artifacts.getArtifactsFolder)(); process.env.BRANCH=this.branch; process.env.ARTIFACTS=this.artifacts; process.env.BUILD_TIME=new Date().toISOString().replace(/[^\w]+/gi,'-').replace(/^-|-$/g,''); }}],[{key:'isCircleCI',value:function isCircleCI() { return(process.env.CIRCLECI||process.env.CI)==='true'; }}]);return Arguments}();