Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ jobs:
- name: Set UID
run: |
echo "UID=$(id --user)" > .env
echo "ISOLATE_UNOCONV=true" >> .env
- name: Build docker containers
run: docker compose up -d --build
- name: Run pytest
Expand All @@ -71,8 +70,6 @@ jobs:
fail-fast: false
matrix:
version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
database:
Expand All @@ -91,6 +88,10 @@ jobs:
--health-retries 5
ports:
- 5432:5432
unoserver:
image: ghcr.io/unoconv/unoserver-docker:0.4.3
ports:
- 2003:2003
steps:
- uses: actions/checkout@v5
- name: Install poetry
Expand All @@ -105,23 +106,23 @@ jobs:
- name: Install dependendies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends util-linux unoconv libreoffice-writer libmagic1
sudo apt-get install -y --no-install-recommends libmagic1 media-types util-linux wait-for-it
poetry install --extras full --with dev
- name: Set environment
run: |
echo "ENV=dev" >> .env
echo "UID=$(id --user)" >> .env
echo "ISOLATE_UNOCONV=true" >> .env
echo "DATABASE_DIR=${{ runner.temp }}/document-merge-service/data" >> .env
echo "MEDIA_ROOT=${{ runner.temp }}/document-merge-service/media" >> .env
echo "UNOSERVER_HOST=localhost" >> .env
- name: Configure postgres
if: ${{ matrix.database == 'postgres' }}
run: |
echo "DATABASE_ENGINE=django.db.backends.postgresql"
echo "DATABASE_HOST=localhost"
echo "DATABASE_PORT=5432"
echo "DATABASE_NAME=document-merge-service"
echo "DATABASE_USER=document-merge-service"
echo "DATABASE_PASSWORD=document-merge-service"
echo "DATABASE_ENGINE=django.db.backends.postgresql" >> .env
echo "DATABASE_HOST=localhost" >> .env
echo "DATABASE_PORT=5432" >> .env
echo "DATABASE_NAME=document-merge-service" >> .env
echo "DATABASE_USER=document-merge-service" >> .env
echo "DATABASE_PASSWORD=document-merge-service" >> .env
- name: Run tests
run: poetry run pytest --no-cov-on-fail --cov --create-db -vv
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,4 @@ target/
.idea/

/.dmypy.json
.aider*
3 changes: 3 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ exclude = document_merge_service/api/migrations
[mypy-rest_framework.*]
ignore_missing_imports = True

[mypy-unoserver.*]
ignore_missing_imports = True

[mypy-babel.dates.*]
ignore_missing_imports = True

Expand Down
10 changes: 6 additions & 4 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ To scale the service a different database storage is needed. Any database suppor
- `DATABASE_USER`: Username to use when connecting to the database
- `DATABASE_PASSWORD`: Password to use when connecting to database

## Unoconv
## Unoconv/Unoserver

- `UNOCONV_ALLOWED_TYPES`: List of types allowed to convert to. See `unoconv --show` (default: ['pdf'])
- `UNOCONV_PYTHON`: String, defaults to "/usr/bin/python3.5"
- `UNOCONV_PATH`: String, defaults to "/usr/bin/unoconv"
Unoserver runs separately in a container. You can configure the connection by the following env variables:

- `UNOSERVER_HOST`: String, defaults to "unoserver"
- `UNOSERVER_PORT`: Integer, defaults to 2003
- `UNOCONV_ALLOWED_TYPES`: List of types allowed to convert to. Defaults to ['pdf']

## python-docx-template

Expand Down
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.13-bookworm AS build
FROM python:3.13-trixie AS build

ARG ENV=docker
ARG APP_HOME=/app
Expand All @@ -24,7 +24,7 @@ RUN \
--mount=type=cache,target=.cache/pypoetry \
poetry install --only-root

FROM python:3.13-slim-bookworm
FROM python:3.13-slim-trixie

ARG UID=901
ARG APP_HOME=/app
Expand Down Expand Up @@ -54,8 +54,7 @@ RUN \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && apt-get install -y --no-install-recommends \
libmagic1 \
libreoffice-writer \
unoconv \
media-types \
util-linux \
wait-for-it \
&& rm -rf /var/lib/apt/lists/*
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ start: ## Start the development server
@docker compose up -d --build

test: ## Test the project
@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"
@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"

shell: ## Shell into document merge service
@docker compose exec document-merge-service bash
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ services:
# - SECRET_KEY=
# https://docs.djangoproject.com/en/2.1/ref/settings/#allowed-hosts
# - ALLOWED_HOSTS=
unoserver:
image: ghcr.io/unoconv/unoserver-docker:0.4.3


volumes:
Expand Down
7 changes: 2 additions & 5 deletions document_merge_service/api/file_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.conf import settings
from django.http import HttpResponse

from .unoconv import Unoconv
from .unoconv import UnoConverter


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

with NamedTemporaryFile("wb", dir=dir) as tmp:
tmp.write(file_contents)
unoconv = Unoconv(
pythonpath=settings.UNOCONV_PYTHON,
unoconvpath=settings.UNOCONV_PATH,
)
unoconv = UnoConverter()
result = unoconv.process(tmp.name, target_format)

status = 200 if result.returncode == 0 else 500
Expand Down
116 changes: 0 additions & 116 deletions document_merge_service/api/tests/test_unoconv.py

This file was deleted.

Loading
Loading