├── .github └── workflows │ ├── format.yaml │ └── main.yaml ├── Dockerfile-7.x ├── Dockerfile-8.x ├── LICENSE ├── README.md ├── build.sh ├── files ├── CentOS-Vault.repo.in ├── init-container.sh ├── rpmmacros ├── xcp-ng.repo.7.x.in ├── xcp-ng.repo.8.x.in └── yum.conf.xs ├── run.py ├── setup.cfg └── test └── test.sh /.github/workflows/format.yaml: -------------------------------------------------------------------------------- 1 | name: Check coding style 2 | 3 | on: [push] 4 | 5 | jobs: 6 | pycodestyle: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - name: Set up Python 11 | uses: actions/setup-python@v2 12 | - name: Install dependencies 13 | run: | 14 | python -m pip install --upgrade pip 15 | pip install pycodestyle 16 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 17 | - name: pycodestyle 18 | run: | 19 | pycodestyle 20 | pydocstyle: 21 | runs-on: ubuntu-latest 22 | steps: 23 | - uses: actions/checkout@v2 24 | - name: Set up Python 25 | uses: actions/setup-python@v2 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | pip install pydocstyle 30 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 31 | - name: pydocstyle 32 | run: | 33 | pydocstyle 34 | -------------------------------------------------------------------------------- /.github/workflows/main.yaml: -------------------------------------------------------------------------------- 1 | name: Test build env 2 | 3 | on: [push] 4 | 5 | jobs: 6 | test: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - name: Set up Python 11 | uses: actions/setup-python@v2 12 | - name: Test 13 | shell: 'script -q -e -c "bash {0}"' 14 | run: | 15 | ./test/test.sh 16 | -------------------------------------------------------------------------------- /Dockerfile-7.x: -------------------------------------------------------------------------------- 1 | FROM centos:7.2.1511 2 | 3 | ARG CUSTOM_BUILDER_UID="" 4 | ARG CUSTOM_BUILDER_GID="" 5 | 6 | # Remove all repositories 7 | RUN rm /etc/yum.repos.d/* 8 | 9 | # Add only the specific CentOS 7.2 repositories, because that's what XS used for the majority of packages 10 | COPY files/tmp-CentOS-Vault.repo /etc/yum.repos.d/CentOS-Vault-7.2.repo 11 | 12 | # Add our repositories 13 | # Repository file depends on the target version of XCP-ng, and is pre-processed by build.sh 14 | COPY files/tmp-xcp-ng.repo /etc/yum.repos.d/xcp-ng.repo 15 | 16 | # Fix invalid rpmdb checksum error with overlayfs, see https://github.com/docker/docker/issues/10180 17 | RUN yum install -y yum-plugin-ovl 18 | 19 | # Use priorities so that packages from our repositories are preferred over those from CentOS repositories 20 | RUN yum install -y yum-plugin-priorities 21 | 22 | # Update 23 | RUN yum update -y 24 | 25 | # Build requirements 26 | RUN yum install -y --exclude=gcc-xs \ 27 | gcc \ 28 | gcc-c++ \ 29 | git \ 30 | git-lfs \ 31 | make \ 32 | mercurial \ 33 | mock \ 34 | rpm-build \ 35 | rpm-python \ 36 | sudo \ 37 | yum-utils \ 38 | epel-release 39 | 40 | # Niceties 41 | RUN yum install -y \ 42 | vim \ 43 | wget \ 44 | which 45 | 46 | # OCaml in XS is slightly older than in CentOS 47 | RUN sed -i "/gpgkey/a exclude=ocaml*" /etc/yum.repos.d/Cent* /etc/yum.repos.d/epel* 48 | 49 | # Set up the builder user 50 | RUN bash -c ' \ 51 | OPTS=(); \ 52 | if [ -n "${CUSTOM_BUILDER_UID}" ]; then \ 53 | OPTS+=("-u" "${CUSTOM_BUILDER_UID}"); \ 54 | fi; \ 55 | if [ -n "${CUSTOM_BUILDER_GID}" ]; then \ 56 | OPTS+=("-g" "${CUSTOM_BUILDER_GID}"); \ 57 | if ! getent group "${CUSTOM_BUILDER_GID}" >/dev/null; then \ 58 | groupadd -g "${CUSTOM_BUILDER_GID}" builder; \ 59 | fi; \ 60 | fi; \ 61 | useradd "${OPTS[@]}" builder; \ 62 | ' \ 63 | && echo "builder:builder" | chpasswd \ 64 | && echo "builder ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers \ 65 | && usermod -G mock builder 66 | 67 | RUN mkdir -p /usr/local/bin 68 | COPY files/init-container.sh /usr/local/bin/init-container.sh 69 | COPY files/rpmmacros /home/builder/.rpmmacros 70 | -------------------------------------------------------------------------------- /Dockerfile-8.x: -------------------------------------------------------------------------------- 1 | FROM centos:7.5.1804 2 | 3 | ARG CUSTOM_BUILDER_UID="" 4 | ARG CUSTOM_BUILDER_GID="" 5 | 6 | # Remove all repositories 7 | RUN rm /etc/yum.repos.d/* 8 | 9 | # Add only the specific CentOS 7.5 repositories, because that's what XS used for the majority of packages 10 | COPY files/tmp-CentOS-Vault.repo /etc/yum.repos.d/CentOS-Vault-7.5.repo 11 | 12 | # Add our repositories 13 | # Repository file depends on the target version of XCP-ng, and is pre-processed by build.sh 14 | COPY files/tmp-xcp-ng.repo /etc/yum.repos.d/xcp-ng.repo 15 | 16 | # Install GPG key 17 | RUN curl -sSf https://xcp-ng.org/RPM-GPG-KEY-xcpng -o /etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 18 | 19 | # Fix invalid rpmdb checksum error with overlayfs, see https://github.com/docker/docker/issues/10180 20 | # (still needed?) 21 | RUN yum install -y yum-plugin-ovl 22 | 23 | # Use priorities so that packages from our repositories are preferred over those from CentOS repositories 24 | RUN yum install -y yum-plugin-priorities 25 | 26 | # Update 27 | RUN yum update -y 28 | 29 | # Common build requirements 30 | RUN yum install -y \ 31 | gcc \ 32 | gcc-c++ \ 33 | git \ 34 | make \ 35 | rpm-build \ 36 | redhat-rpm-config \ 37 | rpm-python \ 38 | sudo \ 39 | yum-utils \ 40 | epel-release \ 41 | epel-rpm-macros 42 | 43 | # Niceties 44 | RUN yum install -y \ 45 | vim \ 46 | wget \ 47 | which 48 | 49 | # OCaml in XS may be older than in CentOS 50 | RUN sed -i "/gpgkey/a exclude=ocaml*" /etc/yum.repos.d/Cent* /etc/yum.repos.d/epel* 51 | 52 | # Set up the builder user 53 | RUN bash -c ' \ 54 | OPTS=(); \ 55 | if [ -n "${CUSTOM_BUILDER_UID}" ]; then \ 56 | OPTS+=("-u" "${CUSTOM_BUILDER_UID}"); \ 57 | fi; \ 58 | if [ -n "${CUSTOM_BUILDER_GID}" ]; then \ 59 | OPTS+=("-g" "${CUSTOM_BUILDER_GID}"); \ 60 | if ! getent group "${CUSTOM_BUILDER_GID}" >/dev/null; then \ 61 | groupadd -g "${CUSTOM_BUILDER_GID}" builder; \ 62 | fi; \ 63 | fi; \ 64 | useradd "${OPTS[@]}" builder; \ 65 | ' \ 66 | && echo "builder:builder" | chpasswd \ 67 | && echo "builder ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers 68 | 69 | RUN mkdir -p /usr/local/bin 70 | COPY files/init-container.sh /usr/local/bin/init-container.sh 71 | COPY files/rpmmacros /home/builder/.rpmmacros 72 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2015 Citrix Systems 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xcp-ng-build-env 2 | 3 | This container config and collection of supporting scripts allows for 4 | creating a container to work on and build a XCP-ng package from an 5 | SRPM or from a directory containing a `SOURCES/` and a `SPECS/` 6 | directory along with appropriate RPM spec file and software sources. 7 | 8 | It will build a container with the right build environment (including some 9 | useful tools). 10 | Depending on the parameters, it will either do everything automatically to build a 11 | given package, or just install build-dependencies and let you work manually from a shell 12 | in the container context. Or even just start the container and let you do anything you 13 | want. 14 | 15 | ## Configuration 16 | 17 | You'll need to install docker or podman. Podman should be available 18 | from your distro repositories, for Docker follow the instructions for 19 | your platform on https://www.docker.com/ 20 | 21 | If you have both installed, docker will be used by default. If you 22 | want to use a specific container runtime, set `XCPNG_OCI_RUNNER` to 23 | the docker-compatible command to use (typically `podman` or `docker`). 24 | 25 | ## Building the container image(s) 26 | 27 | You need one container image per target version of XCP-ng. 28 | 29 | Clone this repository (outside any container), then use `build.sh` to 30 | generate the images for the wanted releases of XCP-ng. 31 | Note that Docker and Podman store container images separately. 32 | 33 | ``` 34 | Usage: ./build.sh {version_of_XCP_ng} 35 | ... where {version_of_XCP_ng} is a 'x.y' version such as 8.0. 36 | ``` 37 | 38 | ## Using the container 39 | 40 | Use the `run.py` script. It accepts a variety of parameters allowing for different uses: 41 | * rebuild an existing source RPM (with automated installation of the build dependencies) 42 | * 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. 43 | * or simply start a shell in the build environment, with the appropriate CentOS, EPEL and XCP-ng yum repositories enabled. 44 | 45 | ```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 | ... 51 | 52 | positional arguments: 53 | command Command to run inside the prepared container 54 | 55 | optional arguments: 56 | -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 61 | Install dependencies for the spec file(s) found in the 62 | SPECS/ subdirectory of the directory passed as 63 | parameter, then build the RPM(s). Built RPMs and SRPMs 64 | will be in RPMS/ and SRPMS/ subdirectories. Any 65 | preexisting BUILD, BUILDROOT, RPMS or SRPMS 66 | directories will be removed first. If --output-dir is 67 | set, the RPMS and SRPMS directories will be copied to 68 | it after the build. 69 | --define DEFINE Definitions to be passed to rpmbuild (if --build-local 70 | or --rebuild-srpm are passed too). Example: --define 71 | 'xcp_ng_section extras', for building the 'extras' 72 | version of a package which exists in both 'base' and 73 | 'extras' versions. 74 | -r REBUILD_SRPM, --rebuild-srpm REBUILD_SRPM 75 | Install dependencies for the SRPM passed as parameter, 76 | then build it. Requires the --output-dir parameter to 77 | be set. 78 | -o OUTPUT_DIR, --output-dir OUTPUT_DIR 79 | Output directory for --rebuild-srpm and --build-local. 80 | -n, --no-exit After executing either an automated build or a custom 81 | command passed as parameter, drop user into a shell 82 | -p PACKAGE, --package PACKAGE 83 | 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 86 | /external/ 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 90 | --rm Destroy the container on exit 91 | --syslog Enable syslog to host by mounting in /dev/log 92 | --name NAME Assign a name to the container 93 | -a ENABLEREPO, --enablerepo ENABLEREPO 94 | additional repositories to enable before installing 95 | 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. 98 | --fail-on-error If container initialisation fails, exit rather than 99 | dropping the user into a command shell 100 | ``` 101 | 102 | **Examples** 103 | 104 | Rebuild an existing source RPM (with automated installation of the build dependencies) 105 | ```sh 106 | ./run.py -b 8.0 --rebuild-srpm /path/to/some-source-rpm.src.rpm --output-dir /path/to/output/directory --rm 107 | ``` 108 | 109 | Build from git (and put the result into RPMS/ and SRPMS/ subdirectories) 110 | ```sh 111 | # Find the relevant repository at https://github.com/xcp-ng-rpms/ 112 | # Make sure you have git-lfs installed before cloning. 113 | # Then... (Example taken: xapi) 114 | git clone https://github.com/xcp-ng-rpms/xapi.git 115 | 116 | # ... Here add your patches ... 117 | 118 | # Build. 119 | /path/to/run.py -b 8.0 --build-local xapi/ --rm 120 | ``` 121 | 122 | **Important switches** 123 | 124 | * `-b` / `--branch` allows to select which version of XCP-ng to work on (defaults to the latest known version if not specified). 125 | * `--no-exit` drops you to a shell after the build, instead of closing the container. Useful if the build fails and you need to debug. 126 | * `--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` 127 | * `-v` / `--volume` (see *Mounting repos from outside the container* below) 128 | 129 | 130 | ## Building packages manually 131 | 132 | If you need to build packages manually, here are some useful commands 133 | 134 | Install the dependencies of the package using yum: 135 | 136 | ```sh 137 | yum-builddep xapi 138 | ``` 139 | 140 | then either download the SRPM using yumdownloader and rebuild it: 141 | 142 | ```sh 143 | yumdownloader --source xapi 144 | rpmbuild --rebuild xapi* 145 | ``` 146 | 147 | or build from upstream sources, without producing RPMs: 148 | 149 | ```sh 150 | git clone git://github.com/xapi-project/xen-api 151 | cd xen-api 152 | ./configure 153 | make 154 | ``` 155 | 156 | ## Mounting external directories into the container 157 | 158 | If you'd like to develop using the tools on your host and preserve the changes 159 | 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 161 | a directory from your host to a suitable point inside the container. For 162 | example, if I clone some repos into a directory on my host, say `/work/code/`, 163 | then I can mount it inside the container as follows: 164 | 165 | ```sh 166 | ./run.py -b 8.0 -v /work/code:/mnt/repos 167 | ``` 168 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | if [ -z "$1" ]; then 6 | echo "Usage: $0 {version}" 7 | echo "... where {version} is a 'x.y' version such as 8.0." 8 | exit 9 | fi 10 | 11 | RUNNER="" 12 | if [ -n "$XCPNG_OCI_RUNNER" ]; then 13 | RUNNER="$XCPNG_OCI_RUNNER" 14 | else 15 | SUPPORTED_RUNNERS="docker podman" 16 | for COMMAND in $SUPPORTED_RUNNERS; do 17 | if command -v $COMMAND >/dev/null; then 18 | RUNNER="$COMMAND" 19 | break 20 | fi 21 | done 22 | if [ -z "$RUNNER" ]; then 23 | echo >&2 "cannot find a supported runner: $SUPPORTED_RUNNERS" 24 | exit 1 25 | fi 26 | fi 27 | 28 | cd $(dirname "$0") 29 | 30 | CUSTOM_ARGS=() 31 | 32 | case "$1" in 33 | 7.*) 34 | REPO_FILE=files/xcp-ng.repo.7.x.in 35 | DOCKERFILE=Dockerfile-7.x 36 | CENTOS_VERSION=7.2.1511 37 | ;; 38 | 8.*) 39 | REPO_FILE=files/xcp-ng.repo.8.x.in 40 | DOCKERFILE=Dockerfile-8.x 41 | CENTOS_VERSION=7.5.1804 42 | ;; 43 | *) 44 | echo >&2 "Unsupported release '$1'" 45 | exit 1 46 | ;; 47 | esac 48 | 49 | sed -e "s/@XCP_NG_BRANCH@/${1}/g" "$REPO_FILE" > files/tmp-xcp-ng.repo 50 | sed -e "s/@CENTOS_VERSION@/${CENTOS_VERSION}/g" files/CentOS-Vault.repo.in > files/tmp-CentOS-Vault.repo 51 | 52 | # Support using docker on other archs (e.g. arm64 for Apple Silicon), building for amd64 53 | if [ "$(uname -m)" != "x86_64" ]; then 54 | CUSTOM_ARGS+=( "--platform" "linux/amd64" ) 55 | fi 56 | 57 | CUSTOM_UID="$(id -u)" 58 | CUSTOM_GID="$(id -g)" 59 | 60 | if [ "${CUSTOM_UID}" -eq 0 ] || [ "${CUSTOM_GID}" -eq 0 ]; then 61 | if [ -z "${SUDO_GID}" ] || [ -z "${SUDO_UID}" ] || [ -z "${SUDO_USER}" ] || \ 62 | [ -z "${SUDO_COMMAND}" ] || [ "${SUDO_GID}" -eq 0 ] || [ "${SUDO_UID}" -eq 0 ]; then 63 | echo -e "[ERROR] This operation cannot be performed by the 'root' user directly:" 64 | echo -e "\tplease use an unprivileged user (eventually with 'sudo')" 65 | exit 1 66 | fi 67 | CUSTOM_UID="${SUDO_UID}" 68 | CUSTOM_GID="${SUDO_GID}" 69 | fi 70 | 71 | # Support for seamless use of current host user 72 | # and Docker user "builder" inside the image 73 | CUSTOM_ARGS+=( "--build-arg" "CUSTOM_BUILDER_UID=${CUSTOM_UID}" ) 74 | CUSTOM_ARGS+=( "--build-arg" "CUSTOM_BUILDER_GID=${CUSTOM_GID}" ) 75 | 76 | "$RUNNER" build \ 77 | "${CUSTOM_ARGS[@]}" \ 78 | -t xcp-ng/xcp-ng-build-env:${1} \ 79 | --ulimit nofile=1024 \ 80 | -f $DOCKERFILE . 81 | 82 | rm -f files/tmp-xcp-ng.repo 83 | rm -f files/tmp-CentOS-Vault.repo 84 | -------------------------------------------------------------------------------- /files/CentOS-Vault.repo.in: -------------------------------------------------------------------------------- 1 | [C@CENTOS_VERSION@-base] 2 | name=CentOS-@CENTOS_VERSION@ - Base 3 | baseurl=http://vault.centos.org/@CENTOS_VERSION@/os/$basearch/ 4 | gpgcheck=1 5 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 6 | exclude=ocaml* 7 | enabled=1 8 | 9 | [C@CENTOS_VERSION@-updates] 10 | name=CentOS-@CENTOS_VERSION@ - Updates 11 | baseurl=http://vault.centos.org/@CENTOS_VERSION@/updates/$basearch/ 12 | gpgcheck=1 13 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 14 | exclude=ocaml* 15 | enabled=1 16 | 17 | [C@CENTOS_VERSION@-extras] 18 | name=CentOS-@CENTOS_VERSION@ - Extras 19 | baseurl=http://vault.centos.org/@CENTOS_VERSION@/extras/$basearch/ 20 | gpgcheck=1 21 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 22 | exclude=ocaml* 23 | enabled=1 24 | 25 | [C@CENTOS_VERSION@-base-source] 26 | name=CentOS-@CENTOS_VERSION@ - Base 27 | baseurl=http://vault.centos.org/@CENTOS_VERSION@/os/Source/ 28 | gpgcheck=1 29 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 30 | exclude=ocaml* 31 | enabled=0 32 | 33 | [C@CENTOS_VERSION@-updates-source] 34 | name=CentOS-@CENTOS_VERSION@ - Updates 35 | baseurl=http://vault.centos.org/@CENTOS_VERSION@/updates/Source/ 36 | gpgcheck=1 37 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 38 | exclude=ocaml* 39 | enabled=0 40 | 41 | [C@CENTOS_VERSION@-extras-source] 42 | name=CentOS-@CENTOS_VERSION@ - Extras 43 | baseurl=http://vault.centos.org/@CENTOS_VERSION@/extras/Source/ 44 | gpgcheck=1 45 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 46 | exclude=ocaml* 47 | enabled=0 48 | -------------------------------------------------------------------------------- /files/init-container.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -n "$FAIL_ON_ERROR" ]; then 4 | set -e 5 | fi 6 | 7 | # clean yum cache to avoid download errors 8 | sudo yum clean all 9 | 10 | # get list of user repos 11 | ( 12 | source /etc/os-release 13 | case "$VERSION_ID" in 14 | 8.2.*) XCPREL=8/8.2 ;; 15 | 8.3.*) XCPREL=8/8.3 ;; 16 | *) echo >&2 "WARNING: unknown release, not fetching user repo definitions" ;; 17 | esac 18 | 19 | curl -s https://koji.xcp-ng.org/repos/user/${XCPREL}/xcpng-users.repo | 20 | sed '/^gpgkey=/ ipriority=1' | sudo tee /etc/yum.repos.d/xcp-ng-users.repo > /dev/null 21 | ) 22 | 23 | # disable repositories if needed 24 | if [ -n "$DISABLEREPO" ]; then 25 | sudo yum-config-manager --disable "$DISABLEREPO" 26 | fi 27 | 28 | # enable additional repositories if needed 29 | if [ -n "$ENABLEREPO" ]; then 30 | sudo yum-config-manager --enable "$ENABLEREPO" 31 | fi 32 | 33 | # update to either install newer updates or to take packages from added repos into account 34 | sudo yum update -y --disablerepo=epel 35 | 36 | cd "$HOME" 37 | 38 | SRPM_MOUNT_DIR=/mnt/docker-SRPMS/ 39 | LOCAL_SRPM_DIR=$HOME/local-SRPMs 40 | 41 | mkdir -p "$LOCAL_SRPM_DIR" 42 | 43 | # Download the source for packages specified in the environment. 44 | if [ -n "$PACKAGES" ] 45 | then 46 | for PACKAGE in $PACKAGES 47 | do 48 | yumdownloader --destdir="$LOCAL_SRPM_DIR" --source $PACKAGE 49 | done 50 | fi 51 | 52 | # Copy in any SRPMs from the directory mounted by the host. 53 | if [ -d $SRPM_MOUNT_DIR ] 54 | then 55 | cp $SRPM_MOUNT_DIR/*.src.rpm "$LOCAL_SRPM_DIR" 56 | fi 57 | 58 | # Install deps for all the SRPMs. 59 | SRPMS=$(find "$LOCAL_SRPM_DIR" -name "*.src.rpm") 60 | 61 | for SRPM in $SRPMS 62 | do 63 | sudo yum-builddep -y "$SRPM" 64 | done 65 | 66 | # double the default stack size 67 | ulimit -s 16384 68 | 69 | if [ -n "$BUILD_LOCAL" ]; then 70 | pushd ~/rpmbuild 71 | rm BUILD BUILDROOT RPMS SRPMS -rf 72 | sudo yum-builddep -y SPECS/*.spec 73 | # in case the build deps contain xs-opam-repo, source the added profile.d file 74 | [ ! -f /etc/profile.d/opam.sh ] || source /etc/profile.d/opam.sh 75 | if [ $? == 0 ]; then 76 | if [ -n "$RPMBUILD_DEFINE" ]; then 77 | rpmbuild -ba SPECS/*.spec --define "$RPMBUILD_DEFINE" 78 | else 79 | rpmbuild -ba SPECS/*.spec 80 | fi 81 | if [ $? == 0 -a -d ~/output/ ]; then 82 | cp -rf RPMS SRPMS ~/output/ 83 | fi 84 | fi 85 | popd 86 | elif [ -n "$REBUILD_SRPM" ]; then 87 | # build deps already installed above 88 | # in case the build deps contain xs-opam-repo, source the added profile.d file 89 | [ ! -f /etc/profile.d/opam.sh ] || source /etc/profile.d/opam.sh 90 | if [ -n "$RPMBUILD_DEFINE" ]; then 91 | rpmbuild --rebuild "$LOCAL_SRPM_DIR/$REBUILD_SRPM"--define "$RPMBUILD_DEFINE" 92 | else 93 | rpmbuild --rebuild "$LOCAL_SRPM_DIR/$REBUILD_SRPM" 94 | fi 95 | if [ $? == 0 ]; then 96 | cp -rf ~/rpmbuild/RPMS ~/output/ 97 | fi 98 | elif [ -n "$COMMAND" ]; then 99 | $COMMAND 100 | else 101 | /bin/bash --login 102 | exit 0 103 | fi 104 | 105 | if [ -n "$NO_EXIT" ]; then 106 | /bin/bash --login 107 | fi 108 | -------------------------------------------------------------------------------- /files/rpmmacros: -------------------------------------------------------------------------------- 1 | # The changes below regarding opamroot are only needed for older XCP-ng releases 2 | # Starting with more recent XCP-ng releases (8.1? 8.2?), xs-opam-repo includes a profile.d 3 | # file that one has to source, which we do when we start the container. 4 | # And by the way opamroot has moved to /usr/lib64 5 | 6 | # taken from /usr/lib/rpm/macros 7 | %__spec_build_pre %{___build_pre}\ 8 | [ ! -d /usr/lib/opamroot ] || eval $(opam config env --root=/usr/lib/opamroot) 9 | 10 | # taken from /usr/lib/rpm/redhat/macros 11 | %__spec_install_pre %{___build_pre}\ 12 | [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf "${RPM_BUILD_ROOT}"\ 13 | mkdir -p `dirname "$RPM_BUILD_ROOT"`\ 14 | mkdir "$RPM_BUILD_ROOT"\ 15 | [ ! -d /usr/lib/opamroot ] || eval $(opam config env --root=/usr/lib/opamroot) 16 | 17 | -------------------------------------------------------------------------------- /files/xcp-ng.repo.7.x.in: -------------------------------------------------------------------------------- 1 | [xcp-ng-builddeps] 2 | name=XCP-ng Builddeps Repository 3 | baseurl=https://updates.xcp-ng.org/7/@XCP_NG_BRANCH@/builddeps/x86_64/ 4 | enabled=1 5 | gpgcheck=0 6 | priority=1 7 | 8 | [xcp-ng-base] 9 | name=XCP-ng Base Repository 10 | baseurl=https://updates.xcp-ng.org/7/@XCP_NG_BRANCH@/base/x86_64/ 11 | enabled=1 12 | gpgcheck=0 13 | priority=1 14 | exclude=xcp-ng-release 15 | 16 | [xcp-ng-updates] 17 | name=XCP-ng Updates Repository 18 | baseurl=https://updates.xcp-ng.org/7/@XCP_NG_BRANCH@/updates/x86_64/ 19 | enabled=1 20 | gpgcheck=0 21 | priority=1 22 | exclude=xcp-ng-release 23 | 24 | [xcp-ng-updates_testing] 25 | name=XCP-ng Updates Testing Repository 26 | baseurl=https://updates.xcp-ng.org/7/@XCP_NG_BRANCH@/updates_testing/x86_64/ 27 | enabled=0 28 | gpgcheck=0 29 | priority=1 30 | exclude=xcp-ng-release 31 | 32 | [xcp-ng-extras] 33 | name=XCP-ng Extras Repository 34 | baseurl=https://updates.xcp-ng.org/7/@XCP_NG_BRANCH@/extras/x86_64/ 35 | enabled=0 36 | gpgcheck=0 37 | priority=1 38 | 39 | [xcp-ng-extras_testing] 40 | name=XCP-ng Extras Testing Repository 41 | baseurl=https://updates.xcp-ng.org/7/@XCP_NG_BRANCH@/extras_testing/x86_64/ 42 | enabled=0 43 | gpgcheck=0 44 | priority=1 45 | 46 | # Source repositories 47 | 48 | [xcp-ng-builddeps-src] 49 | name=XCP-ng Builddeps Source Repository 50 | baseurl=https://updates.xcp-ng.org/7/@XCP_NG_BRANCH@/builddeps/Source/ 51 | enabled=1 52 | gpgcheck=0 53 | priority=1 54 | 55 | [xcp-ng-base-src] 56 | name=XCP-ng Base Source Repository 57 | baseurl=https://updates.xcp-ng.org/7/@XCP_NG_BRANCH@/base/Source/ 58 | enabled=1 59 | gpgcheck=0 60 | priority=1 61 | 62 | [xcp-ng-updates-src] 63 | name=XCP-ng Updates Source Repository 64 | baseurl=https://updates.xcp-ng.org/7/@XCP_NG_BRANCH@/updates/Source/ 65 | enabled=1 66 | gpgcheck=0 67 | priority=1 68 | 69 | [xcp-ng-updates_testing-src] 70 | name=XCP-ng Updates Testing Repository 71 | baseurl=https://updates.xcp-ng.org/7/@XCP_NG_BRANCH@/updates_testing/Source/ 72 | enabled=0 73 | gpgcheck=0 74 | priority=1 75 | 76 | [xcp-ng-extras-src] 77 | name=XCP-ng Extras Source Repository 78 | baseurl=https://updates.xcp-ng.org/7/@XCP_NG_BRANCH@/extras/Source/ 79 | enabled=0 80 | gpgcheck=0 81 | priority=1 82 | 83 | [xcp-ng-extras_testing-src] 84 | name=XCP-ng Extras Testing Source Repository 85 | baseurl=https://updates.xcp-ng.org/7/@XCP_NG_BRANCH@/extras_testing/Source/ 86 | enabled=0 87 | gpgcheck=0 88 | priority=1 89 | -------------------------------------------------------------------------------- /files/xcp-ng.repo.8.x.in: -------------------------------------------------------------------------------- 1 | [xcp-ng-base] 2 | name=XCP-ng Base Repository 3 | baseurl=http://mirrors.xcp-ng.org/8/@XCP_NG_BRANCH@/base/x86_64/ 4 | enabled=1 5 | gpgcheck=1 6 | repo_gpgcheck=1 7 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 8 | priority=1 9 | 10 | [xcp-ng-updates] 11 | name=XCP-ng Updates Repository 12 | baseurl=http://mirrors.xcp-ng.org/8/@XCP_NG_BRANCH@/updates/x86_64/ 13 | enabled=1 14 | gpgcheck=1 15 | repo_gpgcheck=1 16 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 17 | priority=1 18 | 19 | [xcp-ng-candidates] 20 | name=XCP-ng Candidates Repository 21 | baseurl=http://mirrors.xcp-ng.org/8/@XCP_NG_BRANCH@/candidates/x86_64/ 22 | enabled=1 23 | gpgcheck=1 24 | repo_gpgcheck=1 25 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 26 | priority=1 27 | 28 | [xcp-ng-testing] 29 | name=XCP-ng Testing Repository 30 | baseurl=http://mirrors.xcp-ng.org/8/@XCP_NG_BRANCH@/testing/x86_64/ 31 | enabled=1 32 | gpgcheck=1 33 | repo_gpgcheck=1 34 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 35 | priority=1 36 | 37 | [xcp-ng-ci] 38 | name=XCP-ng CI Repository 39 | baseurl=http://mirrors.xcp-ng.org/8/@XCP_NG_BRANCH@/ci/x86_64/ 40 | enabled=1 41 | gpgcheck=1 42 | repo_gpgcheck=1 43 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 44 | priority=1 45 | 46 | [xcp-ng-incoming] 47 | name=XCP-ng Incoming Repository 48 | baseurl=http://mirrors.xcp-ng.org/8/@XCP_NG_BRANCH@/incoming/x86_64/ 49 | enabled=0 50 | gpgcheck=1 51 | repo_gpgcheck=1 52 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 53 | priority=1 54 | 55 | 56 | [xcp-ng-lab] 57 | name=XCP-ng Lab Source Repository 58 | baseurl=http://mirrors.xcp-ng.org/8/@XCP_NG_BRANCH@/lab/x86_64/ 59 | enabled=0 60 | gpgcheck=1 61 | repo_gpgcheck=1 62 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 63 | priority=1 64 | 65 | [xcp-ng-linstor] 66 | name=XCP-ng LINSTOR Repository 67 | baseurl=https://repo.vates.tech/xcp-ng/8/@XCP_NG_BRANCH@/linstor/x86_64/ 68 | enabled=0 69 | gpgcheck=1 70 | repo_gpgcheck=1 71 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 72 | priority=1 73 | 74 | [xcp-ng-linstor-testing] 75 | name=XCP-ng LINSTOR Testing Repository 76 | baseurl=https://repo.vates.tech/xcp-ng/8/@XCP_NG_BRANCH@/linstor-testing/x86_64/ 77 | enabled=0 78 | gpgcheck=1 79 | repo_gpgcheck=1 80 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 81 | priority=1 82 | 83 | # Source repositories 84 | 85 | [xcp-ng-base-src] 86 | name=XCP-ng Base Source Repository 87 | baseurl=http://mirrors.xcp-ng.org/8/@XCP_NG_BRANCH@/base/Source/ 88 | enabled=1 89 | gpgcheck=1 90 | repo_gpgcheck=1 91 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 92 | priority=1 93 | 94 | [xcp-ng-updates-src] 95 | name=XCP-ng Updates Source Repository 96 | baseurl=http://mirrors.xcp-ng.org/8/@XCP_NG_BRANCH@/updates/Source/ 97 | enabled=1 98 | gpgcheck=1 99 | repo_gpgcheck=1 100 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 101 | priority=1 102 | 103 | [xcp-ng-candidates-src] 104 | name=XCP-ng Candidates Source Repository 105 | baseurl=http://mirrors.xcp-ng.org/8/@XCP_NG_BRANCH@/candidates/Source/ 106 | enabled=1 107 | gpgcheck=1 108 | repo_gpgcheck=1 109 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 110 | priority=1 111 | 112 | [xcp-ng-testing-src] 113 | name=XCP-ng Testing Source Repository 114 | baseurl=http://mirrors.xcp-ng.org/8/@XCP_NG_BRANCH@/testing/Source/ 115 | enabled=1 116 | gpgcheck=1 117 | repo_gpgcheck=1 118 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 119 | priority=1 120 | 121 | [xcp-ng-ci-src] 122 | name=XCP-ng CI Source Repository 123 | baseurl=http://mirrors.xcp-ng.org/8/@XCP_NG_BRANCH@/ci/Source/ 124 | enabled=1 125 | gpgcheck=1 126 | repo_gpgcheck=1 127 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 128 | priority=1 129 | 130 | [xcp-ng-incoming-src] 131 | name=XCP-ng Incoming Source Repository 132 | baseurl=http://mirrors.xcp-ng.org/8/@XCP_NG_BRANCH@/incoming/Source/ 133 | enabled=0 134 | gpgcheck=1 135 | repo_gpgcheck=1 136 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 137 | priority=1 138 | 139 | [xcp-ng-lab-src] 140 | name=XCP-ng Lab Source Repository 141 | baseurl=http://mirrors.xcp-ng.org/8/@XCP_NG_BRANCH@/lab/Source/ 142 | enabled=0 143 | gpgcheck=1 144 | repo_gpgcheck=1 145 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 146 | priority=1 147 | 148 | [xcp-ng-linstor-src] 149 | name=XCP-ng LINSTOR Repository 150 | baseurl=https://repo.vates.tech/xcp-ng/8/@XCP_NG_BRANCH@/linstor/Source/ 151 | enabled=0 152 | gpgcheck=1 153 | repo_gpgcheck=1 154 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 155 | priority=1 156 | 157 | [xcp-ng-linstor-testing-src] 158 | name=XCP-ng LINSTOR Testing Repository 159 | baseurl=https://repo.vates.tech/xcp-ng/8/@XCP_NG_BRANCH@/linstor-testing/Source/ 160 | enabled=0 161 | gpgcheck=1 162 | repo_gpgcheck=1 163 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-xcpng 164 | priority=1 165 | -------------------------------------------------------------------------------- /files/yum.conf.xs: -------------------------------------------------------------------------------- 1 | [main] 2 | cachedir=/tmp/yum 3 | keepcache=0 4 | debuglevel=2 5 | logfile=/var/log/yum.log 6 | exactarch=1 7 | obsoletes=1 8 | gpgcheck=0 9 | plugins=1 10 | installonly_limit=3 11 | reposdir=/etc/yum.repos.d.xs 12 | 13 | # This is the default, if you make this bigger yum won't see if the metadata 14 | # is newer on the remote and so you'll "gain" the bandwidth of not having to 15 | # download the new metadata and "pay" for it by yum not having correct 16 | # information. 17 | # It is esp. important, to have correct metadata, for distributions like 18 | # Fedora which don't keep old packages around. If you don't like this checking 19 | # interupting your command line usage, it's much better to have something 20 | # manually check the metadata once an hour (yum-updatesd will do this). 21 | # metadata_expire=90m 22 | 23 | # PUT YOUR REPOS HERE OR IN separate files named file.repo 24 | # in /etc/yum.repos.d 25 | 26 | [epel] 27 | name = epel 28 | enabled = 1 29 | baseurl = https://repo.citrite.net/ctx-remote-yum-fedora/epel/7/x86_64/ 30 | exclude = ocaml* 31 | gpgcheck = 0 32 | 33 | [base] 34 | name = base 35 | enabled = 1 36 | baseurl = https://repo.citrite.net/centos/7.2.1511/os/x86_64/ 37 | exclude = ocaml* 38 | gpgcheck = 0 39 | 40 | [updates] 41 | name = updates 42 | enabled = 1 43 | baseurl = https://repo.citrite.net/centos/7.2.1511/os/x86_64/ 44 | exclude = ocaml* 45 | gpgcheck = 0 46 | 47 | [extras] 48 | name = extras 49 | enabled = 1 50 | baseurl = https://repo.citrite.net/centos/7.2.1511/os/x86_64/ 51 | exclude = ocaml* 52 | gpgcheck = 0 53 | 54 | -------------------------------------------------------------------------------- /run.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | Thin wrapper around "docker run" or "podman run". 6 | 7 | Simplifies the creation of a build environment for XCP-ng packages. 8 | """ 9 | 10 | import argparse 11 | import os 12 | import subprocess 13 | import shutil 14 | import sys 15 | import uuid 16 | 17 | CONTAINER_PREFIX = "xcp-ng/xcp-ng-build-env" 18 | SRPMS_MOUNT_ROOT = "/tmp/docker-SRPMS" 19 | 20 | DEFAULT_BRANCH = '8.3' 21 | DEFAULT_ULIMIT_NOFILE = 1024 22 | 23 | RUNNER = os.getenv("XCPNG_OCI_RUNNER") 24 | if RUNNER is None: 25 | SUPPORTED_RUNNERS = "docker podman" 26 | for command in SUPPORTED_RUNNERS.split(): 27 | if shutil.which(command): 28 | RUNNER = command 29 | break 30 | else: 31 | raise Exception(f"cannot find a supported runner: {SUPPORTED_RUNNERS}") 32 | 33 | def make_mount_dir(): 34 | """ Make a randomly-named directory under SRPMS_MOUNT_ROOT. """ 35 | srpm_mount_dir = os.path.join(SRPMS_MOUNT_ROOT, str(uuid.uuid4())) 36 | try: 37 | os.makedirs(srpm_mount_dir) 38 | except OSError: 39 | pass 40 | return srpm_mount_dir 41 | 42 | 43 | def copy_srpms(srpm_mount_dir, srpms): 44 | """ Copy each SRPM into the mount directory. """ 45 | for srpm in srpms: 46 | srpm_name = os.path.basename(srpm) 47 | shutil.copyfile(srpm, os.path.join(srpm_mount_dir, srpm_name)) 48 | 49 | def is_podman(runner): 50 | if os.path.basename(runner) == "podman": 51 | return True 52 | if subprocess.getoutput(f"{runner} --version").startswith("podman "): 53 | return True 54 | return False 55 | 56 | def main(): 57 | """ Main entry point. """ 58 | parser = argparse.ArgumentParser() 59 | parser.add_argument('-b', '--branch', 60 | help='XCP-ng version: 7.6, %s, etc. If not set, ' 61 | 'will default to %s.' % (DEFAULT_BRANCH, DEFAULT_BRANCH)) 62 | parser.add_argument('-l', '--build-local', 63 | help="Install dependencies for the spec file(s) found in the SPECS/ subdirectory " 64 | "of the directory passed as parameter, then build the RPM(s). " 65 | "Built RPMs and SRPMs will be in RPMS/ and SRPMS/ subdirectories. " 66 | "Any preexisting BUILD, BUILDROOT, RPMS or SRPMS directories will be removed first. " 67 | "If --output-dir is set, the RPMS and SRPMS directories will be copied to it " 68 | "after the build.") 69 | parser.add_argument('--define', 70 | help="Definitions to be passed to rpmbuild (if --build-local or --rebuild-srpm are " 71 | "passed too). Example: --define 'xcp_ng_section extras', for building the 'extras' " 72 | "version of a package which exists in both 'base' and 'extras' versions.") 73 | parser.add_argument('-r', '--rebuild-srpm', 74 | help="Install dependencies for the SRPM passed as parameter, then build it. " 75 | "Requires the --output-dir parameter to be set.") 76 | parser.add_argument('-o', '--output-dir', 77 | help="Output directory for --rebuild-srpm and --build-local.") 78 | parser.add_argument('-n', '--no-exit', action='store_true', 79 | help='After executing either an automated build or a custom command passed as parameter, ' 80 | 'drop user into a shell') 81 | parser.add_argument('-p', '--package', action='append', 82 | help='Packages for which dependencies will ' 83 | 'be installed') 84 | parser.add_argument('-s', '--srpm', action='append', 85 | help='SRPMs for which dependencies will be installed') 86 | parser.add_argument('-d', '--dir', action='append', 87 | help='Local dir to mount in the ' 88 | 'image. Will be mounted at /external/') 89 | parser.add_argument('-e', '--env', action='append', 90 | help='Environment variables passed directly to ' 91 | 'docker -e') 92 | parser.add_argument('-v', '--volume', action='append', 93 | help='Volume mounts passed directly to docker -v') 94 | parser.add_argument('--rm', action='store_true', 95 | help='Destroy the container on exit') 96 | parser.add_argument('--syslog', action='store_true', 97 | help='Enable syslog to host by mounting in /dev/log') 98 | parser.add_argument('--name', help='Assign a name to the container') 99 | parser.add_argument('--ulimit', action='append', 100 | help='Ulimit options passed directly to docker run') 101 | parser.add_argument('-a', '--enablerepo', 102 | help='additional repositories to enable before installing build dependencies. ' 103 | 'Same syntax as yum\'s --enablerepo parameter. Available additional repositories: ' 104 | 'check files/xcp-ng.repo.*.x.in.') 105 | parser.add_argument('--disablerepo', 106 | help='disable repositories. Same syntax as yum\'s --disablerepo parameter. ' 107 | 'If both --enablerepo and --disablerepo are set, --disablerepo will be applied first') 108 | parser.add_argument('--fail-on-error', action='store_true', 109 | help='If container initialisation fails, exit rather than dropping the user ' 110 | 'into a command shell') 111 | parser.add_argument('command', nargs=argparse.REMAINDER, 112 | help='Command to run inside the prepared container') 113 | 114 | args = parser.parse_args(sys.argv[1:]) 115 | 116 | docker_args = [RUNNER, "run", "-i", "-t", "-u", "builder"] 117 | if is_podman(RUNNER): 118 | docker_args += ["--userns=keep-id"] 119 | if os.uname()[4] != "x86_64": 120 | docker_args += ["--platform", "linux/amd64"] 121 | if args.rm: 122 | docker_args += ["--rm=true"] 123 | branch = args.branch or DEFAULT_BRANCH 124 | 125 | if args.command != []: 126 | docker_args += ["-e", "COMMAND=%s" % ' '.join(args.command)] 127 | if args.build_local: 128 | docker_args += ["-v", "%s:/home/builder/rpmbuild" % 129 | os.path.abspath(args.build_local)] 130 | docker_args += ["-e", "BUILD_LOCAL=1"] 131 | if args.define: 132 | docker_args += ["-e", "RPMBUILD_DEFINE=%s" % args.define] 133 | if args.rebuild_srpm: 134 | if not os.path.isfile(args.rebuild_srpm) or not args.rebuild_srpm.endswith(".src.rpm"): 135 | parser.error("%s is not a valid source RPM." % args.rebuild_srpm) 136 | if not args.output_dir: 137 | parser.error( 138 | "Missing --output-dir parameter, required by --rebuild-srpm.") 139 | docker_args += ["-e", "REBUILD_SRPM=%s" % 140 | os.path.basename(args.rebuild_srpm)] 141 | if args.srpm is None: 142 | args.srpm = [] 143 | args.srpm.append(args.rebuild_srpm) 144 | if args.output_dir: 145 | if not os.path.isdir(args.output_dir): 146 | parser.error("%s is not a valid output directory." % 147 | args.output_dir) 148 | docker_args += ["-v", "%s:/home/builder/output" % 149 | os.path.abspath(args.output_dir)] 150 | if args.no_exit: 151 | docker_args += ["-e", "NO_EXIT=1"] 152 | if args.fail_on_error: 153 | docker_args += ["-e", "FAIL_ON_ERROR=1"] 154 | # Add package names to the environment 155 | if args.package: 156 | packages = ' '.join(args.package) 157 | docker_args += ['-e', "PACKAGES=%s" % packages] 158 | # Copy all the RPMs to the mount directory 159 | srpm_mount_dir = None 160 | if args.srpm: 161 | srpm_mount_dir = make_mount_dir() 162 | copy_srpms(srpm_mount_dir, args.srpm) 163 | docker_args += ["-v", "%s:/mnt/docker-SRPMS" % srpm_mount_dir] 164 | if args.syslog: 165 | docker_args += ["-v", "/dev/log:/dev/log"] 166 | if args.name: 167 | docker_args += ["--name", args.name] 168 | if args.dir: 169 | for localdir in args.dir: 170 | if not os.path.isdir(localdir): 171 | print("Local directory argument is not a directory!") 172 | sys.exit(1) 173 | ext_path = os.path.abspath(localdir) 174 | int_path = os.path.basename(ext_path) 175 | docker_args += ["-v", "%s:/external/%s" % (ext_path, int_path)] 176 | if args.volume: 177 | for volume in args.volume: 178 | docker_args += ["-v", volume] 179 | if args.env: 180 | for env in args.env: 181 | docker_args += ["-e", env] 182 | if args.enablerepo: 183 | docker_args += ["-e", "ENABLEREPO=%s" % args.enablerepo] 184 | if args.disablerepo: 185 | docker_args += ["-e", "DISABLEREPO=%s" % args.disablerepo] 186 | ulimit_nofile = False 187 | if args.ulimit: 188 | for ulimit in args.ulimit: 189 | if ulimit.startswith('nofile='): 190 | ulimit_nofile = True 191 | docker_args += ["--ulimit", ulimit] 192 | if not ulimit_nofile: 193 | docker_args += ["--ulimit", "nofile=%s" % DEFAULT_ULIMIT_NOFILE] 194 | 195 | # exec "docker run" 196 | docker_args += ["%s:%s" % (CONTAINER_PREFIX, branch), 197 | "/usr/local/bin/init-container.sh"] 198 | print("Launching docker with args %s" % docker_args, file=sys.stderr) 199 | return_code = subprocess.call(docker_args) 200 | 201 | if srpm_mount_dir: 202 | print("Cleaning up temporary mount directory") 203 | shutil.rmtree(srpm_mount_dir) 204 | 205 | sys.exit(return_code) 206 | 207 | 208 | if __name__ == "__main__": 209 | main() 210 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [pycodestyle] 2 | max-line-length=120 3 | ignore=E261,E302,E305,E402,W503 4 | 5 | [pydocstyle] 6 | ignore=D100,D101,D102,D103,D104,D105,D106,D107,D203,D210,D212,D401,D403 7 | 8 | -------------------------------------------------------------------------------- /test/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eux 4 | 5 | TARGET_XCP_NG_VERSION="8.2" 6 | 7 | ./build.sh "$TARGET_XCP_NG_VERSION" 8 | 9 | REPOS=xcp-emu-manager 10 | 11 | CONTAINER_NAME=${CONTAINER_NAME:-build-env} 12 | 13 | for REPO in ${REPOS}; do 14 | REPO_PATH=/tmp/"$REPO" 15 | git clone --branch "$TARGET_XCP_NG_VERSION" https://github.com/xcp-ng-rpms/"$REPO" "$REPO_PATH" 16 | 17 | ./run.py --name "$CONTAINER_NAME" \ 18 | --fail-on-error \ 19 | -l "$REPO_PATH" \ 20 | -b "$TARGET_XCP_NG_VERSION" \ 21 | --rm 22 | 23 | rm -rf "$REPO_PATH" 24 | done 25 | --------------------------------------------------------------------------------