AkshitShubham commited on
Commit
cf58b83
·
verified ·
1 Parent(s): a9b7fdc

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +92 -0
Dockerfile ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Start with a base image
2
+ FROM ubuntu:22.04
3
+
4
+ # Set environment variables for non-interactive installs
5
+ ENV DEBIAN_FRONTEND=noninteractive
6
+
7
+ # Install core dependencies for Paperless-ngx
8
+ RUN apt-get update && \
9
+ apt-get install -y --no-install-recommends \
10
+ python3 python3-pip python3-dev \
11
+ imagemagick fonts-liberation gnupg \
12
+ libpq-dev default-libmysqlclient-dev pkg-config \
13
+ libmagic-dev libzbar0 poppler-utils \
14
+ unpaper ghostscript icc-profiles-free qpdf liblept5 libxml2 \
15
+ pngquant zlib1g tesseract-ocr tesseract-ocr-eng \
16
+ build-essential python3-setuptools python3-wheel \
17
+ redis-server postgresql postgresql-client \
18
+ supervisor nano # Add supervisor for process management
19
+
20
+ # Clean up apt caches to reduce image size
21
+ RUN rm -rf /var/lib/apt/lists/*
22
+
23
+ # Create user and directories for Paperless-ngx
24
+ RUN adduser --system --home /opt/paperless --group paperless
25
+ WORKDIR /opt/paperless
26
+
27
+ # Clone Paperless-ngx (or copy if you have it locally)
28
+ # Using a specific release is recommended for stability
29
+ RUN apt-get update && apt-get install -y git && \
30
+ git clone https://github.com/paperless-ngx/paperless-ngx.git . && \
31
+ git checkout v2.17.1 # Replace with the version you want
32
+
33
+ # Build frontend (if cloning from git)
34
+ RUN python3 -m venv venv && . venv/bin/activate && \
35
+ npm install -g yarn && \
36
+ yarn install --cwd src/paperless_frontend && \
37
+ yarn build --cwd src/paperless_frontend && \
38
+ deactivate
39
+
40
+ # Install Python dependencies
41
+ COPY requirements.txt .
42
+ RUN pip3 install -r requirements.txt
43
+
44
+ # --- Configure internal Redis and PostgreSQL ---
45
+ # These steps are highly simplified. You'd need to properly configure
46
+ # PostgreSQL for a non-root user and ensure it starts correctly.
47
+ # For Redis, it's usually simpler, but still needs to be started correctly.
48
+
49
+ # Configure PostgreSQL (simple example, needs hardening for production)
50
+ RUN service postgresql start && \
51
+ sudo -u postgres psql -c "CREATE USER paperless WITH PASSWORD 'your_db_password';" && \
52
+ sudo -u postgres psql -c "CREATE DATABASE paperless OWNER paperless;" && \
53
+ service postgresql stop
54
+
55
+ # Create Paperless-ngx specific directories
56
+ RUN mkdir -p media data consume export
57
+ RUN chown -R paperless:paperless media data consume export
58
+
59
+ # --- Paperless-ngx Configuration ---
60
+ # Set environment variables that Paperless-ngx will read
61
+ # These can also be read from a paperless.conf file, but env vars are easier in Docker
62
+ ENV PAPERLESS_REDIS="redis://localhost:6379/0"
63
+ ENV PAPERLESS_DBENGINE="postgresql"
64
+ ENV PAPERLESS_DBHOST="localhost"
65
+ ENV PAPERLESS_DBNAME="paperless"
66
+ ENV PAPERLESS_DBUSER="paperless"
67
+ ENV PAPERLESS_DBPASS="your_db_password"
68
+ ENV PAPERLESS_SECRET_KEY="a_very_long_and_random_string_for_huggingface" # IMPORTANT: Generate this securely!
69
+ ENV PAPERLESS_CONSUMPTION_DIR="/opt/paperless/consume"
70
+ ENV PAPERLESS_DATA_DIR="/opt/paperless/data"
71
+ ENV PAPERLESS_MEDIA_ROOT="/opt/paperless/media"
72
+ ENV PAPERLESS_PORT="7860" # Crucial for Hugging Face Spaces
73
+ ENV PAPERLESS_BIND_ADDR="0.0.0.0" # Bind to all interfaces
74
+ ENV PAPERLESS_WEBSERVER_WORKERS=1 # Save memory on Hugging Face Spaces
75
+
76
+ # Optional: Disable some resource-intensive features for less powerful devices
77
+ ENV PAPERLESS_OCR_PAGES=1
78
+ ENV PAPERLESS_ENABLE_NLTK=false
79
+ ENV PAPERLESS_OCR_CLEAN="none"
80
+
81
+ # --- Database Migrations and Superuser Creation ---
82
+ # This needs to run AFTER the database is up and configured.
83
+ # We'll put it in a startup script for supervisord.
84
+
85
+ # --- Supervisord Configuration ---
86
+ COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
87
+
88
+ # Exposed port for Hugging Face Spaces
89
+ EXPOSE 7860
90
+
91
+ # Command to run supervisord, which will start all services
92
+ CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf"]