Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadavGit committed Sep 21, 2023
2 parents 558a1f6 + 3fca137 commit d3a1a7f
Show file tree
Hide file tree
Showing 20 changed files with 501 additions and 274 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:
8 changes: 8 additions & 0 deletions helm-chart/sefaria-project/templates/configmap/nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ data:
proxy_pass http://varnish_upstream;
}
location /static/mobile/message-en.json {
return 301 ${STRAPI_LOCATION}/api/mobile-message;
}
location /static/mobile/message-he.json {
return 301 ${STRAPI_LOCATION}/api/mobile-message-he;
}
location /static/ {
access_log off;
alias /app/static/;
Expand Down
7 changes: 6 additions & 1 deletion helm-chart/sefaria-project/templates/rollout/nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ spec:
imagePullPolicy: Always
command: ["bash", "-c"]
# https://serverfault.com/questions/577370/how-can-i-use-environment-variables-in-nginx-conf
args: [ "envsubst '${ENV_NAME},${VARNISH_HOST},${SEARCH_HOST},${RELEASE_TAG}{{- if .Values.linker.enabled }},${LINKER_HOST}{{- end }}{{- if .Values.instrumentation.enabled }},${NGINX_VERSION}{{- end }}' < /conf/nginx.template.conf > /nginx.conf && exec nginx -c /nginx.conf -g 'daemon off;'" ]
args: [ "envsubst '${ENV_NAME},${VARNISH_HOST},${SEARCH_HOST},${RELEASE_TAG},${STRAPI_LOCATION}{{- if .Values.linker.enabled }},${LINKER_HOST}{{- end }}{{- if .Values.instrumentation.enabled }},${NGINX_VERSION}{{- end }}' < /conf/nginx.template.conf > /nginx.conf && exec nginx -c /nginx.conf -g 'daemon off;'" ]
ports:
- containerPort: 80
- containerPort: 443
Expand Down Expand Up @@ -96,6 +96,11 @@ spec:
value: "varnish-{{ .Values.deployEnv }}-{{ .Release.Revision }}"
- name: SEARCH_HOST
value: "{{ .Values.nginx.SEARCH_HOST }}"
- name: STRAPI_LOCATION
valueFrom:
secretKeyRef:
name: {{ .Values.secrets.localSettings.ref }}
key: STRAPI_LOCATION
{{- if .Values.linker.enabled }}
- name: LINKER_HOST
value: "linker-{{ .Values.deployEnv }}-{{ .Release.Revision }}"
Expand Down
11 changes: 2 additions & 9 deletions sefaria/client/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,9 @@ def format_link_object_for_client(link, with_text, ref, pos=None):
com["sourceVersion"] = {"title": link.versions[linkPos]["title"], "language": link.versions[linkPos].get("language", None)}
com["displayedText"] = link.displayedText[linkPos] # we only want source displayedText

compDate = getattr(linkRef.index, "compDate", None)
compDate = getattr(linkRef.index, "compDate", None) # default comp date to in the future
if compDate:
try:
com["compDate"] = int(compDate)
except ValueError:
com["compDate"] = 3000 # default comp date to in the future
try:
com["errorMargin"] = int(getattr(linkRef.index, "errorMargin", 0))
except ValueError:
com["errorMargin"] = 0
com["compDate"] = compDate

# Pad out the sections list, so that comparison between comment numbers are apples-to-apples
lsections = linkRef.sections[:] + [0] * (linkRef.index_node.depth - len(linkRef.sections))
Expand Down
28 changes: 10 additions & 18 deletions sefaria/model/garden.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,24 +441,16 @@ def _derive_metadata(self):
# Time
# This is similar to logic on Index.composition_time_period() refactor
if getattr(self, "start", None) is None or getattr(self, "end", None) is None:
if getattr(i, "compDate", None):
errorMargin = int(getattr(i, "errorMargin", 0))
self.startIsApprox = self.endIsApprox = errorMargin > 0

try:
year = int(getattr(i, "compDate"))
self.start = year - errorMargin
self.end = year + errorMargin
except ValueError as e:
years = getattr(i, "compDate").split("-")
if years[0] == "" and len(years) == 3: #Fix for first value being negative
years[0] = -int(years[1])
years[1] = int(years[2])
self.start = int(years[0]) - errorMargin
self.end = int(years[1]) + errorMargin

elif author and author.mostAccurateTimePeriod():
tp = author.mostAccurateTimePeriod()
years = getattr(i, 'compDate', [])
if years and len(years) > 0:
self.startIsApprox = self.endIsApprox = getattr(i, "hasErrorMargin", False)
if len(years) > 1:
self.start = years[0]
self.end = years[1]
else:
self.start = self.end = years[0]
elif author and author.most_accurate_time_period():
tp = author.most_accurate_time_period()
self.start = tp.start
self.end = tp.end
self.startIsApprox = tp.startIsApprox
Expand Down
5 changes: 5 additions & 0 deletions sefaria/model/tests/text_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ def test_invalid_index_save_no_category():
assert "You must create category Mishnah/Commentary/Bartenura/Gargamel before adding texts to it." in str(e_info.value)
assert model.IndexSet({"title": title}).count() == 0

def test_best_time_period():
i = model.library.get_index("Rashi on Genesis")
assert i.best_time_period().period_string('en') == ' (c.1075 - c.1105 CE)'
i.compDate = None
assert i.best_time_period().period_string('en') == ' (1040 - 1105 CE)' # now that compDate is None, period_string should return Rashi's birth to death years

def test_invalid_index_save_no_hebrew_collective_title():
title = 'Bartenura (The Next Generation)'
Expand Down
Loading

0 comments on commit d3a1a7f

Please sign in to comment.