Skip to content

container: rewrite multi-distro build to use Jinja2 template + Python script - #68256

Closed
epuertat with Copilot wants to merge 2 commits into
tentaclefrom
copilot/rewrite-containerfile-approach
Closed

epuertat with Copilot wants to merge 2 commits into
tentaclefrom
copilot/rewrite-containerfile-approach

Conversation

Copilot AI commented Apr 8, 2026 •

Copy link
Copy Markdown
Contributor

Replaces the procedural Bash approach (runtime /etc/os-release parsing, source /etc/ceph-distro.env in every RUN step) with a clean render-then-build model: all distro decisions are resolved at template render time from CI env vars, producing a flat, readable Containerfile with no runtime conditionals.

What changed

Deleted:

  • container/Containerfile → replaced by container/Containerfile.j2
  • container/build.sh → replaced by container/build.py

container/Containerfile.j2 — Jinja2 template rendered before podman build:

  • Jinja2 variables {{ el_ver }}, {{ dist_path }}, {{ distro_id }}, {{ distro_major }} replace all source /etc/ceph-distro.env + bash conditionals
  • Rocky Linux uses shaman API for NFS-Ganesha repo; CentOS/AlmaLinux use static baseurl
  • Copr repos and python3-saml conditionally omitted on EL 10+ (python3-saml: SAML2 SSO deprecated in favour of OAuth2)
  • CUSTOM_CEPH_REPO_URL support preserved

container/build.py — PEP-8 Python, argparse, logging:

  • Derives distro_id / distro_major / el_ver / dist_path from FROM_IMAGE (e.g. quay.io/rockylinux/rockylinux:10 → rocky / 10 / el10 / rocky/10)
  • Default FROM_IMAGE by branch: "reef" in branch or "squid" in branch → centos:stream9; all others → rockylinux:10 (substring match per review feedback on tentacle: container/build.sh: FROM_IMAGE=rockylinux-10 default for >=tentacle backports #67960)
  • Non-default fromtag appended to branch/sha1 tags so ceph:tentacle always resolves to the preferred base
  • debug flavor suffix, crimson-only sha1 tag, arm64 suffix — full parity with build.sh
  • Secret file created atomically via os.open(..., 0o600) before writing credentials

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands
Original prompt

Context

PR #67960 added multi-distro support (CentOS 9 / Rocky 10 / AlmaLinux) to container/Containerfile and container/build.sh. The current implementation uses procedural Bash inside the Containerfile — deriving distro-specific variables at container build time by sourcing /etc/os-release, writing an env file (/etc/ceph-distro.env), and then conditionally branching in every subsequent RUN step. The build.sh script also has complex Bash logic for tagging and pushing.

The goal of this PR is to rewrite the approach so that:

  1. A single container/Containerfile.j2 Jinja2 template is the only declarative artifact describing the container image.
  2. A Python script container/build.py reads CI environment variables (the same ones build.sh consumes today), renders Containerfile.j2 into a final Containerfile using Jinja2, builds the image, tags it, and optionally pushes it.
  3. The generated Containerfile is clean and simple — no source /etc/ceph-distro.env, no runtime bash conditionals for distro detection. All distro-specific decisions are resolved at template render time from CI env vars.
  4. build.sh is replaced by build.py. The old build.sh should be removed.
  5. The old static container/Containerfile should be removed and replaced by container/Containerfile.j2.

Key Design Decisions

Environment Variables (inputs to build.py)

The Python script should consume the same CI environment variables that build.sh uses today:

Variable Default Description
FROM_IMAGE quay.io/centos/centos:stream9 Base container image
CI_CONTAINER false true for CI builds
FLAVOR default OSD flavor: default, crimson-debug, crimson-release, debug
BRANCH current git branch Ceph branch name
CEPH_SHA1 current git HEAD Ceph commit SHA1
ARCH host architecture x86_64 or arm64
CEPH_GIT_REPO auto-detected Git repo URL
CONTAINER_REPO_HOSTNAME quay.ceph.io Registry hostname
CONTAINER_REPO_ORGANIZATION ceph-ci (CI) / ceph (release) Registry org
CONTAINER_REPO ceph (CI) / prerelease-<arch> (release) Registry repo
CONTAINER_REPO_USERNAME — Registry auth username
CONTAINER_REPO_PASSWORD — Registry auth password
PRERELEASE_USERNAME — download.ceph.com credentials
PRERELEASE_PASSWORD — download.ceph.com credentials
REMOVE_LOCAL_IMAGES true Remove local images after push
NO_PUSH — Skip push step if set to true
VERSION latest annotated git tag For release builds
CONTAINER_ENGINE podman podman or docker
CUSTOM_CEPH_REPO_URL — Optional custom ceph repo URL for hackers
GANESHA_REPO_BASEURL https://buildlogs.centos.org/... NFS-Ganesha repo base URL

Distro Detection Logic

The Python script must derive from FROM_IMAGE:

  • distro_id: centos, rocky, or almalinux — parsed from the image name (e.g. quay.io/centos/centos:stream9 → centos, quay.io/rockylinux/rockylinux:10 → rocky)
  • distro_major: 9, 10, etc. — parsed from the image tag
  • el_ver: el9, el10, etc.
  • dist_path: centos/9, rocky/10, etc. — used in shaman API URLs

These are passed as Jinja2 template variables so all distro-specific decisions are resolved at render time, not at container build time.

Containerfile.j2 Template Design

The template should produce a clean, linear Dockerfile with no bash conditionals for distro detection. Key sections:

ARG FROM_IMAGE="{{ from_image }}"
FROM $FROM_IMAGE

# ... ARG declarations ...

SHELL ["/bin/bash", "-c"]

# Disable documentation
RUN ...

# Pre-reqs
RUN dnf install -y --setopt=install_weak_deps=False epel-release jq

# NFS-Ganesha repo
{% if distro_id == 'rocky' %}
RUN curl -fs -L "https://shaman.ceph.com/api/repos/nfs-ganesha/main/latest/{{ dist_path }}/repo?arch=$(arch)" \
    -o /etc/yum.repos.d/ganesha.repo
{% else %}
RUN printf '%s\n' '[ganesha]' 'name=ganesha' ... > /etc/yum.repos.d/ganesha.repo
{% endif %}

# iSCSI repo
RUN set -eux && \
    curl -s -L https://shaman.ceph.com/api/repos/tcmu-runner/main/latest/{{ dist_path }}/repo?arch=$(arch) \
        -o /etc/yum.repos.d/tcmu-runner.repo && \
    ...
    # Use {{ el_ver }} and {{ dist_path }} instead of runtime detection

# Ceph repo — use {{ el_ver }}, {{ dist_path }}
# ...

# Copr repos (only for EL <= 9)
{% if distro_major | int <= 9 %}
RUN dnf install -y ... dnf-plugins-core && dnf copr enable -y tchaikov/python-scikit-learn
{% endif %}

# Packages
RUN echo "..." > packages.txt
# ...

# Crimson packages
{% if osd_flavor in ('crimson-debug', 'crimson-release') %}
RUN echo "ceph-osd-crimson" >> packages.txt
{% endif %}

# python3-saml only on EL <= 9
{% if distro_major | int <= 9 %}
RUN echo "python3-saml" >> packages.txt
{% endif %}

# ... rest of install, cleanup, ENV ...

bui...

This pull request was created from Copilot chat.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

14 similar comments
@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

…thon script

- Remove container/Containerfile (replaced by container/Containerfile.j2)
- Remove container/build.sh (replaced by container/build.py)
- Add container/Containerfile.j2: Jinja2 template rendering a clean Dockerfile
  with no runtime distro-detection bash; all distro values resolved at render time
- Add container/build.py: PEP-8 Python script replacing build.sh

Key improvements over PR #67960 approach:
- No /etc/ceph-distro.env at container build time
- All distro-specific logic (el_ver, dist_path, ganesha repo style, copr repos,
  python3-saml) resolved via Jinja2 conditionals at template render time
- Supports centos/rocky/almalinux with EL9/EL10 detection from FROM_IMAGE
- Branch substring matching per review feedback (reef/squid in branch name)
- python3-saml comment explains SAML2->OAuth2 deprecation
- CUSTOM_CEPH_REPO_URL feature preserved
- Atomic secret file creation with o600 permissions (security fix)
- argparse CLI, logging, proper error handling in build.py

Agent-Logs-Url: https://github.com/ceph/ceph/sessions/7bf14465-0215-4f66-acda-948f28aa5710

Co-authored-by: epuertat <[email protected]>
Comment thread container/build.py
if not ci_container and not version:
errors.append("VERSION")
if errors:
log.error("Missing required environment variables: %s", ", ".join(errors))
Comment thread container/build.py
Comment on lines +143 to +147
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(tpl_dir),
keep_trailing_newline=True,
undefined=jinja2.StrictUndefined,
)
Copilot AI changed the title [WIP] Rewrite container image build approach with Jinja2 and Python container: rewrite multi-distro build to use Jinja2 template + Python script Apr 8, 2026
Copilot AI requested a review from epuertat April 8, 2026 09:19
@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions github-actions Bot added the stale label Jul 8, 2026
@batrick batrick added the releng-audit-fail Release engineering: failed backport verification audit. label Jul 11, 2026
@github-actions github-actions Bot removed the releng-audit-fail Release engineering: failed backport verification audit. label Jul 11, 2026
@batrick batrick added the releng-audit-fail Release engineering: failed backport verification audit. label Jul 11, 2026
@github-actions github-actions Bot removed the releng-audit-fail Release engineering: failed backport verification audit. label Jul 11, 2026
@batrick batrick added the releng-audit-fail Release engineering: failed backport verification audit. label Jul 11, 2026
@github-actions github-actions Bot removed the releng-audit-fail Release engineering: failed backport verification audit. label Jul 11, 2026
@batrick batrick added the releng-audit-fail Release engineering: failed backport verification audit. label Jul 11, 2026
@github-actions github-actions Bot removed releng-audit-fail Release engineering: failed backport verification audit. stale labels Jul 11, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions github-actions Bot added the stale label Sep 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no activity for 90 days. Please feel free to reopen this pull request (or open a new one) if the proposed change is still appropriate. Thank you for your contribution!

@github-actions github-actions Bot closed this Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants