diff --git a/defaults.yaml b/defaults.yaml index 85a55d6f..ba88f08c 100644 --- a/defaults.yaml +++ b/defaults.yaml @@ -258,6 +258,17 @@ images: port: 80 php_log: command: 'tail -F /var/log/php/error.log' + 'proboci/ubuntu-16.04-dotnet:sdk1.0.1-nightly': + services: + cleanapache: + command: 'rm /var/run/apache2/apache2.pid' + apache: + command: '/usr/sbin/apache2ctl -D FOREGROUND' + port: 80 + redis: + command: 'redis-server' + solr: + command: 'service solr start' dataDir: './container-manager-data' # Volumes to mount into created containers. binds: [] diff --git a/lib/plugins/TaskRunner/DotnetApp.js b/lib/plugins/TaskRunner/DotnetApp.js new file mode 100644 index 00000000..2d6ea8eb --- /dev/null +++ b/lib/plugins/TaskRunner/DotnetApp.js @@ -0,0 +1,108 @@ +'use strict'; + +var Script = require('./Script'); +var constants = require('./constants'); + + +class DotnetApp extends Script { + + + /** + * Options (used by this task): + * @param {object} container - An instantiated and configured Container object. + * @param {object} options - A hash of configuration options specific to this task. + * @param {string} [options.dllName] - The name of the DLL to use. + * @param {array} [options.installPackages] - An array of additional packages to install. + * @param {array} [options.apacheMods] - An array of apache modules to enable (should be installed via installPackages if needed) + * @param {boolean} [options.restartApache] - Whether to restart Apache. If phpIniOptions, phpConstants, phpMods, or apacheMods + * are set, Apache will be restarted automatically, so you probably won't need to use this. + */ + constructor(container, options) { + + super(container, options); + + this.options.installPackages = options.installPackages || {}; + this.options.apacheMods = options.apacheMods || {}; + this.options.restartApache = options.restartApache || false; + this.options.dllName = options.dllName; + + // TODO: Add some kind of validation. + + // Filter out secret strings + options.secrets = [ + ]; + + // Allow for subdirectory to be explicitly set to "" without being overwritten for being falsy. + this.script = []; + this.addScriptApacheDotnet(); + this.setScript(this.script); + } + + description() { + return `${this.plugin} 'Provisioning Dotnet Core Application!'`; + } + + // a meta-script that installs all apache/dotnet-related scripts + addScriptApacheDotnet() { + this.addScriptDotnetCoreInit(); + this.addScriptInstallPackages(); + this.addScriptApacheMods(); + this.addScriptRestartApache(); + } + + addScriptDotnetCoreInit() { + this.script = this.script.concat('mkdir -p /var/webapp'); + this.script = this.script.concat('mkdir -p /var/www/html'); + this.script = this.script.concat('cd $SRC_DIR && dotnet restore'); + this.script = this.script.concat('cd $SRC_DIR && dotnet publish -c Release -o /var/webapp'); + this.script = this.script.concat('a2dissite 000-default'); + this.script = this.script.concat('a2ensite 000-default-dotnet'); + this.script = this.script.concat('a2enconf listen_8080'); + this.script = this.script.concat('chown -R www-data:www-data /var/webapp'); + this.script = this.script.concat('service apache2 reload'); + this.script = this.script.concat('cd $SRC_DIR && dotnet run --configuration Release'); + } + + addScriptInstallPackages() { + var packages = this.options.installPackages; + if (!this.isEmptyObject(packages)) { + var packageList = packages.join(' '); + this.script = this.script.concat('apt-get update'); + this.script = this.script.concat('apt-get install -y ' + packageList); + this.options.restartApache = true; + } + } + + addScriptApacheMods() { + var mods = this.options.apacheMods; + if (!this.isEmptyObject(mods)) { + this.script = this.script.concat(mods.map(function(mod) { + var enmod = 'a2enmod ' + mod; + return enmod; + })); + this.options.restartApache = true; + } + } + + addScriptRestartApache() { + if (this.options.restartApache) { + this.script = this.script.concat('apache2ctl graceful'); + } + } + + isEmptyObject(o) { + return !Object.keys(o).length; + } + + + sanitizeValue(val) { + if (typeof val === 'string') { + val = val.replace(/'/g, '\\\''); + val = val.replace(/"/g, '\\\"'); + val = '\'' + val + '\''; + } + return val; + } +} + +module.exports = DotnetApp; diff --git a/lib/plugins/TaskRunner/index.js b/lib/plugins/TaskRunner/index.js index 68b852e3..9f8b24b5 100644 --- a/lib/plugins/TaskRunner/index.js +++ b/lib/plugins/TaskRunner/index.js @@ -7,5 +7,6 @@ module.exports.Script = require('./Script'); module.exports.LAMPApp = require('./LAMPApp'); module.exports.WordPressApp = require('./WordPressApp'); module.exports.Drupal = require('./Drupal'); +module.exports.DotnetApp = require('./DotnetApp'); module.exports.Lighthouse = require('./Lighthouse'); module.exports.Backdrop = require('./Backdrop');