kuzzleio / kuzzle

Open-source Back-end, self-hostable & ready to use - Real-time, storage, advanced search - Web, Apps, Mobile, IoT -
https://kuzzle.io
Apache License 2.0
1.43k stars 123 forks source link

CLI kuzzle createFirstAdmin fails before input #1294

Closed BenjaminVadant closed 5 years ago

BenjaminVadant commented 5 years ago

Hi,

when trying to run the following command: kuzzle createFirstAdmin, I'm getting an error before entering any inputs.

Expected Behavior

I should be able to enter details for the first admin

Current Behavior

An error is thrown:

root@d7fdfe8171d7:/var/app# kuzzle createFirstAdmin
[2019-04-30 10:04:01+00:00] - Waiting for elasticsearch
[2019-04-30 10:04:01+00:00] - Elasticsearch is up. Waiting for shards...
[2019-04-30 10:04:01+00:00] - Starting Kuzzle...
/var/app/node_modules/kuzzle-sdk/src/Kuzzle.js:45
        throw new Error(`Protocol instance must implement a "${method}" method`);
        ^

Error: Protocol instance must implement a "addListener" method
    at new Kuzzle (/var/app/node_modules/kuzzle-sdk/src/Kuzzle.js:45:15)
    at sendAction (/var/app/bin/commands/sendAction.js:51:18)
    at Command.commandCreateFirstAdmin (/var/app/bin/commands/createFirstAdmin.js:89:10)
    at Command.listener (/var/app/node_modules/commander/index.js:315:8)
    at emitTwo (events.js:126:13)
    at Command.emit (events.js:214:7)
    at Command.parseArgs (/var/app/node_modules/commander/index.js:654:12)
    at Command.parse (/var/app/node_modules/commander/index.js:474:21)
    at Object.<anonymous> (/var/app/bin/kuzzle:97:9)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)

Steps to Reproduce

  1. Launch kuzzle via docker
  2. Log in the kuzzle container: docker exec -it kuzzle /bin/bash
  3. Run kuzzle createFirstAdmin

Context (Environment)

Kuzzle version: 1.6.0 Node.js version: v8.11.3 SDK version: ^6.0.0-beta-6

Additional request

Would it be possible to have an "non-interactive" version of this command in order to easily automate setting up kuzzle instances.

Aschen commented 5 years ago

Hi @BenjaminVadant,

I'm not able to reproduce your issue with Kuzzle 1.6.0. Here is the docker-compose file I used:

version: '2'

services:
  kuzzle:
    image: kuzzleio/kuzzle:1.6.0
    ports:
      - "7512:7512"
    cap_add:
      - SYS_PTRACE
    depends_on:
      - redis
      - elasticsearch
    volumes:
      - "./kuzzle:/var/app"
    environment:
      - kuzzle_services__db__client__host=http://elasticsearch:9200
      - kuzzle_services__internalCache__node__host=redis
      - kuzzle_services__memoryStorage__node__host=redis
      - NODE_ENV=development

  redis:
    image: redis:3.2

  elasticsearch:
    image: kuzzleio/elasticsearch:5.4.1
    environment:
      - cluster.name=kuzzle
      - "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"

About the createFirstAdmin action of the CLI, it's simply use the security:createFirstAdmin route from the API. Here you can the query send to Kuzzle through the Javascript SDK.

ffly4u commented 5 years ago

Actually, I'm having this issue with all commands of the kuzzle CLI.

My docker-compose file is fairly similar (I'm using version 3 of docker compose)

I found the issue: in kuzzle:1.6.0, here https://github.com/kuzzleio/kuzzle/blob/1.6.0/bin/commands/sendAction.js#L51

the first parameter is a string but in the kuzzle-sdk beta 6: https://github.com/kuzzleio/sdk-javascript/blob/6.0.0-beta-6/src/Kuzzle.js the constructor expects directly the protocol object.

So the build 1.6.0 is not good when using the kuzzle CLI. I'm surprise that you were able to make it work... can you check which version of the kuzzle sdk you have installed on it?

Aschen commented 5 years ago

@ffly4u @BenjaminVadant Ok I managed to reproduce. Actually I was using the 1.6.0 version of the code but didn't do a new npm install so the kuzzle-sdk version was the latest and not 6.0.0-beta-6.

The CLI has been fixed in 1.6.4. (See https://github.com/kuzzleio/kuzzle/pull/1249)

We are aware that the CLI is not part of our test suite and that many improvement could be done but unfortunately we have other priorities for now.

For your usecase, you can use a simple Node.js script that call the corresponding API action so you can automate the setup of Kuzzle instances.
An other way would be the use a default securities definitions with your default roles, profiles and user. This file can then be loaded using the --securities option of the CLI start command.