Example #1
0
 clean() {
   var path = this.manifest.cache_dir;
   if (fs.existsSync(path)) {
     this.__cache = null;
     return fs.removeSync(path);
   }
 }
Example #2
0
File: init.js Project: awlka/azk
    return async(this, function* () {
      var manifest = config("manifest");
      var cwd  = opts.path || this.cwd;
      var file = path.join(cwd, manifest);
      var generator = new Generator(this);

      if (fs.existsSync(file) && !opts.force) {
        this.fail(this.tKeyPath("already"), manifest);
        return 1;
      }

      var systems = generator.findSystems(cwd);
      if (_.isEmpty(systems)) {
        this.fail(this.tKeyPath("not_found"));
        systems = { [example_system.name]: example_system };
      }

      generator.render({ systems }, file);
      this.ok(this.tKeyPath('generated'), manifest);

      // Only show tips if is a git dir
      if (fs.existsSync(path.join(cwd, ".git")))
        this.tOutput(this.tKeyPath('github'));

      return 0;
    });
Example #3
0
  action(opts) {
    if (opts.filename) {
      return this.showFilename();
    }

    var manifest = config("manifest");
    var cwd  = opts.path || this.cwd;
    var file = path.join(cwd, manifest);
    var generator = new lazy.Generator(this);

    if (fs.existsSync(file) && !opts.force) {
      this.fail(this.tKeyPath("already_exists"), manifest);
      return 1;
    }

    var systemsData = generator.findSystems(cwd);
    log.debug('generator.findSystems(\'%s\')', cwd);

    if (_.isEmpty(systemsData)) {
      this.fail(this.tKeyPath("not_found"));
      systemsData = { [lazy.example_system.name]: lazy.example_system };
    }

    generator.render({ systems: systemsData }, file);
    this.ok(this.tKeyPath('generated'), manifest);

    // Only show tips if is a git dir
    if (fs.existsSync(path.join(cwd, ".git"))) {
      this.tOutput(this.tKeyPath('github'));
    }

    return 0;
  }
Example #4
0
  _findDockerfile(dockerfile_path) {
    var msg;

    if (this.system.hasOwnProperty('manifest') && this.system.manifest.cwd) {
      var dockerfile_cwd = path.resolve(this.system.manifest.cwd, dockerfile_path);
      // FIXME: to change this `Sync` codes we have to change system and image contructors
      // there is no way to call promises on contructors
      // new system -> new image -> set path -> _findDockerfile -> sync calls
      var exists = fs.existsSync(dockerfile_cwd);

      if (exists) {
        var stats = fs.statSync(dockerfile_cwd);
        var isDirectory = stats.isDirectory();

        if (isDirectory) {
          // it is a folder - try find the manifest
          dockerfile_cwd = path.join(dockerfile_cwd, 'Dockerfile');
          exists = fs.existsSync(dockerfile_cwd);

          if (!exists) {
            var translate_options = { system: this.system.name, dockerfile: dockerfile_path };
            msg = t("manifest.cannot_find_dockerfile", translate_options);
            throw new ManifestError('', msg);
          }
        }

        return dockerfile_cwd;
      }
      msg = t("manifest.cannot_find_dockerfile_path", { system: this.system.name, dockerfile: dockerfile_path });
      throw new ManifestError('', msg);
    } else {
      msg = t("manifest.required_path");
      throw new Error(msg);
    }
  }
Example #5
0
File: pid.js Project: awlka/azk
  constructor(file) {
    this.file = file;
    this.pid  = null;

    if (fs.existsSync(file)) {
      this.pid = parseInt(fs.readFileSync(file).toString());
    }
  }
