Skip to content

Commit

Permalink
Merge pull request #52 from practical-recommender-systems/add-docker
Browse files Browse the repository at this point in the history
Add docker
  • Loading branch information
kimfalk authored Feb 13, 2022
2 parents e7ba6c7 + ac67563 commit 0b6bfbd
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 43 deletions.
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.8
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt

COPY . /code/

115 changes: 79 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,86 @@
# The MovieGEEK Installation Guide

The MovieGEEK is a website implemented to accompany my book, Practical Recommender Systems.
It is used in the book to show how recommender systems work and how you can implement them.
The book describes how the algorithms work and provides more detail into how the site works.

The website is not intended as a standalone tutorial or a plug-and-play website for you to install
and use for your own content.
The MovieGEEK is a website initially implemented to accompany my book, Practical Recommender Systems.
However, this folder is used for the manning LiveProject, which is currently in MEAP.

The website is not intended as a standalone tutorial or a plug-and-play website for you to install and
use for your content.

## Thanks!
This site would not be working if it wasn’t for the [MovieTweetings](https://github.com/sidooms/MovieTweetings)
dataset and the poster images provided by the [themoviedb.org](https://www.themoviedb.org) API.
I wish to extend a big thanks to both of them for all their work.

## Project Setup
In the following, we will go through the steps to set up this site.

The first thing is to download this repository. Secondly, create a themoviedb.org ID needed to run the website.

### Download source code
You have two choices for downloading the source code – downloading a zip file of the source code or using Git.

* *Downloading a zip file*

From the main [MovieGEEK directory on GitHub](https://github.com/practical-recommender-systems/moviegeek),
click the green “Clone or download” button and choose to download a zip file to your computer.

* *Using Git*

Clone this repository or create a fork in your GitHub, and then clone that instead. The following command
will create a copy on your computer.
`> git clone https://github.com/kimfalk/live-project.git`


### Create an ID for themoviedb.org

You have to create an ID with themoviedb.org to use its pictures.

* Go to [https://www.themoviedb.org/account/signup](https://www.themoviedb.org/account/signup)
* Sign up
* Login, go to your account settings and [create an API](https://www.themoviedb.org/settings/api). You can access
settings by clicking the avatar in the upper right-hand corner (the default is a blue circle with a white logo in it).
Then you’ll see settings on the left.
* Create a file in the moviegeek directory called ".prs"
* Open .prs and add { "themoviedb_apikey": <INSERT YOUR APIKEY HERE>}
Remember to remove the "<" and ">" When you are finished, the file contents should look something like
{"themoviedb_apikey": "6d88c9a24b1bc9a60b374d3fe2cd92ac"}


## Running the site

There are two ways to run the site:
* [use Docker container](#run-site-in-a-docker-container)
* [run it in a local virtual environment](#run-site-in-a-virtualenv).

I recommend the first option, as the docker container way is faster and requires less setup.

### Run site in a Docker container

As a new addition to this site, this repo will also have a docker container, which should make it
easier to start.

Fire up the website simply by first building the docker container

```shell script
docker-compose build web
```
Create the database and download and import data: (This takes some time)
```shell script
./db-migrate.sh
```

And then start it executing the following:

```shell script
docker-compose up web
```

NB: If the website responds with an error about a ```.prs``` file missing, its because you skipped
the section about creating a themoviedb.org id. [link](#create-an-id-for-themoviedborg)

(to close it again by stopping the process (Cltr+C))

### Run site in a virtualenv.

### Install Python 3.x

Expand All @@ -29,20 +97,6 @@ Windows users, because installing Python and its packages can be tricky for you,
If you want to, you can use the Windows instructions in the Hitchhiker’s Guide,
but I have always used the Anaconda package.

## Download source code
You have two choices for downloading the source code – downloading a zip file of the source code or using Git.

* *Downloading a zip file*

From the main [MovieGEEK directory on GitHub](https://github.com/practical-recommender-systems/moviegeek),
click the green “Clone or download” button and choose to download a zip file to your computer.

* *Using Git*

Clone this repository or create a fork in your GitHub, and then clone that instead. The following command
will create a copy on your computer.
`> git clone https://github.com/practical-recommender-systems/moviegeek.git`

## Create a virtual environment for the project

Before you run the code, create a virtual environment. The Hitchhiker’s Guide provides a
Expand All @@ -61,13 +115,13 @@ commands (Anaconda users, please use the Anaconda-specific commands):

* *Non-Anaconda users*:
```bash
> cd moviegeek
> cd live-project
> virtualenv -p python3 prs
> source prs/bin/activate
```
* *Anaconda users*:
```bash
> cd moviegeek
> cd live-project
> conda create -n prs python=3.6
> conda activate prs
```
Expand Down Expand Up @@ -174,20 +228,6 @@ Everyone, run these commands to populate the databases.
```
WARNING: This might take some time.

### Create an ID for themoviedb.org

You have to create an ID with themoviedb.org to use its pictures.

* Go to [https://www.themoviedb.org/account/signup](https://www.themoviedb.org/account/signup)
* Sign up
* Login, go to your account settings and [create an API](https://www.themoviedb.org/settings/api). You can access
settings by clicking the avatar in the upper right-hand corner (the default is a blue circle with a white logo in it).
Then you’ll see settings on the left.
* Create a file in the moviegeek directory called ".prs"
* Open .prs and add { "themoviedb_apikey": <INSERT YOUR APIKEY HERE>}
Remember to remove the "<" and ">" When you are finished, the file contents should look something like
{"themoviedb_apikey": "6d88c9a24b1bc9a60b374d3fe2cd92ac"}

### Start the web server
To start the development server, run this command:
```bash
Expand All @@ -197,6 +237,9 @@ Running the server like this will make the website available [http://127.0.0.1:8

WARNING: Other applications also use this port so you might need to try out 8001 instead.

NB: If the website responds with an error about a ```.prs``` file missing, its because you skipped
the section about creating a themoviedb.org id. [link](#create-an-id-for-themoviedborg)

## Closing down
When you are finished running the project you can close it down doing the following steps, or simply close the
terminal where the server is running.
Expand Down
6 changes: 6 additions & 0 deletions db-migrate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

docker-compose run web python manage.py makemigrations --noinput
docker-compose run web python manage.py migrate --run-syncdb

docker-compose run web python populate_moviegeek.py
docker-compose run web python populate_ratings.py
49 changes: 49 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: '3'

services:
db:
image: postgres
expose:
- "5432"
networks:
- djangonetwork
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=pw1234
- POSTGRES_DB=moviegeeks
web:
restart: always
build: .
command: python manage.py runserver 0.0.0.0:8010
volumes:
- .:/code
ports:
- "8010:8010"
networks:
- djangonetwork
links:
- db:db
depends_on:
- db

build-recs:
build: .
command: python -m builder.bpr_calculator

evaluate:
restart: always
build: .
command: python -m evaluator.evaluation_runner -ltr
volumes:
- .:/code
depends_on:
- db
notebook:
build: .
command: jupyter notebook
ports:
- "8888:8888"

networks:
djangonetwork:
driver: bridge
2 changes: 1 addition & 1 deletion prs_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['0.0.0.0']


# Application definition
Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ idna==2.7
jmespath==0.9.3
kiwisolver==1.0.1
matplotlib==3.0.2
numpy==1.17.3
pandas==0.23.4
numpy==1.22.2
pandas==1.4.1
packaging==16.8
pyparsing==2.3.0
python-dateutil==2.7.5
pytz==2018.7
python-dateutil==2.8.2
pytz==2021.3
requests==2.20.1
s3transfer==0.1.13
scipy==1.1.0
scipy==1.8.0
seaborn==0.8.1
six==1.11.0
sklearn==0.0
Expand All @@ -31,6 +31,6 @@ stop-words==2015.2.23.1
tqdm==4.28.1
urllib3==1.24.2
pyLDAvis==2.1.1
psycopg2==2.7.6.1



0 comments on commit 0b6bfbd

Please sign in to comment.