<commit_before>var mkdir = require('mkdirp');
var rm = require('rimraf');
var Git = require('git-wrapper');
var path = require('path');
var fs = require('fs');
var log = require('lib/debug')('manager:deis-api:build');

function dockerfile(image){
  return [
    'FROM ' + image,
    'MAINTAINER <NAME> <<EMAIL>>',
    'EXPOSE 80',
    'CMD [ "node", "index.js" ]',
  ].join('\n');
}

var baseDir = '.tmp/deis-builds';

module.exports = function(data, fn){
  var folder = path.resolve('.', baseDir, data.app);
  var remote = 'ssh://git@' + data.controller + ':2222/' + data.app + '.git';

  log('Building Deis app \'%s\'.', data.app);

  mkdir(folder, function (err) {
    if (err) return log('Found error: ', err), fn(err || 'Error.');
    log('Created directory of repo for \'%s\'.', data.app);

    var git = new Git({
      'C': folder
    });

    git.exec('init', function(err){
      if (err) return log('Found error: ', err), fn(err || 'Error.');
      log('Inited deis repo for \'%s\'.', data.app);

      fs.writeFile(path.join(folder, 'Dockerfile'), dockerfile(data.image), function(err){
        if (err) return log('Found error: ', err), fn(err || 'Error.');
        log('Dockerfile created for \'%s\'.', data.app);

        git.exec('remote', ['add', 'deis', remote], function(err){
          if (err) return log('Found error: ', err), fn(err || 'Error.');
          log('Git remote added on \'%s\'.', data.app);

          git.exec('add', { all: true }, [], function(err){
            if (err) return log('Found error: ', err), fn(err || 'Error.');
            log('Git add --all on \'%s\'.', data.app);

            git.exec('commit', { a: true, m: true }, ['"Democratization time!"'], function(err){
              if (err) return log('Found error: ', err), fn(err || 'Error.');
              log('Files commited for \'%s\'.', data.app);

              git.exec('push', { force: true }, ['deis', 'master'], function(err){
                if (err) return log('Found error: ', err), fn(err || 'Error.');
                log('Repo pushed \'%s\'.', data.app);

                rm(folder, function(err){
                  if (err) return log('Found error: ', err), fn(err || 'Error.');
                  log('Directory deleted \'%s\'.', folder);
                  fn(null);
                })
              })
            })
          })
        })
      })
    })
  })
}
<commit_msg>Update dockerfile template 'CMD' instruction<commit_after>var mkdir = require('mkdirp');
var rm = require('rimraf');
var Git = require('git-wrapper');
var path = require('path');
var fs = require('fs');
var log = require('lib/debug')('manager:deis-api:build');

function dockerfile(image){
  return [
    'FROM ' + image,
    'MAINTAINER <NAME> <<EMAIL>>',
    'EXPOSE 80',
    'CMD node ./bin/dos-config && node index.js',
  ].join('\n');
}

var baseDir = '.tmp/deis-builds';

module.exports = function(data, fn){
  var folder = path.resolve('.', baseDir, data.app);
  var remote = 'ssh://git@' + data.controller + ':2222/' + data.app + '.git';

  log('Building Deis app \'%s\'.', data.app);

  mkdir(folder, function (err) {
    if (err) return log('Found error: ', err), fn(err || 'Error.');
    log('Created directory of repo for \'%s\'.', data.app);

    var git = new Git({
      'C': folder
    });

    git.exec('init', function(err){
      if (err) return log('Found error: ', err), fn(err || 'Error.');
      log('Inited deis repo for \'%s\'.', data.app);

      fs.writeFile(path.join(folder, 'Dockerfile'), dockerfile(data.image), function(err){
        if (err) return log('Found error: ', err), fn(err || 'Error.');
        log('Dockerfile created for \'%s\'.', data.app);

        git.exec('remote', ['add', 'deis', remote], function(err){
          if (err) return log('Found error: ', err), fn(err || 'Error.');
          log('Git remote added on \'%s\'.', data.app);

          git.exec('add', { all: true }, [], function(err){
            if (err) return log('Found error: ', err), fn(err || 'Error.');
            log('Git add --all on \'%s\'.', data.app);

            git.exec('commit', { a: true, m: true }, ['"Democratization time!"'], function(err){
              if (err) return log('Found error: ', err), fn(err || 'Error.');
              log('Files commited for \'%s\'.', data.app);

              git.exec('push', { force: true }, ['deis', 'master'], function(err){
                if (err) return log('Found error: ', err), fn(err || 'Error.');
                log('Repo pushed \'%s\'.', data.app);

                rm(folder, function(err){
                  if (err) return log('Found error: ', err), fn(err || 'Error.');
                  log('Directory deleted \'%s\'.', folder);
                  fn(null);
                })
              })
            })
          })
        })
      })
    })
  })
}

{'fraction_non_alphanumeric': 0.21695966907962771, 'fraction_numerical': 0.002481902792140641, 'mean_word_length': 2.330578512396694, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6848259', 'n_tokens_mistral': 1594, 'n_tokens_neox': 1509, 'n_words': 412}