Merge pull request #30 from bcye/feature/docker-multi-stage-builds

Docker multi stage builds
This commit is contained in:
Bruce
2025-09-30 16:21:59 +02:00
committed by GitHub
19 changed files with 22 additions and 20 deletions

View File

@@ -1,8 +0,0 @@
.env
__pycache__
.venv
.pytest_cache
docs
node_modules
output
sketching

View File

@@ -23,11 +23,15 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU for multi-platform builds
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/bcye/structured-wikivoyage-exports:latest

View File

@@ -20,4 +20,4 @@ jobs:
run: uv sync --locked --dev
- name: Run tests
run: PYTHONPATH=. uv run pytest
run: PYTHONPATH=src uv run pytest

View File

@@ -1,11 +1,16 @@
FROM ghcr.io/astral-sh/uv:0.6-python3.12-bookworm
# use python 3.12 as a base image
FROM docker.io/python:3.12-alpine
# use the latest version of uv, independently of the python version
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
WORKDIR /app
COPY pyproject.toml uv.lock ./
# copy the requirements and install them
COPY pyproject.toml uv.lock .
RUN uv sync --frozen
COPY . .
# copy the rest of the code
COPY src ./
RUN chmod +x entrypoint.sh

View File

@@ -18,7 +18,7 @@ See [docs](docs) for more information on how to use this utility.
## Testing
Run `PYTHONPATH=. pytest` from inside the venv
Run `PYTHONPATH=src pytest` from inside the venv, or directly call `PYTHONPATH=src uv run -- pytest`.
## License

View File

@@ -1,2 +0,0 @@
#!/bin/bash
uv run main.py

2
src/entrypoint.sh Normal file
View File

@@ -0,0 +1,2 @@
#!/bin/sh
uv run main.py

View File

@@ -5,6 +5,7 @@ from .parser import WikivoyageParser
logger = getLogger(__name__)
class WikiDumpHandler(xml.sax.ContentHandler):
"""
SAX handler that, for each <page> whose <id> is in mappings,
@@ -92,9 +93,9 @@ class WikiDumpHandler(xml.sax.ContentHandler):
async def _process(self, text: str, uid: str, title: str):
parser = WikivoyageParser()
entry = parser.parse(text)
entry['properties']['title'] = title
entry["properties"]["title"] = title
# Write to all handlers concurrently
await asyncio.gather(*[
handler.write_entry(entry, uid) for handler in self.handlers
])
await asyncio.gather(
*[handler.write_entry(entry, uid) for handler in self.handlers]
)