SushantGautam commited on
Commit
e730de6
·
1 Parent(s): f795f69

Refactor WSGI and manage.py to conditionally download and copy db.sqlite3 when running inside Docker

Browse files
Files changed (3) hide show
  1. BridgeMentor/wsgi.py +17 -15
  2. Dockerfile +1 -0
  3. manage.py +18 -0
BridgeMentor/wsgi.py CHANGED
@@ -9,22 +9,24 @@ https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
9
 
10
  import os
11
  import shutil
12
-
13
- from huggingface_hub import hf_hub_download
14
  from django.core.wsgi import get_wsgi_application
15
- custom_cache_dir = os.path.expanduser("/app/.cache/huggingface")
16
-
17
- file_path = hf_hub_download(
18
- repo_id="SushantGautam/BridgeMentor",
19
- filename="db.sqlite3",
20
- repo_type="dataset",
21
- cache_dir=custom_cache_dir
22
- )
23
- print(f"Downloaded to: {file_path}")
24
- destination_path = os.path.join(os.getcwd(), "db.sqlite3")
25
- shutil.copy(file_path, destination_path)
26
-
27
- print(f"db.sqlite3 Copied to current directory: {destination_path}")
 
 
 
 
28
 
29
 
30
  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BridgeMentor.settings')
 
9
 
10
  import os
11
  import shutil
 
 
12
  from django.core.wsgi import get_wsgi_application
13
+
14
+
15
+ if os.environ.get('INSIDEDOCKER'):
16
+ from huggingface_hub import hf_hub_download
17
+
18
+ custom_cache_dir = os.path.expanduser("/app/.cache/huggingface")
19
+ file_path = hf_hub_download(
20
+ repo_id="SushantGautam/BridgeMentor",
21
+ filename="db.sqlite3",
22
+ repo_type="dataset",
23
+ cache_dir=custom_cache_dir
24
+ )
25
+ print(f"Downloaded to: {file_path}")
26
+ destination_path = os.path.join(os.getcwd(), "db.sqlite3")
27
+ shutil.copy(file_path, destination_path)
28
+
29
+ print(f"db.sqlite3 Copied to current directory: {destination_path}")
30
 
31
 
32
  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BridgeMentor.settings')
Dockerfile CHANGED
@@ -1,6 +1,7 @@
1
  # Use official Python image
2
  FROM python:3.11-slim
3
 
 
4
  # Install system dependencies
5
  RUN apt-get update && apt-get install -y \
6
  default-libmysqlclient-dev \
 
1
  # Use official Python image
2
  FROM python:3.11-slim
3
 
4
+ ENV INSIDEDOCKER 1
5
  # Install system dependencies
6
  RUN apt-get update && apt-get install -y \
7
  default-libmysqlclient-dev \
manage.py CHANGED
@@ -3,6 +3,24 @@
3
  import os
4
  import sys
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  def main():
7
  """Run administrative tasks."""
8
  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BridgeMentor.settings')
 
3
  import os
4
  import sys
5
 
6
+ import shutil
7
+
8
+ if os.environ.get('INSIDEDOCKER'):
9
+ from huggingface_hub import hf_hub_download
10
+ custom_cache_dir = os.path.expanduser("/app/.cache/huggingface")
11
+
12
+ file_path = hf_hub_download(
13
+ repo_id="SushantGautam/BridgeMentor",
14
+ filename="db.sqlite3",
15
+ repo_type="dataset",
16
+ cache_dir=custom_cache_dir
17
+ )
18
+ print(f"Downloaded to: {file_path}")
19
+ destination_path = os.path.join(os.getcwd(), "db.sqlite3")
20
+ shutil.copy(file_path, destination_path)
21
+ print(f"db.sqlite3 Copied to current directory: {destination_path}")
22
+
23
+
24
  def main():
25
  """Run administrative tasks."""
26
  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BridgeMentor.settings')