Example #6
0
 }).then(() => {
   // -------
   // package.json
   // -------
   var apiFolder = path.join(rootFullPath, 'api');
   fs.mkdirSync(apiFolder);
   var packageJsonPath = path.join(apiFolder, 'package.json');
   h.touchSync(packageJsonPath);
   var packageJsonContent = [
     '{',
     '  "name": "best-practices",',
     '  "description": "A package using versioning best-practices",',
     '  "author": "Charlie Robbins <*****@*****.**>",',
     '  "dependencies": {',
     '    "colors": "0.x.x",',
     '    "express": "2.3.x",',
     '    "optimist": "0.2.x"',
     '  },',
     '  "devDependencies": {',
     '    "vows": "0.5.x"',
     '  },',
     '  "engine": "node >= 0.4.1"',
     '}',
   ].join('\n');
   return qfs.write(packageJsonPath, packageJsonContent);
 });
Example #7
0
    return _.reduce(mounts, (volumes, mount, point) => {
      if (_.isString(mount)) {
        mount = { type: 'path', value: mount }
      }

      var target = null;
      switch(mount.type) {
        case 'path':
          target = mount.value;
          if (!target.match(/^\//)) {
            target = path.resolve(this.manifest.manifestPath, target);
          }
          target = (fs.existsSync(target)) ?
            utils.docker.resolvePath(target) : null;
          break;
        case 'persistent':
          target = path.join(persist_base, mount.value);
          break;
      }

      if (!_.isEmpty(target)) {
        volumes[point] = target;
      }

      return volumes;
    }, volumes);
Example #8
0
  _envs_from_file() {
    var envs = {};
    var file = path.join(this.manifest.manifestPath, '.env');

    if (fs.existsSync(file)) {
      var content = fs.readFileSync(file).toString();
      _.each(content.split('\n'), (entry) => {
        if (entry.match(/.*=.*/)) {
          entry = entry.split('=');
          envs[entry[0]] = entry[1];
        }
      });
    }

    return envs;
  }
Example #9
0
File: pid.js Project: awlka/azk
 update(pid = null) {
   this.pid = pid || this.pid;
   if (this.running) {
     fs.writeFileSync(this.file, this.pid);
   } else {
     this.unlink();
   }
 }
Example #10
0
    return h.tmp_dir().then((dir) => {
      rootFolder = dir;

      // `node 1` system folder
      var projectFolder = path.join(dir, 'node1');
      fs.mkdirSync(projectFolder);
      var  packageJson = path.join(projectFolder, 'package.json');
      h.touchSync(packageJson);

      // `node 2` system folder
      projectFolder = path.join(dir, 'node2');
      fs.mkdirSync(projectFolder);
      packageJson = path.join(projectFolder, 'package.json');
      h.touchSync(packageJson);

      return qfs.write(packageJson, '');
    });
Example #11
0
    return _.reduce(mounts, (volumes, mount, point) => {
      if (_.isString(mount)) {
        mount = { type: 'path', value: mount };
      }

      var target = null;
      switch (mount.type) {
        case 'path':
          target = mount.value;

          if (!target.match(/^\//)) {
            target = this._resolved_path(target);
          }

          target = (fs.existsSync(target)) ?
            utils.docker.resolvePath(target) : null;

          break;
        case 'persistent':
          target = path.join(persist_base, mount.value);
          break;

        case 'sync':
          if (daemon && mount.options.daemon !== false ||
             !daemon && mount.options.shell === true) {
            target = this._sync_path(mount.value);
          } else {
            target = mount.value;

            if (!target.match(/^\//)) {
              target = this._resolved_path(target);
            }

            target = (fs.existsSync(target)) ?
              utils.docker.resolvePath(target) : null;
          }
          break;
      }

      if (!_.isEmpty(target)) {
        volumes[point] = target;
      }

      return volumes;
    }, volumes);
Example #12
0
  it("should detect sub-system", function() {
    var sub = path.join(project, "sub");
    fs.mkdirSync(sub);
    h.touchSync(path.join(sub, "Gemfile"));

    var manifest = generateAndReturnManifest(project);
    var system   = manifest.system("sub");

    h.expect(system).to.have.deep.property("name", "sub");
    h.expect(system).to.have.deep.property("options.workdir", "/azk/" + name + "/sub");
  });
Example #13
0
    it("should generate with a valid format", function() {
      var extra = _.merge({}, default_data, {
        systems: {
           front: { envs: { "F-O_O": "BAR"}, scalable: { default: 3}}
        }
      });

      var manifest = generate_manifest(dir, extra);
      var data = fs.readFileSync(manifest.file).toString();

      h.expect(data).to.match(/^\s{2}db: {$/m);
      h.expect(data).to.match(/^\s{6}RACK_ENV: "dev",$/m);
      h.expect(data).to.match(/^\s{6}'F-O_O': "BAR",$/m);
    });
Example #14
0
 parse() {
   var content = fs.readFileSync(this.file);
   var err = check(content, this.file);
   if (err) {
     throw new ManifestError(this.file, err);
   } else {
     try {
       runInNewContext(content, Manifest.createDslContext(this), this.file);
     } catch (e) {
       var stack = e.stack.split('\n');
       var msg   = stack[0] + "\n" + stack[1];
       throw new ManifestError(this.file, msg);
     }
   }
 }
Example #15
0
  var createTestFolders = h.tmp_dir().then((dir) => {
    // -------
    // Gemfile
    // -------
    projectFolder = path.join(dir, 'project');
    fs.mkdirSync(projectFolder);
    var  gemfilePath = path.join(projectFolder, 'Gemfile');
    h.touchSync(gemfilePath);
    var gemfileContent = [
      'source \'https://rubygems.org\'',
      '',
      'gem \'rails\', \'4.1.6\'',
      'gem \'mysql2\'',
    ].join('\n');
    return qfs.write(gemfilePath, gemfileContent);

  });
Example #16
0
  var createTestFolders = h.tmp_dir().then((dir) => {
    // -------
    // Gemfile
    // -------
    rootFullPath = dir;
    var frontFolder = path.join(rootFullPath, 'front');
    fs.mkdirSync(frontFolder);
    var  gemfilePath = path.join(frontFolder, 'Gemfile');
    h.touchSync(gemfilePath);
    var gemfileContent = [
      'source \'https://rubygems.org\'',
      '',
      'gem \'rails\', \'4.1.6\'',
      'gem \'pg\', \'~> 0.17.1\'',
    ].join('\n');
    return qfs.write(gemfilePath, gemfileContent);

  }).then(() => {
Example #17
0
    it("should expand image build steps", function() {
      var extra = _.merge({}, default_data, {
        systems: {
           front: { image: { build: [
             "run step 1",
             ["run", "step 2"],
           ] } }
        }
      });

      var manifest = generate_manifest(dir, extra);
      var data = fs.readFileSync(manifest.file).toString();

      h.expect(data).to.match(/^\s{2}db: {$/m);
      h.expect(data).to.match(/^\s{6}build: \[$/m);
      h.expect(data).to.match(/^\s{8}"run step 1",$/m);
      h.expect(data).to.match(/^\s{8}\["run"\, "step 2"\],$/m);
    });
Example #18
0
 parse() {
   var content = fs.readFileSync(this.file);
   var err = check(content, this.file);
   if (err) {
     throw new ManifestError(this.file, err);
   } else {
     try {
       runInNewContext(content, Manifest.createDslContext(this), this.file);
     } catch (e) {
       if (!(e instanceof ManifestError)) {
         var stack = e.stack.split('\n');
         var msg   = stack[0] + "\n" + stack[1];
         e = new ManifestError(this.file, msg);
       }
       throw e;
     }
   }
   this.systemsInOrder();
 }
Example #19
0
 parse() {
   var content  = fs.readFileSync(this.file);
   let err_file = path.relative(this.cwd_search, this.file);
   var err  = check(content.toString(), this.file);
   if (err) {
     throw new ManifestError(err_file, err, 'syntax');
   } else {
     try {
       lazy.runInNewContext(content, Manifest.createDslContext(this), this.file);
     } catch (e) {
       if (!(e instanceof ManifestError)) {
         var stack = e.stack.split('\n');
         var msg   = stack[0] + "\n" + stack[1];
         log.info('Manifest parse error %s', e.stack);
         throw new ManifestError(err_file, msg, 'logic');
       }
       throw e;
     }
   }
   this.systemsInOrder();
 }
Example #20
0
describe('Azk generators, Elixir Phoenix rule', function() {
  var outputs = [];
  var UI  = h.mockUI(beforeEach, outputs);
  var rule;
  var mixfilePath    = path.join(h.fixture_path('elixir_app'), 'mix_phoenix.exs');
  var mixfileContent = fs.readFileSync(mixfilePath).toString();
  var content, regex;

  before(function() {
    outputs = [];
    UI      = h.mockUI(beforeEach, outputs);
    rule    = new Rule(UI);
  });

  beforeEach(function () {
    content = mixfileContent;
    regex = /\{:phoenix\,\ "(.*)"\}\,/gm;
  });

  it('should return an evidence object', () => {
    var evidence = rule.getEvidence(mixfilePath, content);

    h.expect(evidence).to.have.deep.property('fullpath'  , mixfilePath);
    h.expect(evidence).to.have.deep.property('ruleType'  , 'framework');
    h.expect(evidence).to.have.deep.property('name'      , 'elixir_phoenix');
    h.expect(evidence).to.have.deep.property('ruleName'  , 'elixir_phoenix');
    h.expect(evidence).to.have.deep.property('version'   , '1.0.0');
    h.expect(evidence).to.have.deep.property('framework' , '1.1.4');
    h.expect(evidence).to.have.deep.property('replaces').deep.eql(['elixir', 'node']);
  });

  it('should version 0.12.0 when set 0.12', () => {
    content = content.replace(regex, '{:phoenix, "~> 0.12"},');
    var evidence = rule.getEvidence(mixfilePath, content);

    h.expect(evidence).to.have.deep.property('fullpath'  , mixfilePath);
    h.expect(evidence).to.have.deep.property('ruleType'  , 'framework');
    h.expect(evidence).to.have.deep.property('name'      , 'elixir_phoenix');
    h.expect(evidence).to.have.deep.property('ruleName'  , 'elixir_phoenix');
    h.expect(evidence).to.have.deep.property('version'   , '1.0.0');
    h.expect(evidence).to.have.deep.property('framework' , '0.12.0');
    h.expect(evidence).to.have.deep.property('replaces').deep.eql(['elixir', 'node']);
  });

  it('should version 0.0.0 when set 0', () => {
    content = content.replace(regex, '{:phoenix, "~> 0"},');
    var evidence = rule.getEvidence(mixfilePath, content);

    h.expect(evidence).to.have.deep.property('fullpath'  , mixfilePath);
    h.expect(evidence).to.have.deep.property('ruleType'  , 'framework');
    h.expect(evidence).to.have.deep.property('name'      , 'elixir_phoenix');
    h.expect(evidence).to.have.deep.property('ruleName'  , 'elixir_phoenix');
    h.expect(evidence).to.have.deep.property('version'   , '1.0.0');
    h.expect(evidence).to.have.deep.property('framework' , '0.0.0');
    h.expect(evidence).to.have.deep.property('replaces').deep.eql(['elixir', 'node']);
  });

  it('should null evidence do not found framework deps', () => {
    content = content.replace(regex, '');
    var evidence = rule.getEvidence(mixfilePath, content);

    h.expect(evidence).to.eql(null);
  });
});
Example #21
0
describe('Azk generators, Elixir rule', function() {
  var outputs = [];
  var UI  = h.mockUI(beforeEach, outputs);
  var rule;
  var mixfilePath    = path.join(h.fixture_path('elixir_app'), 'mix.exs');
  var mixfileContent = fs.readFileSync(mixfilePath).toString();
  var content, regex;

  before(function() {
    outputs = [];
    UI      = h.mockUI(beforeEach, outputs);
    rule    = new Rule(UI);
  });

  beforeEach(function () {
    content = mixfileContent;
    regex = new RegExp(h.escapeRegExp('elixir: "~> 1.0",'));
  });

  it('should return an evidence object', () => {
    var evidence = rule.getEvidence(mixfilePath, content);

    h.expect(evidence).to.have.deep.property('fullpath', mixfilePath);
    h.expect(evidence).to.have.deep.property('ruleType', 'runtime');
    h.expect(evidence).to.have.deep.property('name'    , 'elixir');
    h.expect(evidence).to.have.deep.property('ruleName', 'elixir');
    h.expect(evidence).to.have.deep.property('version' , '1.0.0');
  });

  it('should version 1.0.0 when set 1', () => {
    content = content.replace(regex, 'elixir: "~> 1",');
    var evidence = rule.getEvidence(mixfilePath, content);

    h.expect(evidence).to.have.deep.property('fullpath', mixfilePath);
    h.expect(evidence).to.have.deep.property('ruleType', 'runtime');
    h.expect(evidence).to.have.deep.property('name'    , 'elixir');
    h.expect(evidence).to.have.deep.property('ruleName', 'elixir');
    h.expect(evidence).to.have.deep.property('version' , '1.0.0');
  });

  it('should version 0.8.0 when set 0.8', () => {
    content = content.replace(regex, 'elixir: "~> 0.8",');
    var evidence = rule.getEvidence(mixfilePath, content);

    h.expect(evidence).to.have.deep.property('fullpath', mixfilePath);
    h.expect(evidence).to.have.deep.property('ruleType', 'runtime');
    h.expect(evidence).to.have.deep.property('name'    , 'elixir');
    h.expect(evidence).to.have.deep.property('ruleName', 'elixir');
    h.expect(evidence).to.have.deep.property('version' , '0.8.0');
  });

  it('should get latest version when do not found engine', () => {
    content = content.replace(regex, '');
    var evidence = rule.getEvidence(mixfilePath, content);

    h.expect(evidence).to.have.deep.property('fullpath', mixfilePath);
    h.expect(evidence).to.have.deep.property('ruleType', 'runtime');
    h.expect(evidence).to.have.deep.property('name'    , 'elixir');
    h.expect(evidence).to.have.deep.property('ruleName', 'elixir');
    h.expect(evidence).to.have.deep.property('version' , null);
  });
});
Example #22
0
    return this._start_service(name, cmd, pid).then((child) => {
      this.hipache = child;
      log.info("hipache started in %s port with file config", port, file);
      this._handleChild(name, child);
    });
  },

  start_memcached(socket) {
    var pid  = config("paths:memcached_pid");
    var cmd  = [ 'nvm', 'memcachedjs', '--socket', socket ];
    var name = "memcached";

    // Remove socket before start
    // TODO: replace by q-io
    if (fs.existsSync(socket)) {
      fs.unlinkSync(socket);
    }

    return this._start_service(name, cmd, pid).then((child) => {
      this.memcached = child;
      log.info("memcachedjs started in socket: ", socket);
      this._handleChild(name, child);
    });
  },

  stop() {
    if (this.isRunnig()) {
      log.debug("call to stop balancer");
      return Tools.async_status("balancer", this, function* (change_status) {
        yield Q.all([
Example #23
0
 var mock_manifest = (data) => {
   fs.writeFileSync(file, data);
   return () => new Manifest(project);
 }
Example #24
0
 get exist() {
   return fs.existsSync(this.file);
 }
Example #25
0
File: pid.js Project: awlka/azk
 unlink() {
   if (fs.existsSync(this.file)) {
     fs.unlinkSync(this.file);
     this.pid = null;
   }
 }