Skip to content

Support for a v9 build-env #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Jul 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e987f73
run.py: raise the ulimit nofile value
ydirson Jun 27, 2025
ec70301
build.sh: handle more relevant versions first
ydirson Jun 26, 2025
e8cfd2f
init-container: fix "run.py --define=... --rebuild-srpm=..."
ydirson Jun 27, 2025
3f7be42
Make --platform flag systematic
ydirson Jun 26, 2025
f8a1aed
Move yum clean all from init-container to Dockerfile
ydirson Jul 8, 2025
6c35da2
run.py: drop unused --package flag
ydirson Jul 9, 2025
2dd739b
run.py: drop unused --srpm and --rebuild-srpm flags
ydirson Jul 9, 2025
a894ec4
init-container: avoid copypasta
ydirson Jul 9, 2025
a1ca31d
run the build under `time` control
ydirson Jul 8, 2025
4fbcf1b
Set ghcr.io registry for the container
ydirson Jul 30, 2025
c47e597
Move repo logic in the dockerfiles
glehmann Jul 21, 2025
1b0abb5
Initial support for XCP-ng 9 build-env
ydirson Jul 9, 2025
0614c18
init-container: make OS_RELEASE available for setting other vars
ydirson Jun 26, 2025
0191b85
Build 9.0 for x86_64_v2
ydirson Jun 26, 2025
4d1d601
run.py: allow selection of container platform
ydirson Jun 26, 2025
cb3c932
build.sh: add support for options
ydirson Jun 26, 2025
9ce2a76
build.sh: allow selection of container platform
ydirson Jun 26, 2025
1b72667
run.py: add --rpmbuild-opts to help use "rpmbuild --without xxx" etc
ydirson Jun 27, 2025
524c4dd
run.py --local-build: detect spec file paths
ydirson Jul 9, 2025
d623a26
run.py --local-build: teach fetching source tarballs from the Almalin…
ydirson Jul 9, 2025
f82d2f9
run.sh: --rpmbuild-stage to override "-ba"
ydirson Jul 10, 2025
cf41223
run.py: new --debug flag
ydirson Jul 10, 2025
ec22871
README: provide an example to refresh patches
ydirson Jul 10, 2025
fee2790
Adjust /etc/shadow permissions to unbreak sudo un some setups
ydirson Jul 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions Dockerfile-7.x
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM centos:7.2.1511
ARG CENTOS_VERSION=7.2.1511

FROM centos:${CENTOS_VERSION}

