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

Added Dockerized MongoDb with Seed Data #759

Closed
wants to merge 1 commit into from

Conversation

jasonwong26
Copy link
Contributor

Closes #659
Closes #660

Summary

Added MongoDb container to docker environment.

Also added the new /mongo folder for storing the logic for generating seed data and loading it into the database. I have included a README.md within that folder with details on how to use it. But to summarize:

  • The /data folder contains a set of JSON files that store the seed data.
  • The /scripts folder contains a Node script that can be used to generate seed data using faker.
  • The init.sh file contains the commands that are run when the docker environment is started to seed the database.

To retain the ability to run the project locally (without using Docker) I modified the backend/src/config/database.config.js file to recognize when it is being run within Docker via a new environment variable: DATABASE_HOST. When that is provided (it is included in the Docker-Compose file), the application connects to the Mongo database within the docker environment. Otherwise it uses the pre-existing DATABASE_URL environment variable to generate the connection string.

To fully illustrate this process, I have included a new Employee data model with an associated API endpoint: /api/employees/. Unrelated to the MongoDb changes, I used a different way of structuring the backend code. I'd like us to discuss whether this is worth wider adoption.

Copy link
Member

@drubgrubby drubgrubby left a comment

Choose a reason for hiding this comment

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

Ran docker-compose build then docker-compose up

Got the following error:
Screen Shot 2021-10-17 at 7 02 22 PM

We tried to run it locally with npm run start:local and got the same error

We went to the client folder and ran npm install, and then ran npm start:local again and it worked.

Still doesn't work with docker-compose up. Seems like we probably have to add sometime to docker-compose.yml or something. Working on it.

@jasonwong26 -> if you have a sec and know the answer, that would be great. Otherwise, we'll work it out. Thanks.

@jasonwong26
Copy link
Contributor Author

Hi @drubgrubby,

Try deleting and recreating your docker containers - sounds like the docker environment is not pulling in the full list of modules.

@drubgrubby
Copy link
Member

I tried deleting and re-creating the docker containers. Sadly, still getting the same errors.

Screen Shot 2021-10-18 at 11 08 34 AM

I tried deleting the node_modules files and running docker-compose up, but that didn't work.
(The note_modules files were empty in the file structure after running docker-compose up, but I think that's proper).

I ran yarn install to recreate the node_module files just in case, but still nothing.

Putting this down for the moment.

@jasonwong26
Copy link
Contributor Author

Hi David,

Try the following:

  1. Delete all related docker images from your computer
  2. Run the following script: docker-compose build --no-cache --force-rm && docker-compose up

I suspect the issue is that you need to fully rebuild the docker images. The docker-compose up command will reuse the cached image by default, running the build command with the no-cache flag should hopefully resolve the issue.

FYI - I added this command to the package.json file as part of PR #762.

Hope this helps!

Copy link
Member

@jbubar jbubar left a comment

Choose a reason for hiding this comment

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

Got the same error

Screen Shot 2021-10-21 at 7 50 44 PM

But.. I did look into this pr and I am super impressed Jason! Thanks so much for doing all this work

@trillium
Copy link
Member

Closing this pull request as stale. If anyone disagrees feel free to reopen.

@trillium trillium closed this Mar 16, 2023
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

4 participants