UNPKG

tooltwist

Version:
206 lines (174 loc) 6.97 kB
var Config = null, Log = null, Gradle = null, Templates = null, fs = require('fs'), mkdirp = require('mkdirp'); /** * Set up the plugin */ exports.init = function(appDir) { //console.log('plugins.deploy.init()') // Run requires, based on main app directory (i.e. not relative to the plugin) Log = require(appDir + '../../lib/log'); Config = require(appDir + '../../lib/config'); Templates = require(appDir + '../../lib/templates'), Gradle = require(appDir + '../../lib/gradle'); //ZZZZZ Check Docker is installed } /** * Create a default config file for the Designer. */ exports.commandLineInit = function() { Log.debug('plugins.deploy.commandLineInit()') } exports.beforePhase1 = function() { Log.debug('deploy.beforePhase1()') var config = Config.getConfig(); // DESIGNER MODE Config.REPO = config['designer'].repo; //ZZZ check is set Config.BRANCH = config['designer'].branch; // ZZZ check works if undefined } exports.tomcatRunning = function() { Log.debug('plugins.deploy.tomcatRunning()') // Display a nice message for Designer users. //Log.log(); Log.log(' (Server can be stopped with Control-C)'); Log.log(); Log.log(); Log.log(); Log.log('\t\t THE SERVER IS NOW RUNNING.') Log.log(); Log.log('\t\t http://localhost:' + Config.HTTP_PORT + '/ttsvr/login'); Log.log(); Log.log(); Log.log(); //Log.log(' Default log file is ' + Config.HIDDEN_DIR + '/tooltwist.log') } /** * This function is called after generating the default build files from * templates, but before starting Phase 2. Note that phase 2 occurs WITHIN * phase 1, so afterPhase1() has not been called yet. */ exports.beforePhase2 = function() { Log.debug("plugins.deploy.beforePhase2"); // Set a few extra variables var config = Config.getConfig(); if ( !config['deploy']) { Log.error() Log.error('Error: ' + Config.CONFIG_FILE + ' does not have config.deploy section.'); Log.error() process.exit(1) } if (config['deploy'].servers.length < 1) { Log.error() Log.error('Error: ' + Config.CONFIG_FILE + ' does not have config.deploy.servers array.'); Log.error() process.exit(1) } if ( !config['deploy'].servers[0].host) { Log.error() Log.error('Error: ' + Config.CONFIG_FILE + ' does not define config.deploy.servers[0].host'); Log.error() process.exit(1) } if ( !config['deploy'].servers[0].id) { Log.error() Log.error('Error: ' + Config.CONFIG_FILE + ' does not define config.deploy.servers[0].id'); Log.error() process.exit(1) } if ( !config['deploy'].servers[0].sshUser) { Log.error() Log.error('Error: ' + Config.CONFIG_FILE + ' does not define config.deploy.servers[0].sshUser'); Log.error() process.exit(1) } if ( !config['deploy'].servers[0].sshPort) { Log.error() Log.error('Error: ' + Config.CONFIG_FILE + ' does not define config.deploy.servers[0].sshPort'); Log.error() process.exit(1) } if ( !config['deploy'].servers[0].serverHome) { Log.error() Log.error('Error: ' + Config.CONFIG_FILE + ' does not define config.deploy.servers[0].serverHome'); Log.error() process.exit(1) } if ( !config['deploy'].servers[0].fipPort) { Log.error() Log.error('Error: ' + Config.CONFIG_FILE + ' does not define config.deploy.servers[0].fipPort'); Log.error() process.exit(1) } if ( !config['deploy'].servers[0].httpPort) { Log.error() Log.error('Error: ' + Config.CONFIG_FILE + ' does not define config.deploy.servers[0].httpPort'); Log.error() process.exit(1) } config.HOST = config['deploy'].servers[0].host; // config.CONTAINER_NAME = config['deploy'].servers[0].id; config.SSH_USER = config['deploy'].servers[0].sshUser; config.SSH_PORT = config['deploy'].servers[0].sshPort; config.SERVER_HOME = config['deploy'].servers[0].serverHome; config.FIP_PORT = config['deploy'].servers[0].fipPort; config.HTTP_PORT = config['deploy'].servers[0].httpPort; Log.info('HOST=' + config.HOST); Log.info('CONTAINER_NAME=' + config.CONTAINER_NAME); Log.info('SSH_USER=' + config.SSH_USER); Log.info('SSH_PORT=' + config.SSH_PORT); Log.info('SERVER_HOME=' + config.SERVER_HOME); Log.info('FIP_PORT=' + config.FIP_PORT); Log.info('HTTP_PORT=' + config.HTTP_PORT); /* * Generate files for PHASE2 (Grunt), Docker, and installing. */ var templateDir = __dirname + '/templates'; // PHASE2 (generate, build docker, install, etc) mkdirp.sync(Config.HIDDEN_DIR + '/PHASE2'); Templates.copyTemplate(templateDir, 'deploy-PHASE2-DOIT', 'PHASE2/DOIT', Config.getConfig()) fs.chmodSync(Config.HIDDEN_DIR+'/PHASE2/DOIT', '744'); Templates.copyTemplate(templateDir, 'deploy-PHASE2-package.json', 'PHASE2/package.json', Config.getConfig()) Templates.copyTemplate(templateDir, 'deploy-PHASE2-Gruntfile.js', 'PHASE2/Gruntfile.js', Config.getConfig()) // var to = Config.BUILD_DIR + '/gradlew'; // Install stuff mkdirp.sync(Config.HIDDEN_DIR + '/do_install'); Templates.copyTemplate(templateDir, 'deploy-install-DOIT', 'do_install/DOIT', Config.getConfig()) fs.chmodSync(Config.HIDDEN_DIR+'/do_install/DOIT', '744'); Templates.copyTemplate(templateDir, 'deploy-install-pair.sh', 'do_install/pair.sh', Config.getConfig()) fs.chmodSync(Config.HIDDEN_DIR+'/do_install/pair.sh', '744'); Templates.copyTemplate(templateDir, 'deploy-install-build.gradle', 'do_install/build.gradle', Config.getConfig()) Templates.copyTemplate(templateDir, 'deploy-install-rules', 'do_install/rules', Config.getConfig()) // Save the configuration as JSON into the install directory, for use by InstallerUtil. var configJson = JSON.stringify(Config.getConfig(), null, 2); fs.writeFileSync(Config.HIDDEN_DIR + '/do_install/tooltwistJsAsJson.json', configJson) // Check we have the gradle wrapper. This is a standard Gradle // script that installs gradle if it not already installed. Gradle.checkGradleWrapper(Config.HIDDEN_DIR + '/do_install'); // Ensure that required directories exist mkdirp.sync(Config.HIDDEN_DIR + '/do_generate/work'); mkdirp.sync(Config.HIDDEN_DIR + '/do_generate/logs'); mkdirp.sync(Config.HIDDEN_DIR + '/image'); mkdirp.sync(Config.HIDDEN_DIR + '/image/webdesign-projects/config'); fs.writeFileSync(Config.HIDDEN_DIR + '/image/webdesign-projects/config/_empty', '') } exports.afterPhase2 = function() { Log.debug("plugins.deploy.afterPhase2"); // Create Dockerfile //ZZZZ } exports.afterPhase1 = function() { Log.debug('plugins.deploy.afterPhase1()') } exports.createExampleTemplates = function() { Log.debug('\nplugins.docker.createExampleTemplates()') var templateDir = __dirname + '/templates'; Templates.copyExampleTemplate(templateDir, 'PHASE2/'+Config.mode+'-Gruntfile.js'); Templates.copyExampleTemplate(templateDir, 'PHASE2/'+Config.mode+'-package.json'); // Templates.copyTemplate(templateDir, 'docker-PHASE2-package.json', 'PHASE2/package.json', Config.getConfig()) // Templates.copyTemplate(templateDir, 'docker-PHASE2-Gruntfile.js', 'PHASE2/Gruntfile.js', Config.getConfig()) }