ARG CUSTOM_BUILDER_UID=""
ARG CUSTOM_BUILDER_GID=""
Expand All @@ -7,11 +9,15 @@ ARG CUSTOM_BUILDER_GID=""
RUN rm /etc/yum.repos.d/*

# Add only the specific CentOS 7.2 repositories, because that's what XS used for the majority of packages
COPY files/tmp-CentOS-Vault.repo /etc/yum.repos.d/CentOS-Vault-7.2.repo
ARG CENTOS_VERSION
COPY files/CentOS-Vault.repo.in /etc/yum.repos.d/CentOS-Vault-7.2.repo
RUN sed -e "s/@CENTOS_VERSION@/${CENTOS_VERSION}/g" -i /etc/yum.repos.d/CentOS-Vault-7.2.repo

# Add our repositories
# Repository file depends on the target version of XCP-ng, and is pre-processed by build.sh
COPY files/tmp-xcp-ng.repo /etc/yum.repos.d/xcp-ng.repo
ARG XCP_NG_BRANCH=7.6
COPY files/xcp-ng.repo.7.x.in /etc/yum.repos.d/xcp-ng.repo
RUN sed -e "s/@XCP_NG_BRANCH@/${XCP_NG_BRANCH}/g" -i /etc/yum.repos.d/xcp-ng.repo

# Fix invalid rpmdb checksum error with overlayfs, see https://github.com/docker/docker/issues/10180
RUN yum install -y yum-plugin-ovl
Expand Down Expand Up @@ -43,6 +49,9 @@ RUN yum install -y \
wget \
which

# clean package cache to avoid download errors
RUN yum clean all

# OCaml in XS is slightly older than in CentOS
RUN sed -i "/gpgkey/a exclude=ocaml*" /etc/yum.repos.d/Cent* /etc/yum.repos.d/epel*

Expand Down
15 changes: 12 additions & 3 deletions Dockerfile-8.x
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM centos:7.5.1804
ARG CENTOS_VERSION=7.5.1804

FROM centos:${CENTOS_VERSION}

ARG CUSTOM_BUILDER_UID=""
ARG CUSTOM_BUILDER_GID=""
Expand All @@ -7,11 +9,15 @@ ARG CUSTOM_BUILDER_GID=""
RUN rm /etc/yum.repos.d/*

# Add only the specific CentOS 7.5 repositories, because that's what XS used for the majority of packages
COPY files/tmp-CentOS-Vault.repo /etc/yum.repos.d/CentOS-Vault-7.5.repo
ARG CENTOS_VERSION
COPY files/CentOS-Vault.repo.in /etc/yum.repos.d/CentOS-Vault-7.5.repo
RUN sed -e "s/@CENTOS_VERSION@/${CENTOS_VERSION}/g" -i /etc/yum.repos.d/CentOS-Vault-7.5.repo

# Add our repositories
# Repository file depends on the target version of XCP-ng, and is pre-processed by build.sh
COPY files/tmp-xcp-ng.repo /etc/yum.repos.d/xcp-ng.repo
ARG XCP_NG_BRANCH=8.3
COPY files/xcp-ng.repo.8.x.in /etc/yum.repos.d/xcp-ng.repo
RUN sed -e "s/@XCP_NG_BRANCH@/${XCP_NG_BRANCH}/g" -i /etc/yum.repos.d/xcp-ng.repo

# Install GPG key
RUN curl -sSf https://xcp-ng.org/RPM-GPG-KEY-xcpng -o /etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng
Expand Down Expand Up @@ -46,6 +52,9 @@ RUN yum install -y \
wget \
which

# clean package cache to avoid download errors
RUN yum clean all

# OCaml in XS may be older than in CentOS
RUN sed -i "/gpgkey/a exclude=ocaml*" /etc/yum.repos.d/Cent* /etc/yum.repos.d/epel*

Expand Down
79 changes: 79 additions & 0 deletions Dockerfile-9.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
FROM ghcr.io/almalinux/10-base:10.0

ARG CUSTOM_BUILDER_UID=""
ARG CUSTOM_BUILDER_GID=""

# Add our repositories
# temporary bootstrap repository
COPY files/xcp-ng-8.99.repo /etc/yum.repos.d/xcp-ng.repo
# Almalinux 10 devel
COPY files/Alma10-devel.repo /etc/yum.repos.d/

# Install GPG key
RUN curl -sSf https://xcp-ng.org/RPM-GPG-KEY-xcpng -o /etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng

# Update
RUN dnf update -y

# Common build requirements
RUN dnf install -y \
gcc \
gcc-c++ \
git \
make \
rpm-build \
redhat-rpm-config \
python3-rpm \
sudo \
dnf-plugins-core \
epel-release

# EPEL: needs epel-release installed first
RUN dnf install -y \
epel-rpm-macros \
almalinux-git-utils

# Niceties
RUN dnf install -y \
bash-completion \
vim \
wget \
which

# clean package cache to avoid download errors
RUN yum clean all

# -release*, to be commented out to boostrap the build-env until it gets built
# FIXME: isn't it already pulled as almalinux-release when available?
RUN dnf install -y \
xcp-ng-release \
xcp-ng-release-presets

# enable repositories commonly required to build
RUN dnf config-manager --enable crb

# workaround sudo not working (e.g. in podman 4.9.3 in Ubuntu 24.04)
RUN chmod 0400 /etc/shadow

# Set up the builder user
RUN bash -c ' \
OPTS=(); \
if [ -n "${CUSTOM_BUILDER_UID}" ]; then \
OPTS+=("-u" "${CUSTOM_BUILDER_UID}"); \
fi; \
if [ -n "${CUSTOM_BUILDER_GID}" ]; then \
OPTS+=("-g" "${CUSTOM_BUILDER_GID}"); \
if ! getent group "${CUSTOM_BUILDER_GID}" >/dev/null; then \
groupadd -g "${CUSTOM_BUILDER_GID}" builder; \
fi; \
fi; \
useradd "${OPTS[@]}" builder; \
' \
&& echo "builder:builder" | chpasswd \
&& echo "builder ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers

RUN mkdir -p /usr/local/bin
COPY files/init-container.sh /usr/local/bin/init-container.sh

# FIXME: check it we really need any of this
# COPY files/rpmmacros /home/builder/.rpmmacros
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,29 @@ git clone https://github.com/xcp-ng-rpms/xapi.git
* `--rm` destroys the container on exit. Helps preventing containers from using too much space on disk. You can still reclaim space afterwards by running `docker container prune` and `docker image prune`
* `-v` / `--volume` (see *Mounting repos from outside the container* below)

**Refreshing fuzzy patches**

In XCP-ng 9.0, `rpmbuild` rejects fuzzy patches. The easiest-known
way to get them refreshed is to let `quilt` do the job, but that's not
fully automated.

1. modify the specfile to add `-Squilt` to `%autosetup` or
`%autopatch` in the `%prep` block; add `BuildRequires: quilt`
2. let quilt apply them in a 8.3 buildenv (`quilt` in 8.3 is only in EPEL) and get you a shell:
```
xcpng/build-env/run.py --rm -b 8.3 -l . --rpmbuild-stage=p -n --enablerepo=epel
```
3. ask `quilt` to refresh all your patches (alternatively just the one you want)
```
$ cd rpmbuild/BUILD/$dir
$ quilt pop -a --refresh
$ cp patches/* ../../SOURCES/
```
4. carefully pick up the bits you need

Note: unfortunately `rpmbuild` (in 8.3 at least) does not add all
patches in `patches/series` upfront, so in case of real conflict this
has to be redone from step 2 each time.

## Building packages manually

Expand Down
82 changes: 58 additions & 24 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
#!/usr/bin/env bash

set -e

if [ -z "$1" ]; then
echo "Usage: $0 {version}"
echo "... where {version} is a 'x.y' version such as 8.0."
exit
fi
die() {
echo >&2
echo >&2 "ERROR: $*"
echo >&2
exit 1
}

die_usage() {
usage >&2
die "$*"
}

usage() {
cat <<EOF
Usage: $0 [--platform PF] <version>
... where <version> is a 'x.y' version such as 8.0.

--platform override the default platform for the build container.
EOF
}

PLATFORM=
while [ $# -ge 1 ]; do
case "$1" in
--help|-h)
usage
exit 0
;;
--platform)
[ $# -ge 2 ] || die_usage "$1 needs an argument"
PLATFORM="$2"
shift
;;
-*)
die_usage "unknown flag '$1'"
;;
*)
break
;;
esac
shift
done

[ -n "$1" ] || die_usage "version parameter missing"

RUNNER=""
if [ -n "$XCPNG_OCI_RUNNER" ]; then
Expand All @@ -29,31 +67,28 @@ cd $(dirname "$0")

CUSTOM_ARGS=()

ALMA_VERSION=
CENTOS_VERSION=
case "$1" in
7.*)
REPO_FILE=files/xcp-ng.repo.7.x.in
DOCKERFILE=Dockerfile-7.x
CENTOS_VERSION=7.2.1511
9.*)
DOCKERFILE=Dockerfile-9.x
ALMA_VERSION=10.0
: ${PLATFORM:=linux/amd64/v2}
;;
8.*)
REPO_FILE=files/xcp-ng.repo.8.x.in
DOCKERFILE=Dockerfile-8.x
CENTOS_VERSION=7.5.1804
: ${PLATFORM:=linux/amd64}
;;
7.*)
DOCKERFILE=Dockerfile-7.x
: ${PLATFORM:=linux/amd64}
;;
*)
echo >&2 "Unsupported release '$1'"
exit 1
;;
esac

sed -e "s/@XCP_NG_BRANCH@/${1}/g" "$REPO_FILE" > files/tmp-xcp-ng.repo
sed -e "s/@CENTOS_VERSION@/${CENTOS_VERSION}/g" files/CentOS-Vault.repo.in > files/tmp-CentOS-Vault.repo

# Support using docker on other archs (e.g. arm64 for Apple Silicon), building for amd64
if [ "$(uname -m)" != "x86_64" ]; then
CUSTOM_ARGS+=( "--platform" "linux/amd64" )
fi

CUSTOM_UID="$(id -u)"
CUSTOM_GID="$(id -g)"

Expand All @@ -74,10 +109,9 @@ CUSTOM_ARGS+=( "--build-arg" "CUSTOM_BUILDER_UID=${CUSTOM_UID}" )
CUSTOM_ARGS+=( "--build-arg" "CUSTOM_BUILDER_GID=${CUSTOM_GID}" )

"$RUNNER" build \
--platform "$PLATFORM" \
"${CUSTOM_ARGS[@]}" \
-t xcp-ng/xcp-ng-build-env:${1} \
-t ghcr.io/xcp-ng/xcp-ng-build-env:${1} \
--build-arg XCP_NG_BRANCH=${1} \
--ulimit nofile=1024 \
-f $DOCKERFILE .

rm -f files/tmp-xcp-ng.repo
rm -f files/tmp-CentOS-Vault.repo
5 changes: 5 additions & 0 deletions files/Alma10-devel.repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[alma10-devel]
name=Almalinux 10 devel
baseurl=https://repo.almalinux.org/almalinux/10/devel/$basearch/os/
enabled=1
gpgcheck=1
Loading