@vroomlabs/gsdk-deploy
Version:
Google Cloud deployment script for kubernetes clusters using Global Load Balancer
75 lines (59 loc) • 4.36 kB
JavaScript
;
/******************************************************************************
* 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 _logger=require('../util/logger');
var _googleDockerRepo=require('../google/googleDockerRepo');
var _googleSvcManager=require('../google/googleSvcManager');
var _backendConfig=require('../config/backendConfig');
var _googleNetworking=require('../google/googleNetworking');
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 repo,endpoints,dockerImage,endpointInfo,networking,loadBalancer,googKube,clusters,backendConfig;return regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:
_logger.logger.verbose('starting full deployment',{project:app.config.project,name:app.config.name});
repo=new _googleDockerRepo.GoogleDockerRepo(app.gauth);
endpoints=new _googleSvcManager.GoogleSvcManager(app.gauth);
dockerImage=void 0,endpointInfo=void 0;
// push docker images & endpoint
if(app.args.image){_context.next=14;break}
_logger.logger.warn('Skipping docker/api push...');_context.next=8;return(
repo.getLatestImage(app.config.name,app.args.branch));case 8:dockerImage=_context.sent;_context.next=11;return(
endpoints.getLatestEndpoint(app.config.getApiFiles()));case 11:endpointInfo=_context.sent;_context.next=20;break;case 14:_context.next=16;return(
repo.pushLocalImage(app.args.image,app.config.name,app.args.branch,app.config.getDockerTagFormat()));case 16:dockerImage=_context.sent;_context.next=19;return(
endpoints.deployEndpoint(app.config.getApiFiles()));case 19:endpointInfo=_context.sent;case 20:
networking=new _googleNetworking.GoogleNetworking(app.gauth);
loadBalancer=new _googleLoadBalancer.GoogleLoadBalancer(app.gauth);
googKube=new _googleKubernetes.GoogleKubernetes(app.gauth,app.config);
// Step - create environment
_context.next=25;return networking.getNetwork(app.config.current.network,true);case 25:_context.next=27;return(
googKube.getClusters(true));case 27:clusters=_context.sent;_context.next=30;return(
googKube.deployAll(app.config.name,dockerImage,endpointInfo,clusters));case 30:
// Step - configure load balancer
backendConfig=new _backendConfig.BackendConfig(app.config,clusters);_context.next=33;return(
loadBalancer.execScript({
scriptFile:app.config.current.loadBalancerTemplate,
scriptName:'httpsLoadBalancer',
mode:'create'},
backendConfig));case 33:case'end':return _context.stop();}}},_callee,this)}));function fullDeploy(_x){return _ref.apply(this,arguments)}return fullDeploy}();