From 51f614ca6f7c3f09eafe7837bda22f34af148b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Lehmann?= Date: Mon, 24 Feb 2025 16:43:33 +0100 Subject: [PATCH 1/4] pass mount flag required with podman and selinux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gaƫtan Lehmann Signed-off-by: Pau Ruiz Safont --- run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.py b/run.py index 80b6011..b4fdea8 100755 --- a/run.py +++ b/run.py @@ -125,7 +125,7 @@ def main(): if args.command != []: docker_args += ["-e", "COMMAND=%s" % ' '.join(args.command)] if args.build_local: - docker_args += ["-v", "%s:/home/builder/rpmbuild" % + docker_args += ["-v", "%s:/home/builder/rpmbuild:z" % os.path.abspath(args.build_local)] docker_args += ["-e", "BUILD_LOCAL=1"] if args.define: From ef531772effed87723fa8c46806e192b68031b69 Mon Sep 17 00:00:00 2001 From: Pau Ruiz Safont Date: Wed, 9 Jul 2025 09:31:54 +0100 Subject: [PATCH 2/4] run.py: use a default ulimit that allows xapi's tests to pass Signed-off-by: Pau Ruiz Safont --- run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.py b/run.py index b4fdea8..680654a 100755 --- a/run.py +++ b/run.py @@ -18,7 +18,7 @@ SRPMS_MOUNT_ROOT = "/tmp/docker-SRPMS" DEFAULT_BRANCH = '8.3' -DEFAULT_ULIMIT_NOFILE = 1024 +DEFAULT_ULIMIT_NOFILE = 2048 RUNNER = os.getenv("XCPNG_OCI_RUNNER") if RUNNER is None: From fd648e5c0187e7c30ff1891b1ec8202cd4d96979 Mon Sep 17 00:00:00 2001 From: Pau Ruiz Safont Date: Wed, 9 Jul 2025 09:55:12 +0100 Subject: [PATCH 3/4] package the python script so it can be installed with python tooling Adds instructions on the readme on how to do it. The name of the main script has been changed from run.py to xcp-ng-d.ev Adds a gitignore to ignore files produces by the packaging Signed-off-by: Pau Ruiz Safont --- .gitignore | 4 ++ README.md | 76 ++++++--------------------------- pyproject.toml | 20 +++++++++ src/xcp_ng_dev/__init__.py | 0 run.py => src/xcp_ng_dev/cli.py | 0 5 files changed, 38 insertions(+), 62 deletions(-) create mode 100644 .gitignore create mode 100644 pyproject.toml create mode 100644 src/xcp_ng_dev/__init__.py rename run.py => src/xcp_ng_dev/cli.py (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b95b6fb --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# Distribution / packaging +build/ +*.egg-info/ +__pycache__/ diff --git a/README.md b/README.md index 22a9d3f..bde85a2 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,9 @@ If you have both installed, docker will be used by default. If you want to use a specific container runtime, set `XCPNG_OCI_RUNNER` to the docker-compatible command to use (typically `podman` or `docker`). +You'll need to install git-lfs to be able to download the source tarballs from +git, otherwise when running xcp-ng-dev, it won't be able to extract the sources. + ## Building the container image(s) You need one container image per target version of XCP-ng. @@ -37,73 +40,22 @@ Usage: ./build.sh {version_of_XCP_ng} ## Using the container -Use the `run.py` script. It accepts a variety of parameters allowing for different uses: +Install the `xcp-ng-dev` script with however you usually install python +binaries. For example: + +`uv tool install --from path/to/xcp-ng-build-env xcp-ng-dev` +`pipx install path/to/xcpng-build-env` + +Use `xcp-ng-dev`. It accepts a variety of parameters allowing for different uses: * rebuild an existing source RPM (with automated installation of the build dependencies) * build a package from an already extracted source RPM (sources and spec file), or from a directory that follows the rpmbuild convention (a `SOURCES/` directory and a `SPECS/` directory). Most useful for building packages from XCP-ng's git repositories of RPM sources: https://github.com/xcp-ng-rpms. * or simply start a shell in the build environment, with the appropriate CentOS, EPEL and XCP-ng yum repositories enabled. -```sh -usage: run.py [-h] [-b BRANCH] [-l BUILD_LOCAL] [--define DEFINE] - [-r REBUILD_SRPM] [-o OUTPUT_DIR] [-n] [-p PACKAGE] [-s SRPM] - [-d DIR] [-e ENV] [-v VOLUME] [--rm] [--syslog] [--name NAME] - [-a ENABLEREPO] [--fail-on-error] - ... - -positional arguments: - command Command to run inside the prepared container - -optional arguments: - -h, --help show this help message and exit - -b BRANCH, --branch BRANCH - XCP-ng version: 7.6, 8.0, etc. If not set, will - default to 8.0. - -l BUILD_LOCAL, --build-local BUILD_LOCAL - Install dependencies for the spec file(s) found in the - SPECS/ subdirectory of the directory passed as - parameter, then build the RPM(s). Built RPMs and SRPMs - will be in RPMS/ and SRPMS/ subdirectories. Any - preexisting BUILD, BUILDROOT, RPMS or SRPMS - directories will be removed first. If --output-dir is - set, the RPMS and SRPMS directories will be copied to - it after the build. - --define DEFINE Definitions to be passed to rpmbuild (if --build-local - or --rebuild-srpm are passed too). Example: --define - 'xcp_ng_section extras', for building the 'extras' - version of a package which exists in both 'base' and - 'extras' versions. - -r REBUILD_SRPM, --rebuild-srpm REBUILD_SRPM - Install dependencies for the SRPM passed as parameter, - then build it. Requires the --output-dir parameter to - be set. - -o OUTPUT_DIR, --output-dir OUTPUT_DIR - Output directory for --rebuild-srpm and --build-local. - -n, --no-exit After executing either an automated build or a custom - command passed as parameter, drop user into a shell - -p PACKAGE, --package PACKAGE - Packages for which dependencies will be installed - -s SRPM, --srpm SRPM SRPMs for which dependencies will be installed - -d DIR, --dir DIR Local dir to mount in the image. Will be mounted at - /external/ - -e ENV, --env ENV Environment variables passed directly to docker -e - -v VOLUME, --volume VOLUME - Volume mounts passed directly to docker -v - --rm Destroy the container on exit - --syslog Enable syslog to host by mounting in /dev/log - --name NAME Assign a name to the container - -a ENABLEREPO, --enablerepo ENABLEREPO - additional repositories to enable before installing - build dependencies. Same syntax as yum's --enablerepo - parameter. Available additional repositories: xcp-ng- - updates_testing, xcp-ng-extras, xcp-ng-extras_testing. - --fail-on-error If container initialisation fails, exit rather than - dropping the user into a command shell -``` - **Examples** Rebuild an existing source RPM (with automated installation of the build dependencies) ```sh -./run.py -b 8.0 --rebuild-srpm /path/to/some-source-rpm.src.rpm --output-dir /path/to/output/directory --rm +xcp-ng-dev -b 8.2 --rebuild-srpm /path/to/some-source-rpm.src.rpm --output-dir /path/to/output/directory --rm ``` Build from git (and put the result into RPMS/ and SRPMS/ subdirectories) @@ -116,7 +68,7 @@ git clone https://github.com/xcp-ng-rpms/xapi.git # ... Here add your patches ... # Build. -/path/to/run.py -b 8.0 --build-local xapi/ --rm +xcp-ng-dev -b 8.2 --build-local xapi/ --rm ``` **Important switches** @@ -157,11 +109,11 @@ make If you'd like to develop using the tools on your host and preserve the changes to source and revision control but still use the container for building, you -can do using by mouning a volume in the container, using the `-v` option to mount +can do so by mounting a volume in the container, using the `-v` option to mount a directory from your host to a suitable point inside the container. For example, if I clone some repos into a directory on my host, say `/work/code/`, then I can mount it inside the container as follows: ```sh -./run.py -b 8.0 -v /work/code:/mnt/repos +xcp-ng-dev -b 8.2 -v /work/code:/mnt/repos ``` diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..59852c6 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,20 @@ +[project] +name = "xcp-ng-build" +description = "A tool to create XCP-ng-based build environments" +readme = "README.md" +requires-python = ">=3.9" +license = "MIT" +license-files = ["LICENSE"] +dynamic = ["version"] + +[project.scripts] +xcp-ng-dev = "xcp_ng_dev.cli:main" + +[project.urls] +Homepage = "https://github.com/xcp-ng/xcp-ng-build-env/" + +[build-system] +requires = ["setuptools >= 77.0.3", "setuptools-scm>=8"] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] diff --git a/src/xcp_ng_dev/__init__.py b/src/xcp_ng_dev/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/run.py b/src/xcp_ng_dev/cli.py similarity index 100% rename from run.py rename to src/xcp_ng_dev/cli.py From 950896f39d48677bffba1339a35f57b906cae888 Mon Sep 17 00:00:00 2001 From: Pau Ruiz Safont Date: Wed, 9 Jul 2025 14:39:13 +0100 Subject: [PATCH 4/4] Move build.sh to the new python package as xcp-ng-dev-build This needed a small bit of python glue code Signed-off-by: Pau Ruiz Safont --- README.md | 31 ++++++++++++++----- pyproject.toml | 1 + build.sh => src/xcp_ng_dev/build.sh | 8 +++-- src/xcp_ng_dev/cli.py | 4 +++ .../xcp_ng_dev/files}/CentOS-Vault.repo.in | 0 .../xcp_ng_dev/files/Dockerfile-7.x | 0 .../xcp_ng_dev/files/Dockerfile-8.x | 0 .../xcp_ng_dev/files}/init-container.sh | 0 {files => src/xcp_ng_dev/files}/rpmmacros | 0 .../xcp_ng_dev/files}/xcp-ng.repo.7.x.in | 0 .../xcp_ng_dev/files}/xcp-ng.repo.8.x.in | 0 {files => src/xcp_ng_dev/files}/yum.conf.xs | 0 12 files changed, 33 insertions(+), 11 deletions(-) rename build.sh => src/xcp_ng_dev/build.sh (93%) rename {files => src/xcp_ng_dev/files}/CentOS-Vault.repo.in (100%) rename Dockerfile-7.x => src/xcp_ng_dev/files/Dockerfile-7.x (100%) rename Dockerfile-8.x => src/xcp_ng_dev/files/Dockerfile-8.x (100%) rename {files => src/xcp_ng_dev/files}/init-container.sh (100%) rename {files => src/xcp_ng_dev/files}/rpmmacros (100%) rename {files => src/xcp_ng_dev/files}/xcp-ng.repo.7.x.in (100%) rename {files => src/xcp_ng_dev/files}/xcp-ng.repo.8.x.in (100%) rename {files => src/xcp_ng_dev/files}/yum.conf.xs (100%) diff --git a/README.md b/README.md index bde85a2..781c2b1 100644 --- a/README.md +++ b/README.md @@ -25,27 +25,42 @@ the docker-compatible command to use (typically `podman` or `docker`). You'll need to install git-lfs to be able to download the source tarballs from git, otherwise when running xcp-ng-dev, it won't be able to extract the sources. +## Installation + +Clone this repository and install the `xcp-ng-dev` package: + +```bash +git clone xcp-ng/xcp-ng-build-env +cd xcp-ng-build-env +uv tool install --editable . +``` + +If `uv` is not available you can use other tools to install python packages, +like `pipx install --editable .` + +Using the `--editable` flag will allow you to update the cli tools just by +updating the contents of the git repository, without reinstalling. +If you do not want this behaviour, use: `uv tool install --from . xcp-ng-dev` +or `pipx install .` + +After this, two new commands will be available: `xcp-ng-dev-env-create` and +`xcp-ng-dev`. + ## Building the container image(s) You need one container image per target version of XCP-ng. -Clone this repository (outside any container), then use `build.sh` to +Clone this repository (outside any container), then use `xcp-ng-dev-env-create` to generate the images for the wanted releases of XCP-ng. Note that Docker and Podman store container images separately. ``` -Usage: ./build.sh {version_of_XCP_ng} +Usage: xcp-ng-dev-env-create {version_of_XCP_ng} ... where {version_of_XCP_ng} is a 'x.y' version such as 8.0. ``` ## Using the container -Install the `xcp-ng-dev` script with however you usually install python -binaries. For example: - -`uv tool install --from path/to/xcp-ng-build-env xcp-ng-dev` -`pipx install path/to/xcpng-build-env` - Use `xcp-ng-dev`. It accepts a variety of parameters allowing for different uses: * rebuild an existing source RPM (with automated installation of the build dependencies) * build a package from an already extracted source RPM (sources and spec file), or from a directory that follows the rpmbuild convention (a `SOURCES/` directory and a `SPECS/` directory). Most useful for building packages from XCP-ng's git repositories of RPM sources: https://github.com/xcp-ng-rpms. diff --git a/pyproject.toml b/pyproject.toml index 59852c6..0a6fffe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,6 +9,7 @@ dynamic = ["version"] [project.scripts] xcp-ng-dev = "xcp_ng_dev.cli:main" +xcp-ng-dev-env-create = "xcp_ng_dev.cli:build" [project.urls] Homepage = "https://github.com/xcp-ng/xcp-ng-build-env/" diff --git a/build.sh b/src/xcp_ng_dev/build.sh similarity index 93% rename from build.sh rename to src/xcp_ng_dev/build.sh index 1c6b21d..eedfa98 100755 --- a/build.sh +++ b/src/xcp_ng_dev/build.sh @@ -2,8 +2,10 @@ set -e +SELF_NAME="xcp-ng-dev-env-create" + if [ -z "$1" ]; then - echo "Usage: $0 {version}" + echo "Usage: $SELF_NAME {version}" echo "... where {version} is a 'x.y' version such as 8.0." exit fi @@ -32,12 +34,12 @@ CUSTOM_ARGS=() case "$1" in 7.*) REPO_FILE=files/xcp-ng.repo.7.x.in - DOCKERFILE=Dockerfile-7.x + DOCKERFILE=files/Dockerfile-7.x CENTOS_VERSION=7.2.1511 ;; 8.*) REPO_FILE=files/xcp-ng.repo.8.x.in - DOCKERFILE=Dockerfile-8.x + DOCKERFILE=files/Dockerfile-8.x CENTOS_VERSION=7.5.1804 ;; *) diff --git a/src/xcp_ng_dev/cli.py b/src/xcp_ng_dev/cli.py index 680654a..6f0be70 100755 --- a/src/xcp_ng_dev/cli.py +++ b/src/xcp_ng_dev/cli.py @@ -204,6 +204,10 @@ def main(): sys.exit(return_code) +def build(): + bargs = [os.path.join(os.path.dirname(__file__ ), 'build.sh')] + sys.argv[1:] + return_code = subprocess.call(bargs) + sys.exit(return_code) if __name__ == "__main__": main() diff --git a/files/CentOS-Vault.repo.in b/src/xcp_ng_dev/files/CentOS-Vault.repo.in similarity index 100% rename from files/CentOS-Vault.repo.in rename to src/xcp_ng_dev/files/CentOS-Vault.repo.in diff --git a/Dockerfile-7.x b/src/xcp_ng_dev/files/Dockerfile-7.x similarity index 100% rename from Dockerfile-7.x rename to src/xcp_ng_dev/files/Dockerfile-7.x diff --git a/Dockerfile-8.x b/src/xcp_ng_dev/files/Dockerfile-8.x similarity index 100% rename from Dockerfile-8.x rename to src/xcp_ng_dev/files/Dockerfile-8.x diff --git a/files/init-container.sh b/src/xcp_ng_dev/files/init-container.sh similarity index 100% rename from files/init-container.sh rename to src/xcp_ng_dev/files/init-container.sh diff --git a/files/rpmmacros b/src/xcp_ng_dev/files/rpmmacros similarity index 100% rename from files/rpmmacros rename to src/xcp_ng_dev/files/rpmmacros diff --git a/files/xcp-ng.repo.7.x.in b/src/xcp_ng_dev/files/xcp-ng.repo.7.x.in similarity index 100% rename from files/xcp-ng.repo.7.x.in rename to src/xcp_ng_dev/files/xcp-ng.repo.7.x.in diff --git a/files/xcp-ng.repo.8.x.in b/src/xcp_ng_dev/files/xcp-ng.repo.8.x.in similarity index 100% rename from files/xcp-ng.repo.8.x.in rename to src/xcp_ng_dev/files/xcp-ng.repo.8.x.in diff --git a/files/yum.conf.xs b/src/xcp_ng_dev/files/yum.conf.xs similarity index 100% rename from files/yum.conf.xs rename to src/xcp_ng_dev/files/yum.conf.xs