diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e29fbef --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +__pycache__ +/.env +/.envrc +/.idea +/.mypy_cache +/.venv +/*.egg-info diff --git a/.gitignore b/.gitignore index 08f46a4..10b58d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ __pycache__ /.env +/.envrc +/.idea +/.mypy_cache +/.venv /dist /*.egg-info -.envrc -.venv -.idea diff --git a/Dockerfile b/Dockerfile index aabd0fb..28cfc2f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,14 +4,14 @@ FROM python:${PYTHON_VERSION}-alpine as builder COPY ./ ./ -RUN python3 -m pip install --upgrade pip && \ - pip install build && \ - python -m build --wheel +RUN PIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --upgrade pip && \ + pip install build +RUN python -m build --wheel FROM python:${PYTHON_VERSION}-alpine as host -RUN apk add --update nodejs npm && \ - npm install -g @mermaid-js/mermaid-cli +RUN apk add --update nodejs npm +RUN npm install -g @mermaid-js/mermaid-cli FROM host as runner diff --git a/md2conf/mermaid.py b/md2conf/mermaid.py index a1a626b..4a3653e 100644 --- a/md2conf/mermaid.py +++ b/md2conf/mermaid.py @@ -41,10 +41,11 @@ def render(source: str, output_format: Literal["png", "svg"] = "png") -> bytes: stderr=subprocess.PIPE, text=False, ) - proc.communicate(input=source.encode("utf-8")) + stdout, stderr = proc.communicate(input=source.encode("utf-8")) if proc.returncode: raise RuntimeError( - f"failed to convert Mermaid diagram; exit code: {proc.returncode}" + f"failed to convert Mermaid diagram; exit code: {proc.returncode}, " + f"output:\n{stdout.decode('utf-8')}\n{stderr.decode('utf-8')}" ) with open(filename, "rb") as image: return image.read() diff --git a/package.sh b/package.sh index 5208432..5eb7181 100755 --- a/package.sh +++ b/package.sh @@ -1,4 +1,7 @@ set -e +# +# Builds a Python package and runs unit tests in Docker +# PYTHON=python3 @@ -14,6 +17,6 @@ $PYTHON -m build for PYTHON_VERSION in 3.8 3.9 3.10 3.11 3.12 do docker build -f test.dockerfile -t py-$PYTHON_VERSION-image --build-arg PYTHON_VERSION=$PYTHON_VERSION . - docker run -it --env-file .env --rm py-$PYTHON_VERSION-image python3 -m unittest discover tests + docker run -i -t --env-file .env --rm py-$PYTHON_VERSION-image python3 -m unittest discover tests docker rmi py-$PYTHON_VERSION-image done diff --git a/test.dockerfile b/test.dockerfile index f2014b8..36cddbf 100644 --- a/test.dockerfile +++ b/test.dockerfile @@ -1,6 +1,17 @@ ARG PYTHON_VERSION=3.9 -FROM python:${PYTHON_VERSION}-alpine -RUN PIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --upgrade pip + +FROM python:${PYTHON_VERSION}-alpine as host-alpine + +RUN apk add --update nodejs npm +RUN npm install -g @mermaid-js/mermaid-cli + +FROM python:${PYTHON_VERSION}-slim as host-slim + +RUN apt-get update && apt-get install --yes --no-install-recommends nodejs npm +RUN npm install -g @mermaid-js/mermaid-cli + +FROM host-slim as runner + COPY dist/*.whl dist/ RUN python3 -m pip install `ls -1 dist/*.whl` COPY sample/ sample/