fokan commited on
Commit
ecbfb06
·
verified ·
1 Parent(s): b3cb89b

Upload 42 files

Browse files
Files changed (6) hide show
  1. .dockerignore +1 -1
  2. Dockerfile +18 -7
  3. packages.txt +2 -0
  4. test_docker_build.ps1 +26 -0
  5. test_docker_build.sh +27 -0
  6. verify_files.py +39 -2
.dockerignore CHANGED
@@ -40,7 +40,7 @@ temp/
40
  *.tmp
41
 
42
  # Ignore documentation files that aren't needed in the container
 
43
  *.md
44
- *.txt
45
  *.pdf
46
  *.docx
 
40
  *.tmp
41
 
42
  # Ignore documentation files that aren't needed in the container
43
+ # But keep requirements.txt and packages.txt
44
  *.md
 
45
  *.pdf
46
  *.docx
Dockerfile CHANGED
@@ -6,14 +6,20 @@ ENV DEBIAN_FRONTEND=noninteractive
6
  ENV LANG=ar_SA.UTF-8
7
  ENV LC_ALL=ar_SA.UTF-8
8
  ENV PYTHONUNBUFFERED=1
 
 
 
 
9
 
10
- # Install system dependencies including Arabic fonts
11
  RUN apt-get update && apt-get install -y \
12
  python3 \
13
  python3-pip \
14
  libreoffice \
15
  libreoffice-writer \
16
  libreoffice-l10n-ar \
 
 
17
  fonts-liberation \
18
  fonts-liberation2 \
19
  fonts-dejavu \
@@ -40,22 +46,27 @@ RUN fc-cache -fv
40
  # Set working directory
41
  WORKDIR /app
42
 
43
- # Create necessary directories
44
- RUN mkdir -p /tmp/libreoffice_conversion
 
 
 
 
 
45
 
46
  # Create static directory
47
  RUN mkdir -p static
48
 
49
- # Copy all files in a single command to avoid layering issues
50
  COPY . .
51
 
52
- # Install Python dependencies
53
- RUN pip3 install --no-cache-dir -r requirements.txt
54
-
55
  # Setup additional Arabic fonts
56
  RUN chmod +x arabic_fonts_setup.sh && \
57
  ./arabic_fonts_setup.sh
58
 
 
 
 
59
  # Expose port (Hugging Face Spaces requires port 7860)
60
  EXPOSE 7860
61
 
 
6
  ENV LANG=ar_SA.UTF-8
7
  ENV LC_ALL=ar_SA.UTF-8
8
  ENV PYTHONUNBUFFERED=1
9
+ # Set environment variables for LibreOffice
10
+ ENV HOME=/tmp
11
+ ENV TMPDIR=/tmp
12
+ ENV XDG_CONFIG_HOME=/tmp/.config
13
 
14
+ # Install system dependencies including Arabic fonts and Java for LibreOffice
15
  RUN apt-get update && apt-get install -y \
16
  python3 \
17
  python3-pip \
18
  libreoffice \
19
  libreoffice-writer \
20
  libreoffice-l10n-ar \
21
+ libreoffice-java-common \
22
+ openjdk-11-jre-headless \
23
  fonts-liberation \
24
  fonts-liberation2 \
25
  fonts-dejavu \
 
46
  # Set working directory
47
  WORKDIR /app
48
 
49
+ # Copy requirements first to leverage Docker cache
50
+ COPY requirements.txt .
51
+ RUN pip3 install --no-cache-dir -r requirements.txt
52
+
53
+ # Create necessary directories with proper permissions
54
+ RUN mkdir -p /tmp/libreoffice_conversion /tmp/.config && \
55
+ chmod -R 777 /tmp
56
 
57
  # Create static directory
58
  RUN mkdir -p static
59
 
60
+ # Copy all remaining files
61
  COPY . .
62
 
 
 
 
63
  # Setup additional Arabic fonts
64
  RUN chmod +x arabic_fonts_setup.sh && \
65
  ./arabic_fonts_setup.sh
66
 
67
+ # Pre-initialize LibreOffice to avoid first-run errors
68
+ RUN libreoffice --headless --version || true
69
+
70
  # Expose port (Hugging Face Spaces requires port 7860)
71
  EXPOSE 7860
72
 
packages.txt CHANGED
@@ -1,6 +1,8 @@
1
  libreoffice
2
  libreoffice-writer
3
  libreoffice-l10n-ar
 
 
4
  fonts-liberation
5
  fonts-liberation2
6
  fonts-dejavu
 
1
  libreoffice
2
  libreoffice-writer
3
  libreoffice-l10n-ar
4
+ libreoffice-java-common
5
+ openjdk-11-jre-headless
6
  fonts-liberation
7
  fonts-liberation2
8
  fonts-dejavu
test_docker_build.ps1 ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Simple script to test Docker build process
2
+
3
+ Write-Host "Testing Docker build process..."
4
+
5
+ # Create a simple test Dockerfile
6
+ Set-Content -Path "test.Dockerfile" -Value @'
7
+ FROM ubuntu:22.04
8
+ WORKDIR /app
9
+ COPY . .
10
+ RUN ls -la
11
+ '@
12
+
13
+ Write-Host "Building test image..."
14
+ docker build -f test.Dockerfile -t test-build .
15
+
16
+ if ($LASTEXITCODE -eq 0) {
17
+ Write-Host "✅ Test build successful!"
18
+ # Clean up
19
+ docker rmi test-build
20
+ Remove-Item test.Dockerfile
21
+ } else {
22
+ Write-Host "❌ Test build failed!"
23
+ # Clean up
24
+ Remove-Item test.Dockerfile
25
+ exit 1
26
+ }
test_docker_build.sh ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Simple script to test Docker build process
3
+
4
+ echo "Testing Docker build process..."
5
+
6
+ # Create a simple test Dockerfile
7
+ cat > test.Dockerfile << 'EOF'
8
+ FROM ubuntu:22.04
9
+ WORKDIR /app
10
+ COPY . .
11
+ RUN ls -la
12
+ EOF
13
+
14
+ echo "Building test image..."
15
+ docker build -f test.Dockerfile -t test-build .
16
+
17
+ if [ $? -eq 0 ]; then
18
+ echo "✅ Test build successful!"
19
+ # Clean up
20
+ docker rmi test-build
21
+ rm test.Dockerfile
22
+ else
23
+ echo "❌ Test build failed!"
24
+ # Clean up
25
+ rm test.Dockerfile
26
+ exit 1
27
+ fi
verify_files.py CHANGED
@@ -16,10 +16,40 @@ def check_file_exists(filepath, description):
16
  print(f"❌ {description} - Missing")
17
  return False
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  def main():
20
  """Main function to verify all required files"""
21
  print("Verifying required files for Docker build...")
22
 
 
 
 
 
 
23
  # List of required files
24
  required_files = [
25
  ("requirements.txt", "Python dependencies file"),
@@ -38,6 +68,10 @@ def main():
38
  for filepath, description in required_files:
39
  if not check_file_exists(filepath, description):
40
  all_files_found = False
 
 
 
 
41
 
42
  # Check if static directory exists
43
  if os.path.exists("static") and os.path.isdir("static"):
@@ -45,6 +79,9 @@ def main():
45
  # Check if index.html exists in static directory
46
  if os.path.exists("static/index.html"):
47
  print("✅ Static index.html - Found")
 
 
 
48
  else:
49
  print("❌ Static index.html - Missing")
50
  all_files_found = False
@@ -54,10 +91,10 @@ def main():
54
 
55
  # Print summary
56
  if all_files_found:
57
- print("\n🎉 All required files are present!")
58
  return 0
59
  else:
60
- print("\n💥 Some required files are missing!")
61
  return 1
62
 
63
  if __name__ == "__main__":
 
16
  print(f"❌ {description} - Missing")
17
  return False
18
 
19
+ def check_file_not_ignored(filepath, description, dockerignore_patterns):
20
+ """Check if a file would be ignored by .dockerignore"""
21
+ import fnmatch
22
+
23
+ for pattern in dockerignore_patterns:
24
+ if fnmatch.fnmatch(filepath, pattern):
25
+ print(f"❌ {description} - Would be ignored by .dockerignore (pattern: {pattern})")
26
+ return False
27
+
28
+ print(f"✅ {description} - Not ignored by .dockerignore")
29
+ return True
30
+
31
+ def read_dockerignore():
32
+ """Read .dockerignore file and return patterns"""
33
+ patterns = []
34
+ try:
35
+ with open(".dockerignore", "r") as f:
36
+ for line in f:
37
+ line = line.strip()
38
+ if line and not line.startswith("#"):
39
+ patterns.append(line)
40
+ except FileNotFoundError:
41
+ print("⚠️ .dockerignore not found")
42
+ return patterns
43
+
44
  def main():
45
  """Main function to verify all required files"""
46
  print("Verifying required files for Docker build...")
47
 
48
+ # Read .dockerignore patterns
49
+ dockerignore_patterns = read_dockerignore()
50
+ if dockerignore_patterns:
51
+ print(f"Found {len(dockerignore_patterns)} patterns in .dockerignore")
52
+
53
  # List of required files
54
  required_files = [
55
  ("requirements.txt", "Python dependencies file"),
 
68
  for filepath, description in required_files:
69
  if not check_file_exists(filepath, description):
70
  all_files_found = False
71
+ elif dockerignore_patterns:
72
+ # Check if file would be ignored
73
+ if not check_file_not_ignored(filepath, description, dockerignore_patterns):
74
+ all_files_found = False
75
 
76
  # Check if static directory exists
77
  if os.path.exists("static") and os.path.isdir("static"):
 
79
  # Check if index.html exists in static directory
80
  if os.path.exists("static/index.html"):
81
  print("✅ Static index.html - Found")
82
+ if dockerignore_patterns:
83
+ if not check_file_not_ignored("static/index.html", "Static index.html", dockerignore_patterns):
84
+ all_files_found = False
85
  else:
86
  print("❌ Static index.html - Missing")
87
  all_files_found = False
 
91
 
92
  # Print summary
93
  if all_files_found:
94
+ print("\n🎉 All required files are present and not ignored by .dockerignore!")
95
  return 0
96
  else:
97
+ print("\n💥 Some required files are missing or would be ignored!")
98
  return 1
99
 
100
  if __name__ == "__main__":