Skip to content

Commit f1df55e

Browse files
committed
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 <[email protected]>
1 parent ef53177 commit f1df55e

File tree

5 files changed

+63
-26
lines changed

5 files changed

+63
-26
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Distribution / packaging
2+
build/
3+
*.egg-info/

README.md

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ If you have both installed, docker will be used by default. If you
2222
want to use a specific container runtime, set `XCPNG_OCI_RUNNER` to
2323
the docker-compatible command to use (typically `podman` or `docker`).
2424

25+
You'll need to install git-lfs to be able to download the source tarballs from
26+
git, otherwise when running xcp-ng-dev, it won't be able to extract the sources.
27+
2528
## Building the container image(s)
2629

2730
You need one container image per target version of XCP-ng.
@@ -37,27 +40,33 @@ Usage: ./build.sh {version_of_XCP_ng}
3740

3841
## Using the container
3942

40-
Use the `run.py` script. It accepts a variety of parameters allowing for different uses:
43+
Install the `xcp-ng-dev` script with however you usually install python
44+
binaries. For example:
45+
46+
`uv tool install --from path/to/xcp-ng-build-env xcp-ng-build`
47+
`pipx install path/to/xcpng-build-env`
48+
49+
Use `xcp-ng-dev`. It accepts a variety of parameters allowing for different uses:
4150
* rebuild an existing source RPM (with automated installation of the build dependencies)
4251
* 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.
4352
* or simply start a shell in the build environment, with the appropriate CentOS, EPEL and XCP-ng yum repositories enabled.
4453

4554
```sh
46-
usage: run.py [-h] [-b BRANCH] [-l BUILD_LOCAL] [--define DEFINE]
47-
[-r REBUILD_SRPM] [-o OUTPUT_DIR] [-n] [-p PACKAGE] [-s SRPM]
48-
[-d DIR] [-e ENV] [-v VOLUME] [--rm] [--syslog] [--name NAME]
49-
[-a ENABLEREPO] [--fail-on-error]
50-
...
55+
usage: xcp-ng-dev [-h] [-b BRANCH] [-l BUILD_LOCAL] [--define DEFINE]
56+
[-r REBUILD_SRPM] [-o OUTPUT_DIR] [-n] [-p PACKAGE]
57+
[-s SRPM] [-d DIR] [-e ENV] [-v VOLUME] [--rm] [--syslog]
58+
[--name NAME] [--ulimit ULIMIT] [-a ENABLEREPO]
59+
[--disablerepo DISABLEREPO] [--fail-on-error]
60+
...
5161

5262
positional arguments:
5363
command Command to run inside the prepared container
5464

55-
optional arguments:
65+
options:
5666
-h, --help show this help message and exit
57-
-b BRANCH, --branch BRANCH
58-
XCP-ng version: 7.6, 8.0, etc. If not set, will
59-
default to 8.0.
60-
-l BUILD_LOCAL, --build-local BUILD_LOCAL
67+
-b, --branch BRANCH XCP-ng version: 7.6, 8.3, etc. If not set, will
68+
default to 8.3.
69+
-l, --build-local BUILD_LOCAL
6170
Install dependencies for the spec file(s) found in the
6271
SPECS/ subdirectory of the directory passed as
6372
parameter, then build the RPM(s). Built RPMs and SRPMs
@@ -71,30 +80,35 @@ optional arguments:
7180
'xcp_ng_section extras', for building the 'extras'
7281
version of a package which exists in both 'base' and
7382
'extras' versions.
74-
-r REBUILD_SRPM, --rebuild-srpm REBUILD_SRPM
83+
-r, --rebuild-srpm REBUILD_SRPM
7584
Install dependencies for the SRPM passed as parameter,
7685
then build it. Requires the --output-dir parameter to
7786
be set.
78-
-o OUTPUT_DIR, --output-dir OUTPUT_DIR
87+
-o, --output-dir OUTPUT_DIR
7988
Output directory for --rebuild-srpm and --build-local.
8089
-n, --no-exit After executing either an automated build or a custom
8190
command passed as parameter, drop user into a shell
82-
-p PACKAGE, --package PACKAGE
91+
-p, --package PACKAGE
8392
Packages for which dependencies will be installed
84-
-s SRPM, --srpm SRPM SRPMs for which dependencies will be installed
85-
-d DIR, --dir DIR Local dir to mount in the image. Will be mounted at
93+
-s, --srpm SRPM SRPMs for which dependencies will be installed
94+
-d, --dir DIR Local dir to mount in the image. Will be mounted at
8695
/external/<dirname>
87-
-e ENV, --env ENV Environment variables passed directly to docker -e
88-
-v VOLUME, --volume VOLUME
89-
Volume mounts passed directly to docker -v
96+
-e, --env ENV Environment variables passed directly to docker -e
97+
-v, --volume VOLUME Volume mounts passed directly to docker -v
9098
--rm Destroy the container on exit
9199
--syslog Enable syslog to host by mounting in /dev/log
92100
--name NAME Assign a name to the container
93-
-a ENABLEREPO, --enablerepo ENABLEREPO
101+
--ulimit ULIMIT Ulimit options passed directly to docker run
102+
-a, --enablerepo ENABLEREPO
94103
additional repositories to enable before installing
95104
build dependencies. Same syntax as yum's --enablerepo
96-
parameter. Available additional repositories: xcp-ng-
97-
updates_testing, xcp-ng-extras, xcp-ng-extras_testing.
105+
parameter. Available additional repositories: check
106+
files/xcp-ng.repo.*.x.in.
107+
--disablerepo DISABLEREPO
108+
disable repositories. Same syntax as yum's
109+
--disablerepo parameter. If both --enablerepo and
110+
--disablerepo are set, --disablerepo will be applied
111+
first
98112
--fail-on-error If container initialisation fails, exit rather than
99113
dropping the user into a command shell
100114
```
@@ -103,7 +117,7 @@ optional arguments:
103117
104118
Rebuild an existing source RPM (with automated installation of the build dependencies)
105119
```sh
106-
./run.py -b 8.0 --rebuild-srpm /path/to/some-source-rpm.src.rpm --output-dir /path/to/output/directory --rm
120+
xcp-ng-dev -b 8.2 --rebuild-srpm /path/to/some-source-rpm.src.rpm --output-dir /path/to/output/directory --rm
107121
```
108122
109123
Build from git (and put the result into RPMS/ and SRPMS/ subdirectories)
@@ -116,7 +130,7 @@ git clone https://github.com/xcp-ng-rpms/xapi.git
116130
# ... Here add your patches ...
117131

