UNPKG

@vroomlabs/gsdk-deploy

Version:

Google Cloud deployment script for kubernetes clusters using Global Load Balancer

93 lines (39 loc) 4.8 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 rogerk on 7/3/17. ******************************************************************************/var confirm=function(){var _ref2=_asyncToGenerator(/*#__PURE__*/regeneratorRuntime.mark( function _callee2(prompt){var colors,yesno;return regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0: colors=require('colors'); yesno=require('yesno');if(! process.argv.find(function(arg){return arg.match(/^--?confirm/)})){_context2.next=4;break}return _context2.abrupt('return', true);case 4:_context2.next=6;return( new Promise(function(accept,reject){ prompt=colors.dim.cyan('\n'+prompt+'\nContinue [y/N]?'); yesno.ask(prompt,false,function(ok){ if(!ok)return reject(new Error('Operation cancelled.'));else accept(true); }); }));case 6:return _context2.abrupt('return',_context2.sent);case 7:case'end':return _context2.stop();}}},_callee2,this)}));return function confirm(_x2){return _ref2.apply(this,arguments)}}();var _logger=require('../util/logger');var _backendConfig=require('../config/backendConfig');var _googleLoadBalancer=require('../google/googleLoadBalancer');var _googleKubernetes=require('../google/googleKubernetes');function _asyncToGenerator(fn){return function(){var gen=fn.apply(this,arguments);return new Promise(function(resolve,reject){function step(key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{return Promise.resolve(value).then(function(value){step('next',value)},function(err){step('throw',err)})}}return step('next')})}}/** * @param {AppState} app */module.exports=function(){var _ref=_asyncToGenerator(/*#__PURE__*/regeneratorRuntime.mark(function _callee(app){var loadBalancer,googKube,clusters,names,ix,cluster,kubectl,backendConfig;return regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_logger.logger.verbose('removing deployment',{project:app.config.project,name:app.config.name});loadBalancer=new _googleLoadBalancer.GoogleLoadBalancer(app.gauth);googKube=new _googleKubernetes.GoogleKubernetes(app.gauth,app.config);// visit existing clusters and remove the service and deployment _context.next=5;return googKube.getClusters(false);case 5:clusters=_context.sent;names=Object.keys(clusters);_context.next=9;return confirm('Removing '+app.config.name+' from:\n '+names.join('\n '));case 9:ix=0;case 10:if(!(ix<names.length)){_context.next=29;break}cluster=clusters[names[ix]];_context.prev=12;_context.next=15;return googKube.getKubeController(cluster);case 15:kubectl=_context.sent;_context.next=18;return kubectl.removeService(app.config.name);case 18:_context.next=20;return kubectl.removeDeployment(app.config.name);case 20:_context.next=26;break;case 22:_context.prev=22;_context.t0=_context['catch'](12);_logger.logger.error('Unable to remove from cluster '+names[ix]);_logger.logger.verbose(_context.t0);case 26:ix++;_context.next=10;break;case 29:_context.next=31;return confirm('Removing '+app.config.current.host+' load balancer and IP Address.');case 31:// Step - configure load balancer backendConfig=new _backendConfig.BackendConfig(app.config,clusters);_context.next=34;return loadBalancer.execScript({scriptFile:app.config.current.loadBalancerTemplate,scriptName:'httpsLoadBalancer',mode:'delete'},backendConfig);case 34:case'end':return _context.stop();}}},_callee,this,[[12,22]])}));function fullDeploy(_x){return _ref.apply(this,arguments)}return fullDeploy}();