bluewhale2025 commited on
Commit
3c83f33
·
1 Parent(s): 9d14f12

Fix permission issues and update directory structure

Browse files
Files changed (2) hide show
  1. Dockerfile +21 -12
  2. app.py +12 -6
Dockerfile CHANGED
@@ -1,6 +1,14 @@
1
  FROM python:3.9-slim
2
 
3
- WORKDIR /app
 
 
 
 
 
 
 
 
4
 
5
  # Install system dependencies
6
  RUN apt-get update && apt-get install -y \
@@ -18,30 +26,31 @@ RUN apt-get update && apt-get install -y \
18
 
19
  # Set environment variables
20
  ENV PYTHONUNBUFFERED=1
21
- ENV NLTK_DATA=/app/nltk_data
22
- ENV HUGGINGFACE_HUB_CACHE=/app/huggingface_cache
23
- ENV UPLOAD_FOLDER=/app/data/uploads
 
 
 
 
 
24
 
25
  # Copy requirements first to leverage Docker cache
26
- COPY requirements.txt .
27
 
28
  # Install Python dependencies
29
  RUN pip install --no-cache-dir -r requirements.txt
30
 
31
  # Copy application files
32
- COPY . .
33
 
34
  # Make scripts executable
35
- RUN chmod +x /app/start.sh /app/download_nltk_data.py
36
-
37
- # Switch to non-root user
38
- RUN useradd -m -u 1000 user && \
39
- chown -R user:user /app
40
 
41
  USER user
42
 
43
  # Set working directory
44
- WORKDIR /app
45
 
46
  # Expose the port the app runs on
47
  EXPOSE 7860
 
1
  FROM python:3.9-slim
2
 
3
+ # Create app directory and set permissions
4
+ RUN mkdir -p /home/user/app && \
5
+ chmod -R 777 /home/user && \
6
+ mkdir -p /home/user/app/data/uploads && \
7
+ mkdir -p /home/user/app/data/processed && \
8
+ mkdir -p /home/user/app/nltk_data && \
9
+ chmod -R 777 /home/user/app
10
+
11
+ WORKDIR /home/user/app
12
 
13
  # Install system dependencies
14
  RUN apt-get update && apt-get install -y \
 
26
 
27
  # Set environment variables
28
  ENV PYTHONUNBUFFERED=1
29
+ ENV NLTK_DATA=/home/user/app/nltk_data
30
+ ENV HUGGINGFACE_HUB_CACHE=/home/user/app/huggingface_cache
31
+ ENV UPLOAD_FOLDER=/home/user/app/data/uploads
32
+ ENV PROCESSED_FOLDER=/home/user/app/data/processed
33
+
34
+ # Create a non-root user and switch to it
35
+ RUN useradd -m -u 1000 user && \
36
+ chown -R user:user /home/user
37
 
38
  # Copy requirements first to leverage Docker cache
39
+ COPY --chown=user:user requirements.txt .
40
 
41
  # Install Python dependencies
42
  RUN pip install --no-cache-dir -r requirements.txt
43
 
44
  # Copy application files
45
+ COPY --chown=user:user . .
46
 
47
  # Make scripts executable
48
+ RUN chmod +x /home/user/app/start.sh /home/user/app/download_nltk_data.py
 
 
 
 
49
 
50
  USER user
51
 
52
  # Set working directory
53
+ WORKDIR /home/user/app
54
 
55
  # Expose the port the app runs on
56
  EXPOSE 7860
app.py CHANGED
@@ -39,19 +39,25 @@ app.add_middleware(
39
  )
40
 
41
  # Directory configuration
42
- UPLOAD_DIR = Path(os.getenv("UPLOAD_FOLDER", "/app/data/uploads"))
43
- PROCESSED_DIR = Path(os.getenv("PROCESSED_FOLDER", "/app/data/processed"))
 
44
  NLTK_DATA_DIR = Path(os.getenv("NLTK_DATA", "/app/nltk_data"))
45
 
46
  # Ensure directories exist with proper permissions
47
- for directory in [UPLOAD_DIR, PROCESSED_DIR, NLTK_DATA_DIR]:
48
  try:
49
  directory.mkdir(parents=True, exist_ok=True)
 
 
 
 
 
 
 
 
50
  os.chmod(directory, 0o755)
51
  logger.info(f"Ensured directory exists: {directory}")
52
- except Exception as e:
53
- logger.error(f"Failed to create directory {directory}: {e}")
54
- raise
55
 
56
  # Import modules after environment is set up
57
  try:
 
39
  )
40
 
41
  # Directory configuration
42
+ BASE_DIR = Path("/home/user/app/data")
43
+ UPLOAD_DIR = BASE_DIR / "uploads"
44
+ PROCESSED_DIR = BASE_DIR / "processed"
45
  NLTK_DATA_DIR = Path(os.getenv("NLTK_DATA", "/app/nltk_data"))
46
 
47
  # Ensure directories exist with proper permissions
48
+ for directory in [BASE_DIR, UPLOAD_DIR, PROCESSED_DIR]:
49
  try:
50
  directory.mkdir(parents=True, exist_ok=True)
51
+ # Set permissions to 0o777 (read/write/execute for all)
52
+ directory.chmod(0o777)
53
+ logger.info(f"Created directory: {directory}")
54
+ except Exception as e:
55
+ logger.error(f"Failed to create directory {directory}: {str(e)}")
56
+ # Try to continue if directory creation fails
57
+ if not directory.exists():
58
+ raise
59
  os.chmod(directory, 0o755)
60
  logger.info(f"Ensured directory exists: {directory}")
 
 
 
61
 
62
  # Import modules after environment is set up
63
  try: