moviegeek icon indicating copy to clipboard operation
moviegeek copied to clipboard

Run Moviegeek as a containerized app in Docker

Open veekaybee opened this issue 3 years ago • 6 comments

Hi Kim!

I recently started working through Practical Recommender Systems as part of my work at Tumblr (I'm really enjoying it so far, thank you for the book!) and realized that the install process for the app could probably be made a bit more efficient so people don't encounter system incompatibilities or errors.

Right now, there are multiple steps that the user needs to run manually, in addition to manually generating the API key through the Movie Database, to get the app up and running. There's a way the user install experience can be a bit better.

The Issue

The install process for MovieGeek involved a lot of manual moving parts that made it easy to miss a step and incur version or operating system incompatibilities, even using an isolated virtual environment. Additionally, it took over 10 minutes to install locally. Putting both the Django database and the web app into a docker-compose file that starts and runs the two services within its own Docker container will solve the issue. I also made a few other small tweaks to optimize data imports and use libraries like requests instead of urlllib to make starting up easier.

What Was Changed

  • [ ] Created a Dockerfile that installs a plain vanilla version of Python 3.6 and requirements.txt and moves all app work inside the Docker container
  • [ ] Created a docker-compose.yml file that runs the Dockerfile, creates a db and web services that start up together, and then automatically performs the Django migrations (https://github.com/practical-recommender-systems/moviegeek/compare/master...veekaybee:dockerize?expand=1#diff-e45e45baeda1c1e73482975a664062aa56f20c03dd9d64a827aba57775bed0d3R17) and starts the web server with mapped environment variables to Postgres in the db service
  • [ ] modified the populate_moviegeek.py and populate_ratings.py scripts to load data into Postgres more quickly using bulk_uploads (https://github.com/practical-recommender-systems/moviegeek/compare/master...veekaybee:dockerize?expand=1#diff-012d668550df5c86490e59e735fc773a34f64084aa0a60ca75e20f28622cb99bR45) and output the tqdm logs to docker-logs for visibility during install
  • [ ] modified the populate scripts to use the more standard requests instead of urrllib
  • [ ] started to implement type annotations in the populate scripts
  • [ ] modified settings.py to expose allowed hosts and specify the DB name and password mapped in the docker-compose.yml file
  • [ ] Changed the requirements.txt dependency to use the latest version of psycopg2-binary compatible with the project and Docker
  • [ ] Changes to the README to reflect the new install process, as well as some clarifications on how to generate the API key

How to Test the Changes

  1. Pull this branch (dockerize)
  2. Add your API key to the .prs file as before
  3. Install Docker Desktop if you don't have it yet
  4. Run docker-compose up to start the install process. Follow other instructions on the README to restart the image.
  5. Go to http://0.0.0.0:8000/ and click around in the app. It should have the same functionality as described in the book: loading all images, navigating all genres, 'buy' generates a bookmark for a movie, and the analytics module shows logging tracking events.

veekaybee avatar Sep 01 '21 23:09 veekaybee

Hey @kimfalk bump on this. Wanted to make sure you saw it and had a chance to reply with any questions/concerns. Thanks!

veekaybee avatar Sep 18 '21 15:09 veekaybee

I was just about to offer a Dockerize'd PR myself, @veekaybee. Fantastic work! :)

jasonsalas avatar Sep 19 '21 19:09 jasonsalas

He @veekaybee,

Thank you for your work, I have a dockerized version to push the master branch myself. Similar to the one in the https://github.com/kimfalk/live-project. I will push that one of these days, and then I will go through your PR.

kimfalk avatar Sep 20 '21 08:09 kimfalk

Great, thanks @kimfalk!

veekaybee avatar Sep 20 '21 12:09 veekaybee

Hi @veekaybee,

One of these days was a bit optimistic I guess, but now I have added the docker config. Let me know if you still think something is missing.

kimfalk avatar Feb 13 '22 14:02 kimfalk

That's awesome, @kimfalk. Excited to try it out. 😄

veekaybee avatar Feb 18 '22 20:02 veekaybee