Skip to content
New issue

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

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

Already on GitHub? # to your account

feat(docker): added docker-compose script #170

Merged

Conversation

pret3nti0u5
Copy link
Contributor

Description

Adds a docker-compose script.

Changes

Added a docker-compose script. Changed the original Dockerfile to work better with the docker-compose script. Edited README.md to better reflect the changes and how to use the new docker-compose script.

How to test

docker-compose up -d

Please consider using the closing keyword if the pull request is proposed to
fix an issue already created in the repository
(https://help.github.com/articles/closing-issues-using-keywords/)

@GMishx GMishx added enhancement New feature or request needs review Need code review needs test Needs testing labels Jan 27, 2022
@Shruti3004
Copy link
Collaborator

Hey @pret3nti0u5 two things here:

  • Can you remove the yarn.lock changes.
  • Also run the prettier script because of that build is failing.

@GMishx
Copy link
Member

GMishx commented Jan 31, 2022

@pret3nti0u5 , instead of modifying the original Dockerfile, how about creating a new Dockerfile.dev for development purposes and leave the Dockerfile for production grade deployment?

Similar thing can be done for the docker-compose.yml?

@pret3nti0u5
Copy link
Contributor Author

@Shruti3004 yea, I'll do that.

@pret3nti0u5
Copy link
Contributor Author

@GMishx The new dockerfile isn't actually anything different from the original Dockerfile, just sets up some bind mounts to allow for development on Docker or Local Machine. But I do agree with you I will push a new commit with two Dockerfiles and docker-compose scripts. I'll keep the prod version of docker-compose to use just the prod version of Dockerfile, so that running it can be consolidated into one simple command. I'll keep the current changes for dev version of Dockerfile and docker-compose. Hope it sounds all good?

Copy link
Member

@GMishx GMishx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions and questions.

prod.Dockerfile Outdated Show resolved Hide resolved
docker-compose.yml Outdated Show resolved Hide resolved
docker-compose.prod.yml Outdated Show resolved Hide resolved
docker-compose.prod.yml Outdated Show resolved Hide resolved
@pret3nti0u5
Copy link
Contributor Author

Renamed the Dockerfiles and docker-compose files to what was suggested.

Also added fossology/fossology:latest to docker-compose.dev.yml as suggested by @GMishx . I have for now kept the changes to only dev version since fossology/fossology:latest can't serve as the backend for FOSSologyUI right now, because of CORS issues.

Currently the project uses the entire URL described in .env (REACT_APP_SERVER_URL) which causes said CORS issues. To get rid of them we will have to proxy requests sent from the Frontend. You can read more about it here.

This would require a slight rework of the current code, which I am ready to work for, but would suggest to open a new PR for resolving this issue.

The benefits of this rework would be that fossology and FOSSologyUI would never need to be merged for a proper production deployment. For development purposes, the user would either have to stick only to the Docker based development or forego the usage of the Backend for development.

Let me know what the proper approach to this problem would be according to you.

Copy link
Member

@GMishx GMishx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes looks good. Needs test.

@GMishx GMishx removed the needs review Need code review label Feb 17, 2022
@GMishx
Copy link
Member

GMishx commented Feb 17, 2022

Renamed the Dockerfiles and docker-compose files to what was suggested.

Also added fossology/fossology:latest to docker-compose.dev.yml as suggested by @GMishx . I have for now kept the changes to only dev version since fossology/fossology:latest can't serve as the backend for FOSSologyUI right now, because of CORS issues.

Currently the project uses the entire URL described in .env (REACT_APP_SERVER_URL) which causes said CORS issues. To get rid of them we will have to proxy requests sent from the Frontend. You can read more about it here.

This will be a better solution. And the .env file can be changed while creating the Docker image or at entrypoint like done in FOSSology: https://github.com/fossology/fossology/blob/4ce46a3ed1490dce672c3b02fea8aff930017f36/docker-entrypoint.sh#L15-L26

This would require a slight rework of the current code, which I am ready to work for, but would suggest to open a new PR for resolving this issue.

Yes, it should be a new PR.

The benefits of this rework would be that fossology and FOSSologyUI would never need to be merged for a proper production deployment. For development purposes, the user would either have to stick only to the Docker based development or forego the usage of the Backend for development.

Let me know what the proper approach to this problem would be according to you.

Having a single docker-compose setup which can scripted using ARG and ENV will be really nice. We can leave the default values like localhost if someone wants to do a source install.

If you are willing to work on the same, I would recommend you create an issue first for the same.

@GMishx
Copy link
Member

GMishx commented Feb 17, 2022

@pret3nti0u5 , please add docker files to .eslintignore and .prettierignore otherwise CI will keep failing.

/cc @Shruti3004 @Aman-Codes

@GMishx
Copy link
Member

GMishx commented Feb 18, 2022

@pret3nti0u5 looks like you've merged some branch to your existing branch bringing other commits to this PR. We at FOSSology prefer rebasing over merge. It helps keep git history clean.

Can you please rebase your branch with main branch?

@pret3nti0u5 pret3nti0u5 force-pushed the pret3ntiou5/feat/add-docker-compose branch from 5be4a58 to f36abe0 Compare February 18, 2022 14:08
@pret3nti0u5
Copy link
Contributor Author

@GMishx I guess this should work? Sorry, I am a bit new when it comes to using git with multiple members pushing and pulling changes.

@sjha2048
Copy link
Collaborator

sjha2048 commented Mar 18, 2022

Hi @pret3nti0u5, can you please squash your commits and resolve the conflicts?

@sjha2048 sjha2048 added the has merge conflicts PR has merge conflicts, require rebase label Mar 18, 2022
@pret3nti0u5 pret3nti0u5 force-pushed the pret3ntiou5/feat/add-docker-compose branch from f36abe0 to 41ea40b Compare March 21, 2022 04:39
@github-actions github-actions bot removed the has merge conflicts PR has merge conflicts, require rebase label Mar 21, 2022
@pret3nti0u5
Copy link
Contributor Author

Hey @sjha2048, I guess this is fine? Let me know if any changes are needed!

@GMishx
Copy link
Member

GMishx commented Mar 21, 2022

Hello @pret3nti0u5 ,

Looks like files docker-compose.dev.yml, docker-compose.yml and Dockerfile are in CRLF format instead of LF. It ideally should not cause issues but I have past experience it screwing docker-compose. Can you please fix that?

And do you have any idea why following is happening?

gitpod /workspace/FOSSologyUI (pret3ntiou5/feat/add-docker-compose) $ docker-compose version
Docker Compose version v2.2.3
gitpod /workspace/FOSSologyUI (pret3ntiou5/feat/add-docker-compose) $ docker compose version
Docker Compose version v2.2.3
/workspace/FOSSologyUI (pret3ntiou5/feat/add-docker-compose) $ docker-compose -f docker-compose.dev.yml up
[+] Running 14/15
 ⠿ fossology_server Pulled                                                                                          19.7s
   ⠿ a4b007099961 Pull complete                                                                                      2.1s
   ⠿ 5c6ea32d3390 Pull complete                                                                                      2.4s
   ⠿ 4f4fb700ef54 Pull complete                                                                                      2.5s
   ⠿ efe0f0e900d6 Pull complete                                                                                     15.2s
   ⠿ ec58a976d89c Pull complete                                                                                     15.2s
   ⠿ 97419618e5de Pull complete                                                                                     15.3s
   ⠿ 2eeb4e6a4627 Pull complete                                                                                     15.4s
   ⠿ dcc50025cda5 Pull complete                                                                                     15.4s
   ⠿ e03b5e05ea7b Pull complete                                                                                     15.5s
   ⠿ 3e4e3d79f548 Pull complete                                                                                     15.5s
   ⠿ 8c0f91ee7a32 Pull complete                                                                                     15.6s
   ⠿ 566f0537daad Pull complete                                                                                     17.0s
   ⠿ 62ed03ef75b1 Pull complete                                                                                     18.5s
 ⠿ fossologyui_server Error                                                                                          1.1s
1 error occurred:
        * unable to prepare context: context must be a directory: /workspace/FOSSologyUI/Dockerfile.dev

@pret3nti0u5
Copy link
Contributor Author

Hey @GMishx, The docker scripts seem to be working fine on my machine, maybe it's a gitpod specific issue? Generally if you mention the dockerfile in the context directive without specifically separating it out, it still works but I'll separate it out into context and dockerfile directives in the docker-compose files, maybe it'll resolve the issue. Ill push a commit soon, let me know if you want me to squash it too.

@pret3nti0u5
Copy link
Contributor Author

Should work now, works on my machine. Please test it and let me know if I should squash the commit. @GMishx @sjha2048 @Shruti3004

@GMishx
Copy link
Member

GMishx commented Mar 28, 2022

Everything seems to be working fine now. Just one suggestion to add REACT_APP_SERVER_URL and REACT_APP_HTTPS as an environment to both the compose file so the values can be changes at run time. Currently, if I have to change the endpoint URL, I have to rebuild the image.

Otherwise, things are working as expected.

And please change the commit message of last commit (Changed file Dockerfile formats from CRLF to LF).

@pret3nti0u5
Copy link
Contributor Author

Yeah, I didn't want to edit the original Dockerfile so I kept it as build args as specified in the original Dockerfile instead of environment variables. I'll make that change now.

@GMishx
Copy link
Member

GMishx commented Mar 30, 2022

Yeah, I didn't want to edit the original Dockerfile so I kept it as build args as specified in the original Dockerfile instead of environment variables. I'll make that change now.

It's better to have build args. Just suggesting to add environment variables too.

@pret3nti0u5
Copy link
Contributor Author

The original Dockerfile uses the build args as env variables, wouldn't defining environment variables in the compose files conflict with that?

@GMishx
Copy link
Member

GMishx commented Mar 30, 2022

It won't cause issue as the ARG should override the environment from docker compose during build.
At run time, the environment from docker compose can override the value image has.

So, if someone wants to update the value after they have created the image, just updating the environment in compose.yml file will work and they'll not have to re-create the images.

@pret3nti0u5
Copy link
Contributor Author

Got it, let me push the changes.

@pret3nti0u5 pret3nti0u5 force-pushed the pret3ntiou5/feat/add-docker-compose branch from c2eb151 to 7184b3d Compare March 30, 2022 06:26
@GMishx
Copy link
Member

GMishx commented Mar 30, 2022

@pret3nti0u5 Can you please update the commit messages so I can merge this PR?

@pret3nti0u5
Copy link
Contributor Author

pret3nti0u5 commented Mar 30, 2022

@GMishx Could you please tell me which commit message I should update? Or do you want me to squash all those commits into one?

@GMishx
Copy link
Member

GMishx commented Mar 30, 2022

Just the last 2, as they are not following the commit message guidelines.
image

@pret3nti0u5 pret3nti0u5 force-pushed the pret3ntiou5/feat/add-docker-compose branch from 7184b3d to baa8619 Compare March 30, 2022 07:29
@pret3nti0u5
Copy link
Contributor Author

@GMishx I guess this works? Let me know if you want me to change something.

Copy link
Member

@GMishx GMishx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, working as expected.

@GMishx GMishx added ready PR is ready for merge and removed needs test Needs testing labels Mar 30, 2022
@GMishx
Copy link
Member

GMishx commented Mar 30, 2022

Looks good now. Thank you

@pret3nti0u5
Copy link
Contributor Author

Thanks for being patient with me! Glad I could add something for the organization.

@GMishx GMishx merged commit 2d84bc2 into fossology:main Mar 30, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request ready PR is ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants