RocketChat / Rocket.Chat.Apps-cli

The CLI for interacting with Rocket.Chat Apps
MIT License
46 stars 27 forks source link

How to update app without losing association storage #99

Open ghost opened 3 years ago

ghost commented 3 years ago

I am developing an app which makes use of the RocketChatAssociationRecord for rooms.
When I try to deploy a new version, it fails with " › Error: ⟿ Error: Deployment error: App already exists.". But if I uninstall the app first, it removes all associated storage.

How can I update an app without losing stored data?

Is there an "update" command, or a check for a new version number? Can't find either

JargeZ commented 3 years ago

You should use rc-apps deploy --url=http://localhost:3000 --update

P.S. However, I agree that it would be more convenient to have one deployment command that either installs or updates the application itself

d-gubert commented 3 years ago

Totally agreed. @ritwizsinha introduced the new watch command as his GSoC project that doesn't run into this error, so maybe that command already checks for this case.

Maybe it's the case of extracting the logic into a function and reusing it? :)

JargeZ commented 3 years ago

@d-gubert If I understand correctly, the watch command is needed for development. and by the way, I just tried it and get the error:

Error: Cannot find module 'chokidar'
$ rc-apps -v
@rocket.chat/apps-cli/1.7.3 linux-x64 node-v14.15.1

After installing the module manually, it worked, it looks like you need to add it depending on it But it still looks like it shouldn't be - No changes were made Imgur

And for use in CI/CD pipelines, it would be convenient for the deployment command to immediately update the application if it is already installed by one rc-apps deploy call

ritwizsinha commented 3 years ago

@JargeZ, this is happening because, by default it is watching the current directory for changes and redeploying on any change, as the dist folder is updated everytime after packaging, it redeploys again and again. For avoiding this you can specify which folder and files to avoid watching for changes. This can be done by adding a rcappsconfig file and add the list of ignored files or folders or files in the ignoredFiles array as follows: You can also add the local url to deploy to, the username and the password here, so as to avoid passing that again and again. The file is in JSON format.

        url: 'http://localhost:3000',
            username: '',
            password: '',
            ignoredFiles: [
                '**/README.md',
                '**/package-lock.json',
                '**/package.json',
                '**/tslint.json',
                '**/tsconfig.json',
                '**/*.js',
                '**/*.js.map',
                '**/*.d.ts',
                '**/*.spec.ts',
                '**/*.test.ts',
                '**/dist/**',
                '**/.*',
            ],
JargeZ commented 3 years ago

@ritwizsinha Of course I have this file. The scaffolding was generated by the same version of rc-apps If others do not have this problem, could you tell me how I can see which files the script considers modified? Or is there an only option to just install the package locally and run it with a debugger?

cuonghuunguyen commented 3 years ago

Totally agreed. @ritwizsinha introduced the new watch command as his GSoC project that doesn't run into this error, so maybe that command already checks for this case.

Maybe it's the case of extracting the logic into a function and reusing it? :)

Hi, I had a look at the code, it is really a useful feature <3. Some improvement I could suggest that is you may only need to do login + check permission + check app updatability once and then use the token + flag update every following time :D. That could improve the performance

steve-todorov commented 3 years ago

The watch command goes completely bananas. :) I have added ignoredFiles: [] into the .rcappsconfig as suggested, but this doesn't do anything at all. The command is in a forever loop.

cuonghuunguyen commented 3 years ago

The watch command goes completely bananas. :) I have added ignoredFiles: [] into the .rcappsconfig as suggested, but this doesn't do anything at all. The command is in a forever loop.

That's a bug as I see. Add **/app.json to the ignoredFiles list. They implemented the logic to update the app.json file with implements but forgot to ignore it. But tbh u should create another issue

steve-todorov commented 3 years ago

Oh man! Thanks for sharing! That fixes the loop! I wonder why they didn't include this by default. :)

cuonghuunguyen commented 3 years ago

They seem didn't expect it. App.json is changed, but the new value is equal to the old one. Idk why but chokidar will still emit a change event for that, thats why the app gets re-deployed