Skip to content

containerized build tools [V2] - #59841

Merged
zmc merged 4 commits into
ceph:mainfrom
phlogistonjohn:jjm-containerized-build-pyalt
Feb 6, 2025
Merged

zmc merged 4 commits into
ceph:mainfrom
phlogistonjohn:jjm-containerized-build-pyalt

Conversation

@phlogistonjohn

@phlogistonjohn phlogistonjohn commented Sep 17, 2024 •

Copy link
Copy Markdown
Contributor

After a series of discussions, particularly with Zack C and Dan Mick, I've created a new patch series to replace those in #56711.

This version simplifies the (Container|Docker)file and and replaces the harder to maintain shell script wrapper with a more logical and well constructed python script. Right now there are also a couple of patches present in the branch that I needed to make it compile the unit tests. I plan on moving these out eventually as separate PRs.

PRs and issues related to building in containers:

How to test & try

  1. Get the patches
    Assuming you have a git checkout of ceph/ceph already:
    1. git remote add -t jjm-containerized-build-pyalt phlogistonjohn [email protected]:phlogistonjohn/ceph.git
    2. git fetch phlogistonjohn
    3. git switch jjm-containerized-build-pyalt
    4. (AND/OR) git switch -c mybranch jjm-containerized-build-pyalt
  2. View the instructions at the top of ./src/script/build-with-container.py
  3. Give it a go. Some examples:
    • python3 src/script/build-with-container.py -d centos9 -b build.c9
    • python3 src/script/build-with-container.py -d ubuntu22.04 -b build.u22 -e build -e tests
    • python3 src/script/build-with-container.py -d centos9 -b build.c9 -e rpm

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

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
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows
  • jenkins test rook e2e

@phlogistonjohn
phlogistonjohn force-pushed the jjm-containerized-build-pyalt branch from be3b8af to ccdda2e Compare September 17, 2024 14:48
@phlogistonjohn
phlogistonjohn force-pushed the jjm-containerized-build-pyalt branch 2 times, most recently from 6e8086f to 4801522 Compare October 9, 2024 18:57
@phlogistonjohn
phlogistonjohn force-pushed the jjm-containerized-build-pyalt branch 2 times, most recently from c04a52e to 3edeefa Compare October 30, 2024 19:28
@phlogistonjohn phlogistonjohn mentioned this pull request Nov 20, 2024
14 tasks
Comment thread src/script/buildcontainer-setup.sh Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we just use the steps at https://docs.ceph.com/en/squid/start/beginners-guide/ to setup the environment?

as in use install-deps.sh so that we can keep all the dependencies per OS etc are all in the same place?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's a maze of twisty passages throughout these build scripts. This eventually does end up calling install-deps.sh. Without doing a deep check the flow is "include run-make.sh" -> prepare -> install-deps.sh.

I'd love to simplify some of this but this script was added to (a) match more closely what the jenkins builds are doing (b) add extra packages needed to "fix" the container environment where install-deps either misses or doesn't need something but the containerized env does.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

gotcha.

so is the goal - to deprecate install-deps.sh once we get this simplified version done? so that how folks build it locally and how its build in jenkins is consistent(?)

As for the "additional" dependencies needed just for container builds - would it make sense to keep that as a separate list/script so that we can dig into why that difference exists and document it out?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

While I'm not a fan of install-deps.sh, I think it is correct that we use this to install all the dependency packages needed for building ceph. I'm not sure about the extra couple of packages that are being installed for the different distro's below - I think these are really missing dependencies and that we should be fixing install-deps.sh so that it installs these packages as well.

Comment thread src/test/cls_log/test_cls_log.cc Resolved
Comment thread src/test/fio/fio_librgw.cc Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

unsure why we need this - can/should we make this a separate PR (assuming this fixes some problem you ran into)

Also - i would think it makes sense to check the return code instead of removing it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, thanks for the reminder. I have also created a PR for this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FYI - got the PR merged

Comment thread src/script/buildcontainer-setup.sh Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

gotcha.

so is the goal - to deprecate install-deps.sh once we get this simplified version done? so that how folks build it locally and how its build in jenkins is consistent(?)

As for the "additional" dependencies needed just for container builds - would it make sense to keep that as a separate list/script so that we can dig into why that difference exists and document it out?

Comment thread src/script/buildcontainer-setup.sh Resolved
@jmundack

