Skip to content

Commit

Permalink
Merge pull request #1626 from Sefaria/add-docker-compose
Browse files Browse the repository at this point in the history
chore(setup): add docker compose file to facilitate easy setup
  • Loading branch information
akiva10b committed Sep 19, 2023
2 parents ef374c0 + 2517dae commit e8c28c0
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Use an official Python runtime as a parent image
FROM python:3.7-slim

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install psycopg2 dependencies
RUN apt-get update && apt-get install -y libpq-dev

# Install gcc
RUN apt-get update && apt-get install -y gcc

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt

# Make port 8000 available to the world outside this container
EXPOSE 8000

# Define environment variable
ENV NAME Sefaria-Project

# Run app.py when the container launches
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
80 changes: 80 additions & 0 deletions README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,87 @@ First clone the Sefaria-Project repository to a directory on your computer, then
*Note for macOS users - Install `Homebrew`:*

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"


There are two methods with which you can run the Sefaria-Project, docker-compose and local install

#### Run with docker-compose
##### 1) Install Docker and Docker Compose

Follow the instructions [here](https://docs.docker.com/docker-for-mac/install/) to install Docker and [here](https://docs.docker.com/compose/install/) to install Docker Compose.

##### 2) Run the project
In your terminal run:

docker-compose up

This will build the project and run it. You should now have all the proper services set up, lets add some texts.

##### 3) Connect to mongo and add texts:
Connect to mongo running on port 27018. We use 27018 instead of the standard port 27017 to avoid conflicts with any mongo instance you may already have running.

Follow instructions in section 8 below to restore the mongo dump.


##### 4) Update your local settings file:
Copy the local settings file:

cp sefaria/local_settings_example.py sefaria/local_settings.py

Replace the following values:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'sefaria',
'USER': 'admin',
'PASSWORD': 'admin',
'HOST': 'postgres',
'PORT': '',
}
}


MONGO_HOST = "db"

Optionally, you can replace the cache values as well:

MULTISERVER_REDIS_SERVER = "cache"
REDIS_HOST = "cache"

and the respective values in CACHES


##### 5) Connect to the django container and run migrations:
In a new terminal window run:

docker exec -it sefaria-project_web_1 bash

This will connect you to the django container. Now run:

python manage.py migrate

##### 6) Run webpack:
In a new terminal window run:

docker exec -it sefaria-project-node-1 bash

This will connect you to the django container. Now run:

npm run build-client

or

npm run watch-client


##### 7) Visit the site:
In your browser go to http://localhost:8000

If the server isn't running, you may need to run `docker-compose up` again.


#### Run locally
#### 1) Install Python 3.7

*We Recommend using the latest Python 3.7 as opposed to later versions of Python (esp 3.10 and up) since it has been known to cause some compatability issues. These are solvable, but for an easier install experience, we currently recommend 3.7*
Expand Down
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:
web:
build: .
ports:
- "8000:8000"
volumes:
- .:/app
depends_on:
- db
- cache
- postgres

db:
image: "mongo:4.4"
ports:
- "27018:27017"
volumes:
- mongo-data:/data/db

cache:
image: "redis:latest"
ports:
- "6379:6379"

node:
image: "node:latest"
working_dir: /app
volumes:
- .:/app
command: npm start
ports:
- "3000:3000"

postgres:
image: "postgres:latest"
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: admin
POSTGRES_DB: sefaria
ports:
- "5433:5432"
volumes:
- postgres-data:/var/lib/postgresql/sefaria_data

volumes:
mongo-data:
postgres-data:

0 comments on commit e8c28c0

Please sign in to comment.