Spaces:
Build error
Build error
| FROM ubuntu:22.04 | |
| ENV DEBIAN_FRONTEND=noninteractive | |
| # Install core system dependencies + Node.js LTS (>=16) | |
| RUN apt-get update && \ | |
| apt-get install -y --no-install-recommends \ | |
| curl ca-certificates gnupg build-essential git python3 \ | |
| python3-pip python3-dev imagemagick fonts-liberation libpq-dev \ | |
| default-libmysqlclient-dev pkg-config libmagic-dev libzbar0 poppler-utils \ | |
| unpaper ghostscript icc-profiles-free qpdf liblept5 libxml2 pngquant \ | |
| zlib1g tesseract-ocr tesseract-ocr-eng redis-server postgresql \ | |
| postgresql-client supervisor nano && \ | |
| rm -rf /var/lib/apt/lists/* && \ | |
| curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \ | |
| apt-get update && apt-get install -y nodejs && \ | |
| npm install -g pnpm | |
| # Verify Node and pnpm versions | |
| RUN node --version && pnpm --version | |
| # Install uv package installer | |
| RUN curl -sSf https://astral.sh/uv/install.sh | bash | |
| # Create the system user and prepare working directory | |
| RUN adduser --system --home /opt/paperless --group paperless | |
| WORKDIR /opt/paperless | |
| RUN git config --global --add safe.directory /opt/paperless | |
| # Clone repository & checkout specific version | |
| RUN git clone https://github.com/paperless-ngx/paperless-ngx.git . && \ | |
| git checkout v2.17.1 | |
| # Build frontend using pnpm—no production flag | |
| RUN cd src-ui && pnpm install && pnpm exec ng build | |
| # Install Python backend dependencies | |
| RUN /root/.cargo/bin/uv pip install -r requirements.txt | |
| # Initialize PostgreSQL | |
| RUN service postgresql start && \ | |
| su - postgres -c "psql -c \"CREATE USER paperless WITH PASSWORD 'your_db_password';\"" && \ | |
| su - postgres -c "psql -c \"CREATE DATABASE paperless OWNER paperless;\"" && \ | |
| service postgresql stop | |
| # Create and take care of directories | |
| RUN mkdir -p media data consume export && \ | |
| chown -R paperless:paperless media data consume export | |
| # Environment variables for Paperless‑ngx | |
| ENV PAPERLESS_REDIS="redis://localhost:6379/0" \ | |
| PAPERLESS_DBENGINE="postgresql" \ | |
| PAPERLESS_DBHOST="localhost" \ | |
| PAPERLESS_DBNAME="paperless" \ | |
| PAPERLESS_DBUSER="paperless" \ | |
| PAPERLESS_DBPASS="your_db_password" \ | |
| PAPERLESS_SECRET_KEY="a_very_long_random_string" \ | |
| PAPERLESS_CONSUMPTION_DIR="/opt/paperless/consume" \ | |
| PAPERLESS_DATA_DIR="/opt/paperless/data" \ | |
| PAPERLESS_MEDIA_ROOT="/opt/paperless/media" \ | |
| PAPERLESS_PORT="7860" \ | |
| PAPERLESS_BIND_ADDR="0.0.0.0" \ | |
| PAPERLESS_WEBSERVER_WORKERS=1 \ | |
| PAPERLESS_OCR_PAGES=1 \ | |
| PAPERLESS_ENABLE_NLTK=false \ | |
| PAPERLESS_OCR_CLEAN="none" | |
| # Supervisord config to orchestrate services | |
| RUN printf "[supervisord]\nnodaemon=true\n\n\ | |
| [program:postgresql]\ncommand=/usr/lib/postgresql/*/bin/postgres -D /var/lib/postgresql/*/main\nuser=postgres\n\n\ | |
| [program:redis]\ncommand=/usr/bin/redis-server\n\n\ | |
| [program:paperless-webserver]\ncommand=/opt/paperless/src/manage.py runserver 0.0.0.0:7860\nuser=paperless\n\n\ | |
| [program:paperless-consumer]\ncommand=/opt/paperless/src/manage.py document_consumer\nuser=paperless\n\n\ | |
| [program:paperless-scheduler]\ncommand=/opt/paperless/src/manage.py qcluster\nuser=paperless\n" > /etc/supervisor/conf.d/supervisord.conf | |
| ENV PATH="/root/.cargo/bin:${PATH}" | |
| # Startup script: launches DB, Redis, migrations, then supervisord | |
| RUN printf "#!/bin/bash\n\ | |
| service postgresql start\n\ | |
| service redis-server start\n\ | |
| cd /opt/paperless\n\ | |
| python3 src/manage.py migrate\n\ | |
| python3 src/manage.py createsuperuser --noinput --username admin --email admin@example.com || true\n\ | |
| exec /usr/bin/supervisord -n -c /etc/supervisor/conf.d/supervisord.conf\n" > /startup.sh && chmod +x /startup.sh | |
| EXPOSE 7860 | |
| CMD ["/startup.sh"] | |