Skip to content

Commit 8258463

Browse files
committed
refactor: migrate to dedicated unoserver container
The old `unoconv` is not supported anymore upstream and needs to be replaced. Instead of running all the subprocess management code ourselves, we now just let this happen in it's own container. This should improve service stability significantly, as it's now cleanly separated. While we're at it, also update the base image to newest debian Trixie
1 parent 10337ea commit 8258463

File tree

14 files changed

+67
-390
lines changed

14 files changed

+67
-390
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ jobs:
5757
- name: Set UID
5858
run: |
5959
echo "UID=$(id --user)" > .env
60-
echo "ISOLATE_UNOCONV=true" >> .env
6160
- name: Build docker containers
6261
run: docker compose up -d --build
6362
- name: Run pytest
@@ -71,8 +70,6 @@ jobs:
7170
fail-fast: false
7271
matrix:
7372
version:
74-
- "3.10"
75-
- "3.11"
7673
- "3.12"
7774
- "3.13"
7875
database:
@@ -91,6 +88,10 @@ jobs:
9188
--health-retries 5
9289
ports:
9390
- 5432:5432
91+
unoserver:
92+
image: ghcr.io/unoconv/unoserver-docker:0.4.3
93+
ports:
94+
- 2003:2003
9495
steps:
9596
- uses: actions/checkout@v5
9697
- name: Install poetry
@@ -105,15 +106,15 @@ jobs:
105106
- name: Install dependendies
106107
run: |
107108
sudo apt-get update
108-
sudo apt-get install -y --no-install-recommends util-linux unoconv libreoffice-writer libmagic1
109+
sudo apt-get install -y --no-install-recommends libmagic1 media-types util-linux wait-for-it
109110
poetry install --extras full --with dev
110111
- name: Set environment
111112
run: |
112113
echo "ENV=dev" >> .env
113114
echo "UID=$(id --user)" >> .env
114-
echo "ISOLATE_UNOCONV=true" >> .env
115115
echo "DATABASE_DIR=${{ runner.temp }}/document-merge-service/data" >> .env
116116
echo "MEDIA_ROOT=${{ runner.temp }}/document-merge-service/media" >> .env
117+
echo "UNOSERVER_HOST=localhost" >> .env
117118
- name: Configure postgres
118119
if: ${{ matrix.database == 'postgres' }}
119120
run: |

.mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ exclude = document_merge_service/api/migrations
44
[mypy-rest_framework.*]
55
ignore_missing_imports = True
66

7+
[mypy-unoserver.*]
8+
ignore_missing_imports = True
9+
710
[mypy-babel.dates.*]
811
ignore_missing_imports = True
912

CONFIGURATION.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ To scale the service a different database storage is needed. Any database suppor
2121
- `DATABASE_USER`: Username to use when connecting to the database
2222
- `DATABASE_PASSWORD`: Password to use when connecting to database
2323

24-
## Unoconv
24+
## Unoconv/Unoserver
2525

26-
- `UNOCONV_ALLOWED_TYPES`: List of types allowed to convert to. See `unoconv --show` (default: ['pdf'])
27-
- `UNOCONV_PYTHON`: String, defaults to "/usr/bin/python3.5"
28-
- `UNOCONV_PATH`: String, defaults to "/usr/bin/unoconv"
26+
Unoserver runs separately in a container. You can configure the connection by the following env variables:
27+
28+
- `UNOSERVER_HOST`: String, defaults to "unoserver"
29+
- `UNOSERVER_PORT`: Integer, defaults to 2003
30+
- `UNOCONV_ALLOWED_TYPES`: List of types allowed to convert to. Defaults to ['pdf']
2931

3032
## python-docx-template
3133

Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.13-bookworm AS build
1+
FROM python:3.13-trixie AS build
22

33
ARG ENV=docker
44
ARG APP_HOME=/app
@@ -24,7 +24,7 @@ RUN \
2424
--mount=type=cache,target=.cache/pypoetry \
2525
poetry install --only-root
2626

27-
FROM python:3.13-slim-bookworm
27+
FROM python:3.13-slim-trixie
2828

2929
ARG UID=901
3030
ARG APP_HOME=/app
@@ -54,8 +54,7 @@ RUN \
5454
--mount=type=cache,target=/var/lib/apt,sharing=locked \
5555
apt-get update && apt-get install -y --no-install-recommends \
5656
libmagic1 \
57-
libreoffice-writer \
58-
unoconv \
57+
media-types \
5958
util-linux \
6059
wait-for-it \
6160
&& rm -rf /var/lib/apt/lists/*

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ start: ## Start the development server
88
@docker compose up -d --build
99

1010
test: ## Test the project
11-
@docker compose exec document-merge-service sh -c "ruff format --diff --fix . && ruff check --diff . && mypy document_merge_service && pytest --no-cov-on-fail --cov --create-db"
11+
@docker compose exec document-merge-service sh -c "ruff format --diff . && ruff check --diff . && mypy document_merge_service && pytest --no-cov-on-fail --cov --create-db"
1212

1313
shell: ## Shell into document merge service
1414
@docker compose exec document-merge-service bash

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ services:
1515
# - SECRET_KEY=
1616
# https://docs.djangoproject.com/en/2.1/ref/settings/#allowed-hosts
1717
# - ALLOWED_HOSTS=
18+
unoserver:
19+
image: ghcr.io/unoconv/unoserver-docker:0.4.3
1820

1921

2022
volumes:

document_merge_service/api/file_converter.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from django.conf import settings
55
from django.http import HttpResponse
66

7-
from .unoconv import Unoconv
7+
from .unoconv import UnoConverter
88

99

1010
class FileConverter:
@@ -14,10 +14,7 @@ def convert(file_contents, target_format):
1414

1515
with NamedTemporaryFile("wb", dir=dir) as tmp:
1616
tmp.write(file_contents)
17-
unoconv = Unoconv(
18-
pythonpath=settings.UNOCONV_PYTHON,
19-
unoconvpath=settings.UNOCONV_PATH,
20-
)
17+
unoconv = UnoConverter()
2118
result = unoconv.process(tmp.name, target_format)
2219

2320
status = 200 if result.returncode == 0 else 500

document_merge_service/api/tests/test_unoconv.py

Lines changed: 0 additions & 116 deletions
This file was deleted.

0 commit comments

Comments
 (0)