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..781c2b1 100644 --- a/README.md +++ b/README.md @@ -22,88 +22,55 @@ 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. + +## 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 -Use the `run.py` script. It accepts a variety of parameters allowing for different uses: +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 +83,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 +124,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..0a6fffe --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,21 @@ +[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" +xcp-ng-dev-env-create = "xcp_ng_dev.cli:build" + +[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/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/run.py b/src/xcp_ng_dev/cli.py similarity index 97% rename from run.py rename to src/xcp_ng_dev/cli.py index 80b6011..6f0be70 100755 --- a/run.py +++ b/src/xcp_ng_dev/cli.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: @@ -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: @@ -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