pylokid/Dockerfile

67 lines
1.8 KiB
Docker
Raw Permalink Normal View History

2021-02-13 19:27:41 +00:00
## ----------- Step 1
2021-02-11 20:00:29 +00:00
FROM docker.io/python:3.9 AS base
2019-01-06 12:25:37 +00:00
2019-09-22 18:34:38 +00:00
# Install pdftotext
RUN set -x; \
apt update && \
apt install -y poppler-utils && \
rm -rf /var/lib/apt/lists/*
2021-02-11 20:00:29 +00:00
ENV HOME=/app
2019-01-06 12:25:37 +00:00
2021-02-11 20:00:29 +00:00
WORKDIR ${HOME}
2021-02-13 19:27:41 +00:00
## ----------- Step 2
2021-02-11 20:00:29 +00:00
FROM base AS builder
ENV PATH=${PATH}:${HOME}/.poetry/bin
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python - --version 1.1.0 \
&& mkdir -p /app/.config
COPY pyproject.toml poetry.lock ./
RUN poetry config virtualenvs.create false \
&& poetry install --no-dev --no-root
COPY . ./
RUN poetry build --format wheel
2021-02-13 19:27:41 +00:00
## ----------- Step 3
2021-02-11 20:00:29 +00:00
FROM builder AS installer
COPY --from=builder \
/app/dist /app/dist
RUN pip install /app/dist/pylokid-*-py3-none-any.whl
2021-02-27 13:37:24 +00:00
COPY hack/patches/*.patch /tmp/
2021-02-13 19:27:41 +00:00
# The ugliest possible way to workaround https://github.com/MechanicalSoup/MechanicalSoup/issues/356
# For some unknown reasons Lodur now wants "Content-Type: application/pdf" set in the multipart
# data section. And as I couln't figure out yet how to do that in MechanicalSoup and I only upload PDFs
# I just patch it to hardcode it. YOLO
2021-02-27 13:37:24 +00:00
RUN \
patch -p0 /usr/local/lib/python3.9/site-packages/mechanicalsoup/browser.py < /tmp/mechsoup-browser-content-type.patch && \
patch -p0 /usr/local/lib/python3.9/site-packages/mechanicalsoup/stateful_browser.py < /tmp/mechsoup-link-regex.patch
2021-02-13 19:27:41 +00:00
## ----------- Step 4
2021-02-11 20:00:29 +00:00
FROM base AS runtime
COPY --from=installer \
/usr/local/lib/python3.9/site-packages/ /usr/local/lib/python3.9/site-packages/
COPY --from=installer \
/usr/local/bin/* \
/usr/local/bin/
RUN chgrp 0 /app/ \
&& chmod g+rwX /app/
USER 1001
CMD [ "pylokid" ]