koopjs / koop-cli

CLI tool to build Koop applications and plugins
Other
11 stars 6 forks source link

Deploy command and deployer #12

Closed haoliangyu closed 4 years ago

haoliangyu commented 5 years ago

This issue is to discuss the deploy command and the deployer. More content is to add.

deploy command

This proposed command is to automate the Koop application deployment to a given cloud platform.

When used, the command reads koop.json, the CLI configuration, at the current Koop application project and check if the project's deployer is specified.

{
  "deployer": "koop-deployer-heroku"
}

The deployer property refers to the name of a standalone Koop deployer module, which includes the actual logic of the deployment.

Alternatively, a js file path can be specified if a custom deployment is needed.

{
  "deployer": "./path/to/custom/module.js"
}

If the deployer is not specified, the command will throw an deployer undefined error.

If the deployer is specified, the deployer will be loaded and deploy the application with any given arguments.

The deploy command is actually a runner of any given deployer. This provides many advantages:

Psedocode of the src/commands/deploy.js:


// read koop.json at the app directory
const config = readKoopConfig()

const deployModule = {
  command: 'deploy',
  description: 'deploy command'
}

if (config.deployer) {
  // if the deployer is specified, load the deployer
  const deployer = require(config.deployer)

  // pass the deployer's argument builder and handler to the "deploy" command
  deployModule.builder = deployer.builder
  deployModule.handler = deployer.handler
} else {
  // export a default deploy command module, which is just to print the
  // deployer undefined error
  deployModule.builder = () => {}
  deployModule.handler = () => {
    throw new Error('deployer undefined')
  }
}

// export a yargs command module
module.exports = deployModule

Deployer

A deployer is a separate nodejs module that exports a yargs command module. It is the actual implementation of the deploy command for a specific platform.

An example:

module.exports = {
  command: 'koop deploy',
  description: 'my custom deploy command',
  builder: (yargs) => {
    // defind command options
  }
  handler: (argv) => {
    // handle command call
  }
}

How to use

The Koop CLI and the deployer module must be installed as global packages or the project's dev dependencies at the same time. Once the user specifies the deployer at the project's koop.json, he can use the koop deploy command for the app.

Plan

haoliangyu commented 5 years ago

ping @dmfenton @rgwozdz for comments

rgwozdz commented 5 years ago

This seems like a very good approach! Looking forward to seeing the PR.

haoliangyu commented 4 years ago

Close the proposal for now because the deployment is out of scope. We should guide the Koop developers to use the native tool provided by the cloud service provider.