<commit_before>
'use strict';

var findImage = require('./docker').findImage;
var toTargetIp = require('nscale-target-ip');
var exitError = require('exit-error');
var spawnCommand = require('spawn-command');
var pipeChildStdioToOut = require('./pipe-child-stdio-to-out');

module.exports = function(config, logger) {

  var execute = function(cmd, out, cb) {
    var child = spawnCommand(cmd);
    pipeChildStdioToOut(child, out);
    child.on('exit', function(code, signal) {
      cb(exitError(cmd, code, signal));
    });
  };

  /**
   * build the container
   * system - the system definition
   * cdef - contianer definition block
   * out - ouput stream
   * cb - complete callback
   */
  var build = function build(mode, system, containerDef, out, cb) {
    var name = containerDef.specific.name;

    if (!name) {
      return cb(new Error('missing name for definition ' + containerDef.id));
    }

    if (!containerDef.specific.execute) {
      return cb(new Error('missing execute block in ' + containerDef.id + ' container definition'));
    }

    var pullCmd = 'docker pull ' + name;
    var tag = system.name + '/' + containerDef.id;
    var tagCmd = 'docker tag ' + name + ' ' + tag;

    execute(pullCmd, out, function(err) {
      if (err) {
        return cb(err);
      }

      execute(tagCmd, out, function(err) {

        if (err) {
          return cb(err);
        }

        findImage(tag, function(err, image) {
          if (err) {
            return cb(err);
          }

          var containerBinaryPath = system.repoPath + '/builds/' + image.Id;
          var exportCmd = 'docker save ' + image.Id + ' > ' + containerBinaryPath;
          execute(exportCmd, out, function(err) {
            if (err) {
              return cb(err);
            }<commit_msg>Export the registry images with their tag.<commit_after>
'use strict';

var findImage = require('./docker').findImage;
var toTargetIp = require('nscale-target-ip');
var exitError = require('exit-error');
var spawnCommand = require('spawn-command');
var pipeChildStdioToOut = require('./pipe-child-stdio-to-out');

module.exports = function(config, logger) {

  var execute = function(cmd, out, cb) {
    var child = spawnCommand(cmd);
    pipeChildStdioToOut(child, out);
    child.on('exit', function(code, signal) {
      cb(exitError(cmd, code, signal));
    });
  };

  /**
   * build the container
   * system - the system definition
   * cdef - contianer definition block
   * out - ouput stream
   * cb - complete callback
   */
  var build = function build(mode, system, containerDef, out, cb) {
    var name = containerDef.specific.name;

    if (!name) {
      return cb(new Error('missing name for definition ' + containerDef.id));
    }

    if (!containerDef.specific.execute) {
      return cb(new Error('missing execute block in ' + containerDef.id + ' container definition'));
    }

    var pullCmd = 'docker pull ' + name;
    var tag = system.name + '/' + containerDef.id;
    var tagCmd = 'docker tag ' + name + ' ' + tag;

    execute(pullCmd, out, function(err) {
      if (err) {
        return cb(err);
      }

      execute(tagCmd, out, function(err) {

        if (err) {
          return cb(err);
        }

        findImage(tag, function(err, image) {
          if (err) {
            return cb(err);
          }

          var containerBinaryPath = system.repoPath + '/builds/' + image.Id;
          var exportCmd = 'docker save ' + tag + ' > ' + containerBinaryPath;
          execute(exportCmd, out, function(err) {
            if (err) {
              return cb(err);
            }
{'fraction_non_alphanumeric': 0.13588463671658346, 'fraction_numerical': 0.0, 'mean_word_length': 2.4783027965284474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6777508', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1065, 'n_words': 284}