Skip to content

Update worker Dockerfile image to bookworm #460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 30, 2025

Conversation

LeoTheMighty
Copy link
Contributor

@LeoTheMighty LeoTheMighty commented Jul 14, 2025

Upgrade the image used for the pytest_celery_worker from the python:3.10-slim-buster to the python:3.10-slim-bookworm image, because the buster images are on Debian 10, and it has already left the LTS, so therefore its package mirrors were moved from deb.debian.org to archive.debian.org.

Once that happened, apt-get update inside the image began getting 404 / Release-file-missing errors, and the next apt-get install bailed out with exit code 100.

To reproduce on the main branch run:

cd src/pytest_celery/vendors/worker

docker build --no-cache .

You will see an output like this:

docker build --no-cache .

[+] Building 0.9s (7/10)                                                                                                                                                                      docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                                                                          0.0s
 => => transferring dockerfile: 1.26kB                                                                                                                                                                        0.0s
 => WARN: JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals (line 52)                                                                              0.0s
 => [internal] load metadata for docker.io/library/python:3.10-slim-buster                                                                                                                                    0.0s
 => [internal] load .dockerignore                                                                                                                                                                             0.0s
 => => transferring context: 2B                                                                                                                                                                               0.0s
 => CACHED [1/6] FROM docker.io/library/python:3.10-slim-buster                                                                                                                                               0.0s
 => [internal] load build context                                                                                                                                                                             0.0s
 => => transferring context: 1.65kB                                                                                                                                                                           0.0s
 => [2/6] RUN adduser --disabled-password --gecos "" test_user                                                                                                                                                0.2s
 => ERROR [3/6] RUN apt-get update && apt-get install -y build-essential     git     wget     make     curl     apt-utils     debconf     lsb-release     libmemcached-dev     libffi-dev     ca-certificate  0.7s
------                                                                                                                                                                                                             
 > [3/6] RUN apt-get update && apt-get install -y build-essential     git     wget     make     curl     apt-utils     debconf     lsb-release     libmemcached-dev     libffi-dev     ca-certificates     pypy3     pypy3-lib     sudo:                                                                                                                                                                                              
0.228 Ign:1 http://deb.debian.org/debian buster InRelease                                                                                                                                                          
0.367 Ign:2 http://deb.debian.org/debian-security buster/updates InRelease                                                                                                                                         
0.387 Ign:3 http://deb.debian.org/debian buster-updates InRelease                                                                                                                                                  
0.407 Err:4 http://deb.debian.org/debian buster Release
0.407   404  Not Found [IP: 199.232.66.132 80]
0.548 Err:5 http://deb.debian.org/debian-security buster/updates Release
0.548   404  Not Found [IP: 199.232.66.132 80]
0.568 Err:6 http://deb.debian.org/debian buster-updates Release
0.568   404  Not Found [IP: 199.232.66.132 80]
0.577 Reading package lists...
0.590 E: The repository 'http://deb.debian.org/debian buster Release' does not have a Release file.
0.590 E: The repository 'http://deb.debian.org/debian-security buster/updates Release' does not have a Release file.
0.590 E: The repository 'http://deb.debian.org/debian buster-updates Release' does not have a Release file.
------

 1 warning found (use docker --debug to expand):
 - JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals (line 52)
Dockerfile:7
--------------------
   6 |     # Install system dependencies
   7 | >>> RUN apt-get update && apt-get install -y build-essential \
   8 | >>>     git \
   9 | >>>     wget \
  10 | >>>     make \
  11 | >>>     curl \
  12 | >>>     apt-utils \
  13 | >>>     debconf \
  14 | >>>     lsb-release \
  15 | >>>     libmemcached-dev \
  16 | >>>     libffi-dev \
  17 | >>>     ca-certificates \
  18 | >>>     pypy3 \
  19 | >>>     pypy3-lib \
  20 | >>>     sudo
  21 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c apt-get update && apt-get install -y build-essential     git     wget     make     curl     apt-utils     debconf     lsb-release     libmemcached-dev     libffi-dev     ca-certificates     pypy3     pypy3-lib     sudo" did not complete successfully: exit code: 100