Copy link
Copy Markdown
Contributor

general question - do we want to add some non blocking (while we are flushing out the details) PR checks to make sure the containerized builds wont break on a code/dependency change?

@phlogistonjohn
phlogistonjohn force-pushed the jjm-containerized-build-pyalt branch from 5ace380 to 152a070 Compare December 14, 2024 15:35
@phlogistonjohn

Copy link
Copy Markdown
Contributor Author

general question - do we want to add some non blocking (while we are flushing out the details) PR checks to make sure the containerized builds wont break on a code/dependency change?

I'm open to the idea, but I'm not sure where to begin. What are you thinking of in particular?

@phlogistonjohn

Copy link
Copy Markdown
Contributor Author

I've cleaned up the content of this branch a lot. I've removed a lot of the WIP patches that existed to get certain builds passing - you can still run them, but failures are expected.
The WIP stuff now exists in my jjm-containerized-build-wip1 branch

This should make the current PR easier to try out and to review, but if you do want to experiment with it in practice you may still end up need patches from that other branch.

@phlogistonjohn
phlogistonjohn force-pushed the jjm-containerized-build-pyalt branch 2 times, most recently from 9d93790 to 08fa675 Compare December 15, 2024 16:04
Comment thread Dockerfile.build Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this line accurate? COPY from /usr/local/src/ceph to /usr/local/src/ceph?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, the --from=bootstrap part means copy said path from the build container named boostrap. This container (layer) was already created in previous steps and populated /usr/local/src/ceph. (Maybe think of it more like scp'ing from host1's /usr/local/src/ceph to host2 of the same dir?)

@phlogistonjohn phlogistonjohn Dec 16, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If you're curious why I did it this way:

  • it produces fewer layers in the final image - the COPY statements in the bootstrap build container each produce a layer - but this single COPY statement produces one layer in the resulting image
  • it felt nice to organize the "minimal" set of files taken from the ceph tree needed to create the build image all together in one logical block

@phlogistonjohn
phlogistonjohn force-pushed the jjm-containerized-build-pyalt branch 2 times, most recently from 668cd3b to 68f0355 Compare December 16, 2024 21:49
@jmundack

Copy link
Copy Markdown
Contributor

@phlogistonjohn - can we also add some instruction on how to build/test this? (i am hoping to play with it and also help fix some of the open trackers linked here)

@phlogistonjohn

Copy link
Copy Markdown
Contributor Author

new instructions have been added to the PR description under How to test & try. I wrote it fast and can't really test it myself because I'm the author :-) So feedback on that is very much welcome.

@phlogistonjohn
phlogistonjohn force-pushed the jjm-containerized-build-pyalt branch 3 times, most recently from 0174947 to 571b196 Compare December 18, 2024 21:55
@dparmar18

Copy link
Copy Markdown
Contributor

I like this initiative @phlogistonjohn. This PR made me recall making use of Rook for testing my NFS related patches last year. It was as simple as having a Dockerfile with custom built binaries, add it to my quay account and use it in config YAML to spin up a cluster. So, having something like this within Ceph repo is really helpful. I'll plan to use this in some of my upcoming testings.

@jmundack

jmundack commented Jan 8, 2025

Copy link
Copy Markdown
Contributor

one feedback item

  • having an option to override the url for the base OS image and what the OS is (centos vs ubuntu) would be useful for environments that don't have connectivity to the internet or i you want to use a custom local image

@phlogistonjohn
phlogistonjohn force-pushed the jjm-containerized-build-pyalt branch from 571b196 to cdf9bdc Compare January 8, 2025 23:42
@ronen-fr

ronen-fr commented Feb 4, 2025

Copy link
Copy Markdown
Contributor

@phlogistonjohn hi, John. Two question:

  1. how to prevent the script from filling up /var/tmp?
    when trying (for example: ./src/script/build-with-container.py -d centos9 -b configure -e tests --homedir ~/src/cont59841 --keep-container, with or without the homedir param), I get:

_> [2/2] COMMIT ceph-build:ctr1.centos9

Error: committing container for step {Env:[CEPH_CTR_SRC=/usr/local/src/ceph CLEAN_DNF=yes CEPH_BRANCH=main DISTRO=quay.io/centos/centos:stream9 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin FOR_MAKE_CHECK=1] Command:run Args:[DISTRO=$DISTRO CEPH_BRANCH=$CEPH_BRANCH CLEAN_DNF=$CLEAN_DNF CEPH_CTR_SRC=${CEPH_CTR_SRC} bash -x ${CEPH_CTR_SRC}/buildcontainer-setup.sh] Flags:[] Attrs:map[] Message:RUN DISTRO=$DISTRO CEPH_BRANCH=$CEPH_BRANCH CLEAN_DNF=$CLEAN_DNF CEPH_CTR_SRC=${CEPH_CTR_SRC} bash -x ${CEPH_CTR_SRC}/buildcontainer-setup.sh Heredocs:[] Original:RUN DISTRO=$DISTRO CEPH_BRANCH=$CEPH_BRANCH CLEAN_DNF=$CLEAN_DNF CEPH_CTR_SRC=${CEPH_CTR_SRC} bash -x ${CEPH_CTR_SRC}/buildcontainer-setup.sh}: copying layers and metadata for container "04572749a7b8431ab8e7bed83e3bc295e7c00d3ab41a210d8825384bb8e30211": writing blob: storing blob to file "/var/tmp/container_images_storage108785264/1": write /var/tmp/container_images_storage108785264/1: no space left on device
2025-02-04 07:31:33,502: ERROR: Command failed: Command '['podman', 'build', '-t', 'ceph-build:ctr1.centos9', '--build-arg=JENKINS_HOME=/home/rfriedma/src/cont59841', '--build-arg=DISTRO=quay.io/centos/centos:stream9', '--volume=/mnt/nvme0/src/cont59841/ceph:/home/rfriedma/src/cont59841:Z', '-f', 'Dockerfile.build', '.']' returned non-zero exit status 125._

And - 2- how to create the build environment for Reef?
tried 'CEPH_REF=reef ./src/script/build-with-container.py ...'
but it seems that 'main' was still the one selected.

Thanks!

@phlogistonjohn

phlogistonjohn commented Feb 4, 2025 •

Copy link
Copy Markdown
Contributor Author

Thanks for trying it out!

@phlogistonjohn hi, John. Two question:

1. how to prevent the script from filling up /var/tmp?
   when trying (for example: `./src/script/build-with-container.py -d centos9 -b configure -e tests --homedir ~/src/cont59841 --keep-container`, with or without the homedir param), I get:

_> [2/2] COMMIT ceph-build:ctr1.centos9

Error: committing container for step {Env:[CEPH_CTR_SRC=/usr/local/src/ceph CLEAN_DNF=yes CEPH_BRANCH=main DISTRO=quay.io/centos/centos:stream9 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin FOR_MAKE_CHECK=1] Command:run Args:[DISTRO=$DISTRO CEPH_BRANCH=$CEPH_BRANCH CLEAN_DNF=$CLEAN_DNF CEPH_CTR_SRC=${CEPH_CTR_SRC} bash -x ${CEPH_CTR_SRC}/buildcontainer-setup.sh] Flags:[] Attrs:map[] Message:RUN DISTRO=$DISTRO CEPH_BRANCH=$CEPH_BRANCH CLEAN_DNF=$CLEAN_DNF CEPH_CTR_SRC=${CEPH_CTR_SRC} bash -x ${CEPH_CTR_SRC}/buildcontainer-setup.sh Heredocs:[] Original:RUN DISTRO=$DISTRO CEPH_BRANCH=$CEPH_BRANCH CLEAN_DNF=$CLEAN_DNF CEPH_CTR_SRC=${CEPH_CTR_SRC} bash -x ${CEPH_CTR_SRC}/buildcontainer-setup.sh}: copying layers and metadata for container "04572749a7b8431ab8e7bed83e3bc295e7c00d3ab41a210d8825384bb8e30211": writing blob: storing blob to file "/var/tmp/container_images_storage108785264/1": write /var/tmp/container_images_storage108785264/1: no space left on device
2025-02-04 07:31:33,502: ERROR: Command failed: Command '['podman', 'build', '-t', 'ceph-build:ctr1.centos9', '--build-arg=JENKINS_HOME=/home/rfriedma/src/cont59841', '--build-arg=DISTRO=quay.io/centos/centos:stream9', '--volume=/mnt/nvme0/src/cont59841/ceph:/home/rfriedma/src/cont59841:Z', '-f', 'Dockerfile.build', '.']' returned non-zero exit status 125._

