mirror of
https://github.com/bcye/structured-wikivoyage-exports.git
synced 2025-10-29 14:12:43 +00:00
Merge pull request #30 from bcye/feature/docker-multi-stage-builds
Docker multi stage builds
This commit is contained in:
@@ -1,8 +0,0 @@
|
|||||||
.env
|
|
||||||
__pycache__
|
|
||||||
.venv
|
|
||||||
.pytest_cache
|
|
||||||
docs
|
|
||||||
node_modules
|
|
||||||
output
|
|
||||||
sketching
|
|
||||||
4
.github/workflows/build-image.yaml
vendored
4
.github/workflows/build-image.yaml
vendored
@@ -23,11 +23,15 @@ jobs:
|
|||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Set up QEMU for multi-platform builds
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: ghcr.io/bcye/structured-wikivoyage-exports:latest
|
tags: ghcr.io/bcye/structured-wikivoyage-exports:latest
|
||||||
|
|||||||
2
.github/workflows/test-parser.yaml
vendored
2
.github/workflows/test-parser.yaml
vendored
@@ -20,4 +20,4 @@ jobs:
|
|||||||
run: uv sync --locked --dev
|
run: uv sync --locked --dev
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: PYTHONPATH=. uv run pytest
|
run: PYTHONPATH=src uv run pytest
|
||||||
|
|||||||
11
Dockerfile
11
Dockerfile
@@ -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
|
WORKDIR /app
|
||||||
|
|
||||||
COPY pyproject.toml uv.lock ./
|
# copy the requirements and install them
|
||||||
|
COPY pyproject.toml uv.lock .
|
||||||
RUN uv sync --frozen
|
RUN uv sync --frozen
|
||||||
|
|
||||||
COPY . .
|
# copy the rest of the code
|
||||||
|
COPY src ./
|
||||||
|
|
||||||
RUN chmod +x entrypoint.sh
|
RUN chmod +x entrypoint.sh
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ See [docs](docs) for more information on how to use this utility.
|
|||||||
|
|
||||||
## Testing
|
## 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
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
uv run main.py
|
|
||||||
2
src/entrypoint.sh
Normal file
2
src/entrypoint.sh
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
uv run main.py
|
||||||
@@ -5,6 +5,7 @@ from .parser import WikivoyageParser
|
|||||||
|
|
||||||
logger = getLogger(__name__)
|
logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class WikiDumpHandler(xml.sax.ContentHandler):
|
class WikiDumpHandler(xml.sax.ContentHandler):
|
||||||
"""
|
"""
|
||||||
SAX handler that, for each <page> whose <id> is in mappings,
|
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):
|
async def _process(self, text: str, uid: str, title: str):
|
||||||
parser = WikivoyageParser()
|
parser = WikivoyageParser()
|
||||||
entry = parser.parse(text)
|
entry = parser.parse(text)
|
||||||
entry['properties']['title'] = title
|
entry["properties"]["title"] = title
|
||||||
|
|
||||||
# Write to all handlers concurrently
|
# Write to all handlers concurrently
|
||||||
await asyncio.gather(*[
|
await asyncio.gather(
|
||||||
handler.write_entry(entry, uid) for handler in self.handlers
|
*[handler.write_entry(entry, uid) for handler in self.handlers]
|
||||||
])
|
)
|
||||||
Reference in New Issue
Block a user