|
| 1 | +# Document Engine example — deploying with Docker Compose and Caddy |
| 2 | + |
| 3 | +- [Prerequisites](#prerequisites) |
| 4 | +- [Getting started](#getting-started) |
| 5 | +- [Configuration](#configuration) |
| 6 | +- [API usage examples](#api-usage-examples) |
| 7 | +- [Cleanup](#cleanup) |
| 8 | +- [Support](#support) |
| 9 | +- [License](#license) |
| 10 | +- [Contributing](#contributing) |
| 11 | + |
| 12 | +> This example demonstrates a local [Nutrient Document Engine](https://www.nutrient.io/guides/document-engine/) deployment using Docker Compose, PostgreSQL, MinIO, and Caddy. |
| 13 | +
|
| 14 | +This stack is intended for local development and manual testing of large uploads. It includes a `README`, a `setup.sh`, a dedicated configuration file, and a sample document for smoke tests. |
| 15 | + |
| 16 | +## Prerequisites |
| 17 | + |
| 18 | +- A Docker-compatible runtime with `docker compose` support |
| 19 | +- `curl` |
| 20 | + |
| 21 | +## Getting started |
| 22 | + |
| 23 | +1. Run the automated setup script: |
| 24 | + |
| 25 | + ```bash |
| 26 | + ./setup.sh |
| 27 | + ``` |
| 28 | + |
| 29 | +2. Wait for the script to report that the stack is healthy, then open: |
| 30 | + |
| 31 | + ```text |
| 32 | + http://localhost:5000/dashboard |
| 33 | + ``` |
| 34 | + |
| 35 | +Default credentials: |
| 36 | + |
| 37 | +- Username: `admin` |
| 38 | +- Password: `admin` |
| 39 | + |
| 40 | +The setup script starts four services: |
| 41 | + |
| 42 | +- PostgreSQL for Document Engine metadata |
| 43 | +- MinIO as the local S3-compatible asset store |
| 44 | +- Document Engine itself |
| 45 | +- Caddy as the reverse proxy in front of Document Engine |
| 46 | + |
| 47 | +## Configuration |
| 48 | + |
| 49 | +The local profile lives in `document-engine.env.sh`. `setup.sh` sources that file before calling `docker compose`, so you can either: |
| 50 | + |
| 51 | +- Edit `document-engine.env.sh` |
| 52 | +- Override individual values in your shell before running `./setup.sh` |
| 53 | + |
| 54 | +Example: |
| 55 | + |
| 56 | +```bash |
| 57 | +export CADDY_HTTP_PORT=5050 |
| 58 | +export DASHBOARD_PASSWORD=supersecret |
| 59 | +./setup.sh |
| 60 | +``` |
| 61 | + |
| 62 | +You can also choose the Document Engine image tag at invocation time: |
| 63 | + |
| 64 | +```bash |
| 65 | +./setup.sh |
| 66 | +./setup.sh nightly |
| 67 | +``` |
| 68 | + |
| 69 | +The default tag is `latest`. |
| 70 | + |
| 71 | +The default profile is tuned for multi-GB uploads: |
| 72 | + |
| 73 | +- `MAX_UPLOAD_SIZE_BYTES=50000000000` |
| 74 | +- `SERVER_REQUEST_TIMEOUT=900000` |
| 75 | +- `PSPDFKIT_WORKER_TIMEOUT=900000` |
| 76 | +- `FILE_UPLOAD_TIMEOUT_MS=900000` |
| 77 | +- `ASSET_STORAGE_CACHE_SIZE=20000000000` |
| 78 | + |
| 79 | +To actually test large documents, you must provide a valid `ACTIVATION_KEY`. Without one, Document Engine runs with license-imposed trial limits and uploads are capped at `50 MB`, even though the local proxy and runtime configuration allow much larger request bodies. |
| 80 | + |
| 81 | +Caddy is configured to: |
| 82 | + |
| 83 | +- Allow request bodies up to `50GB` |
| 84 | +- Proxy `/i/d/.../h/.../page-*` tile-rendering requests upstream over HTTP/2 |
| 85 | +- Keep all other upstream requests on HTTP/1.1 with `response_header_timeout 15m` |
| 86 | + |
| 87 | +The dashboard is exposed at plain `http://localhost:5000/dashboard`. TLS is not needed: Caddy's h2c reverse proxy uses Go's `http.Transport`, which multiplexes incoming HTTP/1.1 requests onto a single upstream HTTP/2 connection. This gives Document Engine the HTTP/2 stream multiplexing it needs to reuse a single rendering worker across concurrent tile requests. |
| 88 | + |
| 89 | +## API usage examples |
| 90 | + |
| 91 | +Once the stack is running, you can use the [Document Engine API](https://www.nutrient.io/api/reference/document-engine/upstream/) directly through Caddy. |
| 92 | + |
| 93 | +### Upload a document |
| 94 | + |
| 95 | +```bash |
| 96 | +curl --request POST \ |
| 97 | + --url http://localhost:5000/api/documents \ |
| 98 | + --header 'Authorization: Token token=secret' \ |
| 99 | + --form 'pdf-file-from-multipart=@sample.pdf' \ |
| 100 | + --form 'instructions={"parts":[{"file":"pdf-file-from-multipart"}],"actions":[],"output":{"type":"pdf","metadata":{"title":"Test Document","author":"API User"}}}' |
| 101 | +``` |
| 102 | + |
| 103 | +### List documents |
| 104 | + |
| 105 | +```bash |
| 106 | +curl --request GET \ |
| 107 | + --url http://localhost:5000/api/documents \ |
| 108 | + --header 'Authorization: Token token=secret' |
| 109 | +``` |
| 110 | + |
| 111 | +### Get document information |
| 112 | + |
| 113 | +Replace `DOCUMENT_ID` with the actual document ID from the upload response: |
| 114 | + |
| 115 | +```bash |
| 116 | +curl --request GET \ |
| 117 | + --url http://localhost:5000/api/documents/DOCUMENT_ID/document_info \ |
| 118 | + --header 'Authorization: Token token=secret' |
| 119 | +``` |
| 120 | + |
| 121 | +### Extract text |
| 122 | + |
| 123 | +```bash |
| 124 | +curl --request GET \ |
| 125 | + --url http://localhost:5000/api/documents/DOCUMENT_ID/pages/text \ |
| 126 | + --header 'Authorization: Token token=secret' |
| 127 | +``` |
| 128 | + |
| 129 | +### Download PDF |
| 130 | + |
| 131 | +```bash |
| 132 | +curl --request GET \ |
| 133 | + --url http://localhost:5000/api/documents/DOCUMENT_ID/pdf \ |
| 134 | + --header 'Authorization: Token token=secret' \ |
| 135 | + --output downloaded-document.pdf |
| 136 | +``` |
| 137 | + |
| 138 | +## Cleanup |
| 139 | + |
| 140 | +Stop the stack: |
| 141 | + |
| 142 | +```bash |
| 143 | +source document-engine.env.sh |
| 144 | +docker compose down |
| 145 | +``` |
| 146 | + |
| 147 | +Remove the stack and local volumes: |
| 148 | + |
| 149 | +```bash |
| 150 | +source document-engine.env.sh |
| 151 | +docker compose down -v |
| 152 | +``` |
| 153 | + |
| 154 | +## Support |
| 155 | + |
| 156 | +Nutrient offers support for customers with an active SDK license via [Nutrient Support](https://www.nutrient.io/support/request/). |
| 157 | + |
| 158 | +Are you [evaluating our SDK](https://www.nutrient.io/sdk/try)? That's great, we're happy to help out. To make sure this is fast, please use a work email and have someone from your company fill out our [sales form](https://www.nutrient.io/contact-sales/). |
| 159 | + |
| 160 | +## License |
| 161 | + |
| 162 | +This project is licensed under the BSD license. See the LICENSE file for more details. |
| 163 | + |
| 164 | +## Contributing |
| 165 | + |
| 166 | +Please ensure you have signed our CLA so that we can accept your contributions. |
0 commit comments