Interesting. I have not seen that before. Are you able to build container images successfully with podman normally? If yes let's try to execute the build command (seen in the output - minus the comma separators) without the script involved. If no, we will probably need to debug your podman/system setup a bit.

And - 2- how to create the build environment for Reef? tried 'CEPH_REF=reef ./src/script/build-with-container.py ...' but it seems that 'main' was still the one selected.

We would need to backport PR #48697 and these patches to reef. I tried to do a quick and dirty backport here. I was able to build a ubuntu 22.04 builder image but then ceph failed to configure due to some dpdk error. Unfortunately , I don't have time to debug that today. Maybe later this week.

[EDIT] Actually, because I was in a rush I wasn't paying attention and notice /remember that my reef dir was a git worktree. Worktree checkouts won't work with the script because we mount the current ceph tree into the container and that is not compatible with worktrees. Making a reef clone and the retrying now has me at step 202/1316 of the build. No promises that this will complete without error though :-)

@bill-scales

Copy link
Copy Markdown
Contributor

@ronen-fr we use podman quite a bit and have also had issues with /var/ filling up (and $HOME when not running as root). Other than increasing the size of /var and $HOME there are a couple of solutions:

  1. Use the environment variable TMPDIR to have podman place container images somewhere other than /var/tmp
    or

  2. Create symbolic links for /var/lib/containers and $HOME/.local/share/containers/ to a directory that has more space. If the system has selinux then moving /var/lib/containers can cause problems - you need something like this to keep it happy:

    mv /var/lib/containers/ /extra/containers
    ln -s /extra/containers/ /var/lib/containers
    semanage fcontext -a -e /var/lib/containers /extra/containers
    restorecon -R -v /extra/containers

@ronen-fr

ronen-fr commented Feb 5, 2025

Copy link
Copy Markdown
Contributor

@bill-scales

@ronen-fr we use podman quite a bit and have also had issues with /var/ filling up (and $HOME when not running as root). Other than increasing the size of /var and $HOME there are a couple of solutions:

Thanks a lot!

@phlogistonjohn
phlogistonjohn force-pushed the jjm-containerized-build-pyalt branch from ee0762f to da6856a Compare February 5, 2025 20:12
This function returns successfully if $BUILD_DIR exists and is valid.
This is a useful building block for automation around the build and
can be used to avoid re-running commands that fail is the build dir
exists already.

Signed-off-by: John Mulligan <[email protected]>
Move the mkdir line to allow for other builds dir naming schemes outside
of what appears in the .gitignore file. A tiny bit of added flexibility
at little cost.

Signed-off-by: John Mulligan <[email protected]>
A build container contains all the tools and dependencies needed to
build ceph. It provides a Container file and small script that
helps bootstrap the container setup. This script installs a few extra
things we need before farming most of the work out to install-deps.sh.

Signed-off-by: John Mulligan <[email protected]>
The build-with-container script tries to encapsulate nearly all major
build tasks using docker/podman containers. If there's no build image
locally it will create one for your. It provides targets for building
(make), testing (make check), building rpm packages or deb packages and
is designed to be fairly easily extended.

View the comment at the top of the source file for usage details.

Signed-off-by: John Mulligan <[email protected]>
@phlogistonjohn
phlogistonjohn force-pushed the jjm-containerized-build-pyalt branch from da6856a to f276cc5 Compare February 5, 2025 20:13
@phlogistonjohn

Copy link
Copy Markdown
Contributor Author

Moving out of draft as per discussion on 02/05.

@phlogistonjohn
phlogistonjohn marked this pull request as ready for review February 5, 2025 20:15
@phlogistonjohn phlogistonjohn changed the title [WIP] containerized build tools [V2] containerized build tools [V2] Feb 5, 2025
@zmc

zmc commented Feb 5, 2025

Copy link
Copy Markdown
Member

@phlogistonjohn @ronen-fr @bill-scales

To free up space, I personally use podman system prune a lot. A larger hammer is podman system reset

@zmc

zmc commented Feb 6, 2025

Copy link
Copy Markdown
Member

I think this is ready to merge and iterate on. I am going to start work on integrating it with the new build pipeline, which should also be ready to merge: ceph/ceph-build#2310