118132
# Build.
119-
/path/to/run.py -b 8.0 --build-local xapi/ --rm
133+
xcp-ng-dev -b 8.2 --build-local xapi/ --rm
120134
```
121135
122136
**Important switches**
@@ -157,11 +171,11 @@ make
157171
158172
If you'd like to develop using the tools on your host and preserve the changes
159173
to source and revision control but still use the container for building, you
160-
can do using by mouning a volume in the container, using the `-v` option to mount
174+
can do using by mounting a volume in the container, using the `-v` option to mount
161175
a directory from your host to a suitable point inside the container. For
162176
example, if I clone some repos into a directory on my host, say `/work/code/`,
163177
then I can mount it inside the container as follows:
164178
165179
```sh
166-
./run.py -b 8.0 -v /work/code:/mnt/repos
180+
xcp-ng-dev -b 8.2 -v /work/code:/mnt/repos
167181
```

pyproject.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[project]
2+
name = "xcp-ng-build"
3+
description = "A tool to create XCP-ng-based build environments"
4+
readme = "README.md"
5+
requires-python = ">=3.9"
6+
license = "MIT"
7+
license-files = ["LICENSE"]
8+
dynamic = ["version"]
9+
10+
[project.scripts]
11+
xcp-ng-dev = "xcp_ng_dev.cli:main"
12+
13+
[project.urls]
14+
Homepage = "https://github.com/xcp-ng/xcp-ng-build-env/"
15+
16+
[build-system]
17+
requires = ["setuptools >= 77.0.3", "setuptools-scm>=8"]
18+
build-backend = "setuptools.build_meta"
19+
20+
[tool.setuptools_scm]

src/xcp_ng_dev/__init__.py

Whitespace-only changes.
File renamed without changes.

0 commit comments

Comments
 (0)