Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker support using Alpine base image #20

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Jasmin25
Copy link

@Jasmin25 Jasmin25 commented Apr 19, 2023

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:

  • Added Dockerfile: The new Dockerfile provides a multi-stage build process to create an optimized final image.
  • Added docker-compose.yml: A docker-compose file is included to make it easier to run the application using Docker Compose.
  • Updated .gitignore: Removed the Dockerfile from the .gitignore to include it in the repository.
  • Updated package.json: Added new script specifically for docker start, without disturbing the manual process scripts.
  • Updated README.md: Added instructions for running the application using Docker.

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
Copy link

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
Copy link
Author

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
Copy link

xaksh commented Apr 21, 2023

Tested the docker compose. Works! Great work guys

@Jasmin25
Copy link
Author

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

@UglyBob79
Copy link

UglyBob79 commented Apr 29, 2023

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
Copy link
Author

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
Copy link

UglyBob79 commented Apr 30, 2023

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
Copy link

xaksh commented May 2, 2023

@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
Copy link
Author

Jasmin25 commented May 2, 2023

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
Copy link
Author

Jasmin25 commented May 2, 2023

@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
Copy link

xaksh commented May 3, 2023

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
Copy link
Author

Jasmin25 commented May 3, 2023

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
Copy link

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! ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants