Ctrl K
ComunidadGuías…

Dockerfile.fromwheel

Rama main · réplica de lectura del repositorio original.

Archivo original ↗Preguntar a KiBot
# This is the Dockerfile that builds an image given a specified WHEEL_FILE,
# rather than from source/working dir.
#
# The reason for this is that, although Bugsink is certainly available as a
# Docker image, it is available as a Python package first. We thus want
# the Docker image to be as faithful as possible to the Python package.
#
# Because the typical expectation for a Dockerfile is that it "just works"
# and that it builds from source (the working directory), the present file
# is not named Dockerfile, but an explicitly postfixed one. Still, for the
# purpose of what actually ends up on Docker hub, the present file is the
# one that's used.
ARG PYTHON_VERSION=3.12

# Build image: non-slim, in particular to build the mysqlclient wheel
FROM python:${PYTHON_VERSION} AS build

# mysqlclient is not available as a .whl on PyPI, so we need to build it from
# source and store the .whl. This is both the most expensive part of the build
# and the one that is least likely to change, so we do it first.
RUN --mount=type=cache,target=/root/.cache/pip \
    pip wheel --wheel-dir /wheels mysqlclient

# NOTE: At some point in the past, we built all requirements as encoded in the
# Bugsink wheel file into wheels at this point. It is not clear that this saves
# any build time however, because:
#
# * this moves the dependency on the bugsink wheel up in the build-order, and
#     that's precisely the most changing part, i.e. the thing that breaks caching.
#
# * all current (Aug 2025) dependencies .whl files are available on PyPI anyway.
#     Nothing much is gained by fetch-first-install-later. And if we ever
#     depend on packages that require a build step, explicit action is probably
#     needed anyway b/c of the build deps.
#
# * pointing to requirements.txt here instead of the wheel is tempting, but
#     breaks the idea of "just build the wheel" (requirements.txt is whatever
#     it happens to be right now, not what it was at the time the wheel was
#     built)
# 
# Moreover, there's the argument of image _size_ rather than build time, and
# copying over all wheels instead of just their unpacked equivalents increases
# that.

# Actual image (based on slim)
FROM python:${PYTHON_VERSION}-slim

ARG WHEEL_FILE=wheelfile-not-specified.whoops

ENV PYTHONUNBUFFERED=1

ENV PORT=8000

WORKDIR /app

# Runtime shared library the mysqlclient wheel links against.
RUN apt update && apt install libmariadb3 ca-certificates -y \
 && rm -rf /var/lib/apt/lists/*

# Install all deps and strip native extensions in a single layer, so only the
# stripped binaries are stored (must be same layer to actually shrink the image).
# binutils is installed and purged here; the wheel is bind-mounted, not COPYed,
# so neither ends up in a layer.
RUN --mount=type=cache,target=/root/.cache/pip \
    --mount=type=bind,from=build,source=/wheels,target=/wheels \
    --mount=type=bind,source=dist/$WHEEL_FILE,target=/tmp/$WHEEL_FILE \
    apt-get update \
 && apt-get install -y --no-install-recommends binutils \
 && pip install --find-links /wheels --no-index mysqlclient \
 && pip install "psycopg[binary]" \
 && pip install /tmp/$WHEEL_FILE \
 && find /usr/local/lib/python3.12/site-packages -name '*.so' -exec strip --strip-unneeded {} + \
 && apt-get purge -y binutils && apt-get autoremove -y \
 && rm -rf /var/lib/apt/lists/*

RUN cp /usr/local/lib/python3.12/site-packages/bugsink/conf_templates/docker.py.template /app/bugsink_conf.py && \
    cp /usr/local/lib/python3.12/site-packages/bugsink/gunicorn.docker.conf.py /app/gunicorn.docker.conf.py

RUN groupadd --gid 14237 bugsink \
 && useradd --uid 14237 --gid 14237 bugsink \
 && mkdir -p /data \
 && chown -R bugsink:bugsink /data

USER bugsink

HEALTHCHECK CMD python -c 'import requests; requests.get("http://localhost:8000/health/ready").raise_for_status()'

CMD [ "monofy", "bugsink-show-version", "&&", "bugsink-manage", "check", "--deploy", "--fail-level", "WARNING", "&&", "bugsink-manage", "migrate", "snappea", "--database=snappea", "&&", "bugsink-manage", "migrate", "&&", "bugsink-manage", "prestart", "&&", "gunicorn", "--config", "gunicorn.docker.conf.py", "--bind=0.0.0.0:$PORT", "--access-logfile", "-", "bugsink.wsgi", "|||", "bugsink-runsnappea"]