Then on my branch, you will see the same command run without error.

Summary by CodeRabbit

  • Chores
    • Updated the base Docker image to a newer version for improved compatibility and support.

The issue here was that `slim-buster` has reached LTS and so
trying to run `apt-get` commands on the image was returning 404
errors. The real robust solution is to upgrade to a newer future-
proof image like `bookworm` instead.
@LeoTheMighty LeoTheMighty requested a review from Nusnus as a code owner July 14, 2025 21:00
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/pytest_celery/vendors/worker/Dockerfile (1)

7-21: Shrink image size & avoid dangling layers.

apt-get update && apt-get install -y … leaves APT caches in the layer and pulls in recommended packages by default, inflating the image >200 MB.

-RUN apt-get update && apt-get install -y build-essential \
+RUN set -eux; \
+    apt-get update; \
+    apt-get install -y --no-install-recommends build-essential \
     git \
@@
-    sudo
+    sudo \
+ && apt-get clean \
+ && rm -rf /var/lib/apt/lists/*

Benefits: ~80 MB smaller image, fewer CVE surfaces.
No functional change.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d1a1db and 5ce515c.

📒 Files selected for processing (1)
  • src/pytest_celery/vendors/worker/Dockerfile (1 hunks)
🔇 Additional comments (1)
src/pytest_celery/vendors/worker/Dockerfile (1)

1-1: All dependencies exist in Debian Bookworm
Verified against packages.debian.org/bookworm—build-essential, git, wget, make, curl, apt-utils, debconf, lsb-release, libmemcached-dev, libffi-dev, ca-certificates, pypy3, pypy3-lib, and sudo all return HTTP 200. No renames or backports needed; you can safely bump to python:3.10-slim-bookworm.

Copy link

codecov bot commented Jul 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 23.80%. Comparing base (4d1a1db) to head (e69aa88).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #460   +/-   ##
=======================================
  Coverage   23.80%   23.80%           
=======================================
  Files          41       41           
  Lines        1294     1294           
  Branches       94       94           
=======================================
  Hits          308      308           
  Misses        959      959           
  Partials       27       27           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@celery celery deleted a comment from coderabbitai bot Jul 15, 2025
Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about updating to python 3.12 as well?

@LeoTheMighty
Copy link
Contributor Author

I'll try updating to 3.12, the errors on the CI workflow are still showing the same error. Any chance the docker images are being cached in those tests? I don't see slim-buster being used anywhere else in the repo

@go-diego-go
Copy link

Any chance this can be fixed soon?
Or is there any other workaround to override the Dockerfile within the test setup?
We're also being impacted by this so it's breaking our tests

@LeoTheMighty
Copy link
Contributor Author

@Nusnus do you know what these CI failures are about? It looks like the existing issue, is there any chance there is caching affecting the testing suites that we can expire ?

@gpkc
Copy link

gpkc commented Jul 24, 2025

I think this works as a workaround for now:

  1. Create a custom dockerfile with the updated base image, placing it in the same folder as your conftest.py:
FROM python:3.12-slim-bookworm

# Create a user to run the worker
RUN adduser --disabled-password --gecos "" test_user

# Install system dependencies
RUN apt-get update && apt-get install -y build-essential \
    git \
    wget \
    make \
    curl \
    apt-utils \
    debconf \
    lsb-release \
    libmemcached-dev \
    libffi-dev \
    ca-certificates \
    pypy3 \
    pypy3-lib \
    sudo

# Set arguments
ARG CELERY_VERSION=""
ARG CELERY_LOG_LEVEL=INFO
ARG CELERY_WORKER_NAME=celery_test_worker
ARG CELERY_WORKER_QUEUE=celery
ENV WORKER_VERSION=$CELERY_VERSION
ENV LOG_LEVEL=$CELERY_LOG_LEVEL
ENV WORKER_NAME=$CELERY_WORKER_NAME
ENV WORKER_QUEUE=$CELERY_WORKER_QUEUE

ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1

EXPOSE 5678

# Install Python dependencies
RUN pip install --no-cache-dir --upgrade \
    pip \
    celery[redis,pymemcache,gevent]${WORKER_VERSION:+==$WORKER_VERSION} \
    pytest-celery[sqs]@git+https://github.com/celery/pytest-celery.git

# The workdir must be /app
WORKDIR /app

COPY content/ .

# Switch to the test_user
USER test_user

# Start the celery worker
CMD celery -A app worker --loglevel=$LOG_LEVEL -n $WORKER_NAME@%h -Q $WORKER_QUEUE
  1. Then add this to your conftest.py
@pytest.fixture(scope="session")
def celery_base_worker_image(
    docker_client,
    default_worker_celery_version,
    default_worker_celery_log_level,
    default_worker_celery_worker_name,
    default_worker_celery_worker_queue,
):
    from pkg_resources import resource_filename

    original_context_path = resource_filename("pytest_celery.vendors.worker", "")
    custom_dockerfile = "Dockerfile"
    custom_dockerfile_absolute_path = os.path.abspath(custom_dockerfile)

    with open(custom_dockerfile, "rb") as f:
        image, _ = docker_client.images.build(
            path=original_context_path,
            dockerfile=custom_dockerfile_absolute_path,
            tag="pytest-celery/components/worker:default-custom",
            buildargs={
                "CELERY_VERSION": default_worker_celery_version,
                "CELERY_LOG_LEVEL": default_worker_celery_log_level,
                "CELERY_WORKER_NAME": default_worker_celery_worker_name,
                "CELERY_WORKER_QUEUE": default_worker_celery_worker_queue,
            },
            rm=True,
        )
        return image

1. We’re capped at 3.10 due to the `custom_setup` tests which use Celery 4.
2. The examples CI is bugged as it does not use the current branch’s changes and should work once the PR is merged to `main` (if everything else passes)
@Nusnus Nusnus added the bug Something isn't working label Jul 30, 2025
@Nusnus Nusnus assigned Nusnus and unassigned Nusnus Jul 30, 2025
Copy link
Member

@Nusnus Nusnus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom_setup tests are using Celery 4 with Celery 5 in the same test setup (hybrid worker cluster), which uses the same Dockerfile with different version args, which limits the Dockerfile base python to 3.10.

The right fix will be to create a separate Dockerfile for the Celery 4 worker in the tests, to “free” the Celery 5 base python from Celery 4 issues with newer python versions.
Due to the original reason this PR was opened, I prefer to accept the 3.10 change and then create a new PR for the “right fix”.

Take note the examples CI is bugged and should pass after merge on main if everything else passes in the CI. This is another technical debt to fix :)

@Nusnus Nusnus mentioned this pull request Jul 30, 2025
9 tasks
@Nusnus Nusnus merged commit 0c246f7 into celery:main Jul 30, 2025
33 of 43 checks passed
@Nusnus
Copy link
Member

Nusnus commented Jul 30, 2025

The custom_setup tests are using Celery 4 with Celery 5 in the same test setup (hybrid worker cluster), which uses the same Dockerfile with different version args, which limits the Dockerfile base python to 3.10.

The right fix will be to create a separate Dockerfile for the Celery 4 worker in the tests, to “free” the Celery 5 base python from Celery 4 issues with newer python versions. Due to the original reason this PR was opened, I prefer to accept the 3.10 change and then create a new PR for the “right fix”.

Take note the examples CI is bugged and should pass after merge on main if everything else passes in the CI. This is another technical debt to fix :)

CleanShot 2025-07-30 at 15 56 03@2x

@Nusnus
Copy link
Member

Nusnus commented Jul 30, 2025

v1.2.1 is now released with the fix.
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants