pashpashpash / vault-ai

OP Vault ChatGPT: Give ChatGPT long-term memory using the OP Stack (OpenAI + Pinecone Vector Database). Upload your own custom knowledge base files (PDF, txt, epub, etc) using a simple React frontend.
https://vault.pash.city
MIT License
3.26k stars 307 forks source link

Add Docker support using Alpine base image #20

Open Jasmin25 opened 1 year ago

Jasmin25 commented 1 year ago

This PR adds Docker support to the application by introducing a multi-stage Dockerfile with an Alpine base image to minimize the final image size. The Dockerfile is divided into three stages:

  1. Build the Go backend.
  2. Build the React frontend.
  3. Assemble the final image with the built backend, frontend, and required runtime dependencies.

Changes:

How to test:

  1. Ensure Docker and Docker Compose are installed on your system.
  2. Run docker-compose up in the project's root directory.
  3. Open a browser and navigate to http://localhost:8100. The application should be running and accessible.

Additional notes:

  1. Special thanks to @oscarsantillana for making a PR; I got some inspiration from there to make fixes here.
  2. Additional testing is required before the merge, as I do not have PineCone access yet. I've tested that the platform comes up and gets the relevant errors with the OpenAI key.
  3. Update required to packages-lock.json file.
oscarsantillana commented 1 year ago

I'm glad my code was helpful. Please have a look at my latest commit about max file size. Might be useful to include it as an environment variable in docker-compose.

Jasmin25 commented 1 year ago

I'm glad my code was helpful. Please have a look at my latest commit about max file size. Might be useful to include it as an environment variable in docker-compose.

That's a great feature, I believe it should go in as a separate feature (with your name) once this PR gets merged.

xaksh commented 1 year ago

Tested the docker compose. Works! Great work guys

Jasmin25 commented 1 year ago

I tested it as well -- as I got access to Pinecone, works fine. @pashpashpash

UglyBob79 commented 1 year ago

Stupid question maybe, but I'm trying to access this from another local machine and whatever I do I get: This site can’t provide a secure connection. This happens even if accessing over http. In the docker log I get:

vault-ai-opvault-1 | [negroni] Apr 29 17:23:36 | 200 | 1.2142ms vault-ai-opvault-1 | GET /

I guess I need to disable SSL or something, but not sure how...

Jasmin25 commented 1 year ago

Stupid question maybe, but I'm trying to access this from another local machine and whatever I do I get: This site can’t provide a secure connection. This happens even if accessing over http. In the docker log I get:

vault-ai-opvault-1 | [negroni] Apr 29 17:23:36 | 200 | 1.2142ms vault-ai-opvault-1 | GET /

I guess I need to disable SSL or something, but not sure how...

Do you have any other containers that you are able to run correctly from the same source and destination local machine? Afraid this might not be relevant to this PR.

UglyBob79 commented 1 year ago

Stupid question maybe, but I'm trying to access this from another local machine and whatever I do I get: This site can’t provide a secure connection. This happens even if accessing over http. In the docker log I get: vault-ai-opvault-1 | [negroni] Apr 29 17:23:36 | 200 | 1.2142ms vault-ai-opvault-1 | GET / I guess I need to disable SSL or something, but not sure how...

Do you have any other containers that you are able to run correctly from the same source and destination local machine? Afraid this might not be relevant to this PR.

Yes, several. It might be related to the docker setup of this PR though, I got it working with tunneling, so I think the problem is it binds to localhost. And even if I configure it to bind to my ip in the compose file, it still binds to localhost. But I'm not sure if it's hard coded in the source or something.

xaksh commented 1 year ago

@Jasmin25 @UglyBob79 I think I have hit this issue too. Upon looking I found something in the index.html. Is that something that might not be letting it load on anything other than localhost?

    <script type="text/javascript">
        (function () {
            if (
                location.hostname !== 'localhost' &&
                location.protocol !== 'https:'
            ) {
                location.replace(
                    'https:' +
                    location.href.substring(location.protocol.length)
                );
            }
        })();
    </script>
Jasmin25 commented 1 year ago

Thanks for looking into it @xaksh; I can further look into a solution later tonight and update the PR with a fix, if any.

Jasmin25 commented 1 year ago

@xaksh @UglyBob79

So, I looked into it and this script forces users to use HTTPS by redirecting them if they access the page with HTTP. However, it does not redirect if the hostname is "localhost". So, how about "whitelisting" the local network IPs too?

Perhaps you could test by modifying the static/index.html to the following? It's a hack, but hey, if it works ;)

Let me know if it works, I can update the PR.

(function () {
    const localNetworkPrefix = '192.168.'; // Replace this with your local network's IP address prefix

    if (
        location.hostname !== 'localhost' &&
        !location.hostname.startsWith(localNetworkPrefix) &&
        location.protocol !== 'https:'
    ) {
        location.replace(
            'https:' +
            location.href.substring(location.protocol.length)
        );
    }
})();
xaksh commented 1 year ago

Tested. Confirm it works. I think this should be handled more elegantly but since OP had it in such a way at first place, hotfix for now should be good. Question! Would setting network prefix to 0.0.0.0 allow all?

Anyways thanks! @Jasmin25

Jasmin25 commented 1 year ago

Perhaps just disabling HTTPS redirect would be a better solution till its handled by the OP themselves?

What happens when you comment out the javascript part?

pedroespecial101 commented 1 year ago

Hi - has the Docker support been superseded by the latest updates? If so, I'm wondering if I should try out Jasmin25's last commit and perhaps upgrade from there? Or is there an easy fix to get it working with Docker? ....or perhaps am I unreasonably scared of installing Go etc. on my machine and should in fact just dive in! ;-)