0.0.1 • Published 5 years ago

moleculer-app-updater v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Moleculer logo

Build Status Coverage Status David Known Vulnerabilities Join the chat at https://gitter.im/moleculerjs/moleculer

moleculer-app-updater NPM version

Moleculer service to update a node application with a REST API

Features

  • Auto-update your application
  • Add assets to your update
  • Use a secret to filter who can create a version
  • Custom deploy

Install

yarn add moleculer-app-updater

Usage

// Create broker
const broker = new ServiceBroker({
  logger: console,
  logLevel: 'trace',
});

// Load my service
broker.createService({
  name: 'app-updater',
  mixins: [AppUpdater],
  settings: {
    // Secret to send in newVersion action
    // Default false
    secret: process.env.APP_UPDATE_SECRET,
    // Where to put assets
    // Default os.tmpdir()
    tmpFolder: path.join(__dirname, 'assets'),
    // Minutes before clearing the current version if not deployed
    // Default 5
    versionTimeout: 5,
    // AppVersion class
    AppVersion: MyCustomVersionClass
  }
});
broker.createService({
  name: 'api',
  mixins: [ApiGateway],

  settings: {
    routes: [
      {
        path: '',

        // You should disable body parsers
        bodyParsers: { json: false, urlencoded: false },

        aliases: {
          // You must declared this route yourself for now
          'POST /v1/app-updater/set-assets': 'stream:v1.app-updater.setAssets',
        },

        autoAliases: true,
      },
    ],
  },
});

Example MyCustomVersionClass:

class MyCustomVersionClass extends AppVersion {
  status(){
    return {
      progress: this.progress,
    };
  }
  
  async deploy(){
    this.isDeploying = true;
    // Do what you want here
    await doBackup();
    this.progress = 10;
    await doExtractAssets(this.filePath);
    this.progress = 30;
    await doUpdate(this.meta);
    this.progress = 80;
    await reloadMoleculerServices();
    this.progress = 100;
    this.logger.warn(`New version ${this.id} deployed`);
    
    this.isDeploying = false;
    this.isDeployed = true;
  }
}

Test

$ yarn test

In development with watching

$ yarn run ci

Contribution

Please send pull requests improving the usage and fixing bugs, improving documentation and providing better examples, or providing some testing, because these things are important.

License

The project is available under the MIT license.

Contact

Copyright (c) 2018 Marc-Antoine Fernandes

@moleculerjs