const path = require('path'); module.exports = { tags: async (tln) => [], dotenvs: async (tln) => [], env: async (tln, env) => {}, options: async (tln, args) => { args .prefix('TLN_SONARQUBE') .option('image', { describe: 'Sonarqube image version', default: 'sonarqube:6.7.7-community', type: 'string' }) .option('db-version', { describe: 'Database version', default: 'mysql:5.7', type: 'string' }) .option('db-name', { describe: 'Database name', default: 'sonar', type: 'string' }) .option('db-root-pass', { describe: 'Database root password', default: null, type: 'string' }) .option('db-user', { describe: 'Database sonar user', default: 'sonar', type: 'string' }) .option('db-pass', { describe: 'Database sonar user password', default: null, type: 'string' }) .option('lang', { describe: 'Language for sonar.properties', default: null, type: 'string' }); }, inherits: async (tln) => [], depends: async (tln) => [], steps: async (tln) => [ { id: 'prereq', filter: 'linux', desc: '', builder: async (tln, script) => { script.set([ ]) } }, { id: 'install', filter: 'linux', desc: 'Install Sonarqube server', builder: ['generate-compose', 'up'] }, { id: 'generate-compose', filter: 'linux', desc: 'Generate docker-compose file for SonarQube server', builder: async (tln, script) => { if (script.env.TLN_SONARQUBE_DB_ROOT_PASS && script.env.TLN_SONARQUBE_DB_PASS) { const home = script.env.TLN_COMPONENT_HOME; const src = path.join(__dirname, 'docker-compose.yml.template'); const dest = path.join(home, 'docker-compose.yml'); script.set([ /* TODO: support sonar 7.9 without mysql `sysctl -w vm.max_map_count=262144`, `sysctl -w fs.file-max=65536`, `ulimit -n 65536`, `ulimit -u 4096`, */ `envsubst < "${src}" > "${dest}"`, ]) } else { script.logger.error('Please define both --db-root-pass and --db-pass options'); } } }, { id: 'up', filter: 'linux', desc: 'Run SonarQube server', builder: async (tln, script) => { script.set([ `docker-compose up -d` ]) } }, { id: 'down', filter: 'linux', desc: 'Down SonarQube server', builder: async (tln, script) => { script.set([ `docker-compose down --rmi all` ]) } }, { id: 'generate-properties', filter: '', builder: async (tln, script) => { const langs = ['cpp', 'java', 'js', 'golang', 'python', 'php', 'ts']; const home = script.env.TLN_COMPONENT_HOME; const lang = script.env.TLN_SONARQUBE_LANG; if (langs && langs.indexOf(lang) != -1) { tln.copyTemplate( tln, script, path.join(__dirname, 'sonar-project.properties.template'), path.join(home, 'sonar-project.properties.template'), [path.join(__dirname, `${lang}.template`)] ); } else { script.logger.error(`Please define language via --lang option: tln generate-properties@sonarqube -- --lang=[${langs.join(' | ')}]`); } } } ], components: async (tln) => [] }