Skip to content

Commit

Permalink
docker_file_update
Browse files Browse the repository at this point in the history
  • Loading branch information
Lungsangg committed Nov 21, 2024
1 parent afadb58 commit bf52a55
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
35 changes: 19 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ COPY ./sefaria/local_settings.py ./sefaria/local_settings.py
COPY requirements.txt ./
COPY package*.json ./

# Install global Python and Node.js dependencies
RUN pip install -r requirements.txt
RUN npm install --unsafe-perm

Expand All @@ -20,11 +21,20 @@ COPY ./static/js ./static/js
RUN npm run setup
RUN npm run build-prod

# Install system dependencies for Pillow and Python 3.12
# Install system dependencies for building Python 3.12
RUN apt-get update && apt-get install -y \
software-properties-common

# Download and build Python 3.12 from source
software-properties-common \
wget \
build-essential \
zlib1g-dev \
libssl-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
libffi-dev && \
apt-get clean

# Download and build Python 3.12
RUN wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz && \
tar xvf Python-3.12.0.tgz && \
cd Python-3.12.0 && \
Expand All @@ -37,22 +47,15 @@ RUN wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz && \
RUN python3.12 --version

# Create a virtual environment with Python 3.12
ENV VIRTUAL_ENV="/env"
RUN python3.12 -m venv $VIRTUAL_ENV

# Install Pillow 11 in the virtual environment
RUN $VIRTUAL_ENV/bin/pip install --upgrade pip && \
$VIRTUAL_ENV/bin/pip install Pillow==11.0.0
RUN python3.12 -m venv /env && \
/env/bin/pip install --upgrade pip && \
/env/bin/pip install Pillow==11.0.0

# Copy application source code
COPY . ./

# Ensure the virtual environment is used for the application
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN echo "PATH is set to: $PATH"

# Run Django migrations and start the server
CMD ["bash", "-c", "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"]

# Expose the port that the Django server will listen on
EXPOSE 8000
# Expose the port for the Django application
EXPOSE 8000
Binary file modified output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 2 additions & 6 deletions sefaria/image_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,12 @@ def make_img_http_response(text, category, ref_str, lang, platform):
env = os.environ.copy()
env['PECHA_TEXT'] = text
env['PECHA_REF'] = ref_str

# for local testing
# subprocess.run(["/home/lungsang/Project/Pecha.org/env/bin/python3", "sefaria/pecha_text_image.py", "output.png"], env=env)

# for production
# Dynamically resolve the Python path
python_path = os.path.join(env.get("VIRTUAL_ENV", "/env"), "bin", "python3")

# Run the script
subprocess.run([python_path, "sefaria/pecha_text_image.py", "output.png"], env=env)
subprocess.run(["/env/bin/python3", "sefaria/pecha_text_image.py", "output.png"], env=env)


img = Image.open("output.png")
Expand Down

0 comments on commit bf52a55

Please sign in to comment.