@zmc
zmc merged commit 4244480 into ceph:main Feb 6, 2025
@phlogistonjohn
phlogistonjohn deleted the jjm-containerized-build-pyalt branch February 6, 2025 14:55
@fayak

fayak commented Feb 17, 2025

Copy link
Copy Markdown
Contributor

Hello @phlogistonjohn !
Thanks for the tool, I could definitely benefit from it :)
Is it planned to work with docker ?
When trying to build something I have

2025-02-17 17:22:53,005: INFO: Executing command: docker build -t ceph-build:main.centos9 --build-arg=JENKINS_HOME=/ceph --build-arg=DISTRO=quay.io/centos/centos:stream9 --volume=/home/zarak/Docs/ceph:/ceph:Z -f Dockerfile.build .
unknown flag: --volume
See 'docker buildx build --help'.
2025-02-17 17:22:53,116: ERROR: Command failed: Command '['docker', 'build', '-t', 'ceph-build:main.centos9', '--build-arg=JENKINS_HOME=/ceph', '--build-arg=DISTRO=quay.io/centos/centos:stream9', '--volume=/home/zarak/Docs/ceph:/ceph:Z', '-f', 'Dockerfile.build', '.']' returned non-zero exit status 125.

I can see that the --volume option is used but it is not supported by docker buildx. Am I missing something like some upcoming update of docker supporting this option, or is it some podman only option ?

@phlogistonjohn

Copy link
Copy Markdown
Contributor Author

It is supposed to work, but I never test it with docker. I rely on others to try it with docker.

Since docker apparently doesn't support passing the --volume option to build, you can try commenting out the section:

    if ctx.cli.homedir:
        cwd = pathlib.Path(".").absolute()
        cmd.append(f"--volume={cwd}:{ctx.cli.homedir}:Z")

in the build_container funciton.

Otherwise please file a tracker issue on ceph: https://tracker.ceph.com - use the ceph project ( https://tracker.ceph.com/projects/ceph/issues/new ) and the build category. I will try to look into it soon. Thanks.

phlogistonjohn added a commit to phlogistonjohn/ceph that referenced this pull request Feb 27, 2025
On the original github pr ceph#59841 user fayak kindly informed us that the
--volume option was not supported by docker build. Since this section
was a leftover from a previous way of constructing the builder image and
was no longer needed we simply removed it.

Signed-off-by: John Mulligan <[email protected]>
phlogistonjohn added a commit to phlogistonjohn/ceph that referenced this pull request Feb 28, 2025
On the original github pr ceph#59841 user fayak kindly informed us that the
--volume option was not supported by docker build. Since this section
was a leftover from a previous way of constructing the builder image and
was no longer needed we simply removed it.

Signed-off-by: John Mulligan <[email protected]>
phlogistonjohn added a commit to phlogistonjohn/ceph that referenced this pull request Mar 6, 2025
On the original github pr ceph#59841 user fayak kindly informed us that the
--volume option was not supported by docker build. Since this section
was a leftover from a previous way of constructing the builder image and
was no longer needed we simply removed it.

Signed-off-by: John Mulligan <[email protected]>
(cherry picked from commit 612a9d6)
phlogistonjohn added a commit to phlogistonjohn/ceph that referenced this pull request Mar 6, 2025
On the original github pr ceph#59841 user fayak kindly informed us that the
--volume option was not supported by docker build. Since this section
was a leftover from a previous way of constructing the builder image and
was no longer needed we simply removed it.

Signed-off-by: John Mulligan <[email protected]>
(cherry picked from commit 612a9d6)
kamoltat pushed a commit to kamoltat/ceph that referenced this pull request Oct 14, 2025
On the original github pr ceph#59841 user fayak kindly informed us that the
--volume option was not supported by docker build. Since this section
was a leftover from a previous way of constructing the builder image and
was no longer needed we simply removed it.

Signed-off-by: John Mulligan <[email protected]>
(cherry picked from commit 612a9d6)
(cherry picked from commit e56df19)
afreen23 pushed a commit to rhcs-dashboard/ceph that referenced this pull request Jul 29, 2026
On the original github pr ceph#59841 user fayak kindly informed us that the
--volume option was not supported by docker build. Since this section
was a leftover from a previous way of constructing the builder image and
was no longer needed we simply removed it.

Signed-off-by: John Mulligan <[email protected]>
(cherry picked from commit 99d1b71)
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.

10 participants