nextcloud / context_chat_backend

GNU Affero General Public License v3.0
5 stars 5 forks source link

Set-up a remote docker for backend #3

Closed Floflobel closed 7 months ago

Floflobel commented 8 months ago

Hello,

I tried to set up the whole set-up without having Docker on my Nextcloud. I would like to make a separate docker for the backend.

The problem is that when configuring on Nextcloud in the admin interface we have to specify a docker network.

Is it possible to carry out this installation only by connecting to the backend port and sharing the /var/www/nextcloud folder with the backend?

kyteinsky commented 8 months ago

What do you mean by "a separate docker for the backend"? A remote instance with this backend app in a docker container? You will need to provide the NC's web server user access to /var/run/docker.sock for AppAPI to work.

During the configuration in NC, you might have seen the AppAPI's deploy daemon settings. The default one prevents access to the external app's port in the whole machine but only inside the docker network and in NC.

Yes, you can totally do that by just having access to the host and port and don't need to provide access to the nextcloud folder to the external app. The register step will do just that but would require you to create a manual deploy daemon first.

occ app_api:daemon:register --net host manual_install "Manual Install" manual-install http null <nextcloud_url>

More info here: https://cloud-py-api.github.io/app_api/CreationOfDeployDaemon.html

Floflobel commented 8 months ago

Thank you for the quick reply.

What do you mean by "a separate docker for the backend"? A remote instance with this backend app in a docker container? You will need to provide the NC's web server user access to /var/run/docker.sock for AppAPI to work.

My current set-up is nextcloud installed in an LXD container. And I use Portainer to manage my Docker in a separate LXD container. This allows me to separate the dockers from the other manually installed tools.

I don't want to install docker on Nextcloud because I want it to have as few dependencies as possible.

So I just wanted to leave my Nextcloud container as is and create a Docker for "context_chat_backend" on Portainer.

But from what I understand "context_chat_backend" needs to have access to the Docker socket to work ?

Yes, you can totally do that by just having access to the host and port and don't need to provide access to the nextcloud folder to the external app. The register step will do just that but would require you to create a manual deploy daemon first.

Are you talking about performing the Complex Install (without docker) in this case?

Just so you know, I turned to this manual installation without docker and I had a problem with the dependencies because I was using python3.8. I think you should add to the doc that you need python3.9.

I have another problem: once the pip prerequisites have been installed, I get this error:

(.venv) root@box:~/context_chat_backend # ./main.py                                                                                                                                                                  
Traceback (most recent call last):
  File "/root/context_chat_backend/./main.py", line 6, in <module>
    from context_chat_backend import create_server, models, vector_dbs
  File "/root/context_chat_backend/context_chat_backend/__init__.py", line 6, in <module>
    from .controller import app
  File "/root/context_chat_backend/context_chat_backend/controller.py", line 10, in <module>
    from .chain import embed_sources, process_query
  File "/root/context_chat_backend/context_chat_backend/chain/__init__.py", line 1, in <module>
    from .ingest import embed_sources
  File "/root/context_chat_backend/context_chat_backend/chain/ingest/__init__.py", line 1, in <module>
    from .injest import embed_sources
  File "/root/context_chat_backend/context_chat_backend/chain/ingest/injest.py", line 7, in <module>
    from .doc_loader import decode_source
  File "/root/context_chat_backend/context_chat_backend/chain/ingest/doc_loader.py", line 76, in <module>
    def _load_email(file: BinaryIO, ext: str = 'eml') -> str | None:
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'
bigcat88 commented 8 months ago

def _load_email(file: BinaryIO, ext: str = 'eml') -> str | None:

that's Python 3.10 syntax

kyteinsky commented 8 months ago

But from what I understand "context_chat_backend" needs to have access to the Docker socket to work ?

Yes, for the one-click install from the External App Store. For the manual one, the manual-install deploy daemon can be used instead.

Are you talking about performing the Complex Install (without docker) in this case?

Since you're using portainer to manage your docker containers,

  1. you can build a docker image from the Dockerfile.dev file and remember to tweak the example.env to your liking or mount a volume for the .env file
  2. create a docker container and expose the defined port the .env file
  3. register a manual-install deploy daemon (see my previous post)
  4. register the context_chat_backend app (you can find the command in the Makefile)

You should be able to use Context chat now, provided you installed the php companion context_chat app and the app_api app. Quick way to test it would be occ context_chat:scan <username>

bigcat88 commented 8 months ago

Since you're using portainer to manage your docker containers,

Do we really have a difference between Portainer and Docker? For AppAPI there is no difference between Portainer or Docker, as they are compatible and both use Docker Engine

kyteinsky commented 8 months ago

Do we really have a difference between Portainer and Docker?
For AppAPI there is no difference between Portainer or Docker, as they are compatible and both use Docker Engine

I meant to say that @Floflobel is using docker and does not need to fiddle with the (manual install without docker) and the dependencies.

Floflobel commented 7 months ago

Thank you very much for your explanations, I think I've understood better.

So I executed these two commands on my Nextcloud server after my docker is up and I've installed the prerequisite apps:

sudo -u www-data php /var/www/nextcloud/occ app_api:daemon:register --net host manual_install "Manual Install" manual-install http null https://URL

sudo -u www-data php /var/www/nextcloud/occ app_api:app:register context_chat_backend manual_install --json-info "{\"appid\":\"context_chat_backend\",\"name\":\"Context Chat Backend\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"h1-portainer.domain\",\"port\":3658,\"scopes\":{\"required\":[],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" --force-scopes

I do have one final question. It seems that my "Context Chat Backend" application is in version 1.0.0 and not 1.0.1. I tried to redo the command by unregistering first and giving it "version":\"1.0.1" but it didn't change anything.

If I go through the Nextcloud GUI it tells me :

An error occurred during the request. Unable to proceed.
Only docker-install is supported for now
kyteinsky commented 7 months ago

I do have one final question. It seems that my "Context Chat Backend" application is in version 1.0.0 and not 1.0.1.

yeah it was just a readme update to the app store so the docker image uses the same 1.0.0 version. It is absolutely fine.

In the Nextcloud GUI, AppAPI reports an error because it cannot contact the docker socket which is required if AppAPI were to setup the docker container for the ex-app itself, which is not the case here so it should be good for this app. If you want to install other external apps through the GUI, that mandates the docker.sock access in the Nextcloud container.

Floflobel commented 7 months ago

Thanks for your help, I've managed to understand it better and implement it. I'm closing this ticket.

kyteinsky commented 7 months ago

Thanks to you for trying out the app! Does it work reliably on your system for general queries? It would be helpful to identify bugs upfront.

Floflobel commented 7 months ago

I still have to scan all my documents before I can test it. I'll let you know if I see a problem or an improvement when I've played with it a bit.

Thank you for this great project!