From e0e4184fa47a79e84be7257e5814c32f27ed770c Mon Sep 17 00:00:00 2001 From: Madhu Challa Date: Mon, 3 Jun 2024 10:07:56 -0700 Subject: [PATCH] Add support for ubi8 rpmbuild See rpms/README.txt Address Toms comments and fixed few more issues - copy all rpms including from base image into final - change build_opflexrpm.sh to pass branch and rpm version to build - update README.txt Signed-off-by: Madhu Challa --- docker/rpms/Dockerfile-opflexrpm-build | 51 ++++++++++ docker/rpms/Dockerfile-opflexrpm-build-base | 101 ++++++++++++++++++++ docker/rpms/README.txt | 63 ++++++++++++ docker/rpms/build_opflex_baserpm.sh | 15 +++ docker/rpms/build_opflexrpm.sh | 33 +++++++ 5 files changed, 263 insertions(+) create mode 100644 docker/rpms/Dockerfile-opflexrpm-build create mode 100644 docker/rpms/Dockerfile-opflexrpm-build-base create mode 100644 docker/rpms/README.txt create mode 100755 docker/rpms/build_opflex_baserpm.sh create mode 100755 docker/rpms/build_opflexrpm.sh diff --git a/docker/rpms/Dockerfile-opflexrpm-build b/docker/rpms/Dockerfile-opflexrpm-build new file mode 100644 index 00000000..c3bdfad8 --- /dev/null +++ b/docker/rpms/Dockerfile-opflexrpm-build @@ -0,0 +1,51 @@ +ARG baseimage=noiro/opflexrpm-build-base:latest +FROM $baseimage +ARG branch="master" +ARG buildversion="private" +RUN mkdir -p /root/opflexrpms-$buildversion \ + && rm -f /root/opflexrpms/* \ + && git clone https://github.com/noironetworks/opflex -b $branch \ + && cd opflex \ + && pushd libopflex \ + && ./autogen.sh \ + && ./configure --with-buildversion=$buildversion \ + && make srpm \ + && make rpm \ + && cp *.rpm /root/opflexrpms-$buildversion \ + && export LIBOPFLEX_INSTALLS=`ls *.x86_64.rpm` \ + && rpm -i $LIBOPFLEX_INSTALLS \ + && popd \ + && pushd genie \ + && mvn compile exec:java \ + && popd \ + && pushd genie/target/libmodelgbp \ + && bash autogen.sh \ + && ./configure --with-buildversion=$buildversion \ + libopflex_CFLAGS='none' libopflex_LIBS='none' \ + && make srpm \ + && ./configure --with-buildversion=$buildversion \ + && make rpm \ + && cp *.rpm /root/opflexrpms-$buildversion \ + && export MODELGBP_INSTALLS=`ls *.x86_64.rpm` \ + && rpm -i $MODELGBP_INSTALLS \ + && popd \ + && pushd agent-ovs \ + && ./autogen.sh \ + && ./configure --with-buildversion=$buildversion \ + libopflex_CFLAGS='none' libopflex_LIBS='none' \ + libmodelgbp_CFLAGS='none' libmodelgbp_LIBS='none' \ + libofproto_CFLAGS='none' libofproto_LIBS='none' \ + libopenvswitch_CFLAGS='none' libopenvswitch_LIBS='none' \ + && make srpm \ + && ./configure --with-buildversion=$buildversion \ + && make rpm \ + && cp *.rpm /root/opflexrpms-$buildversion \ + && popd \ + && cd /root \ + && cp ./rpmbuild-libuv/RPMS/x86_64/*.rpm ./opflexrpms-$buildversion \ + && cp ./rpmbuild-ovs/RPMS/noarch/*.rpm ./opflexrpms-$buildversion \ + && cp ./rpmbuild-ovs/RPMS/x86_64/*.rpm ./opflexrpms-$buildversion \ + && cp ./rpmbuild-prometheus/RPMS/x86_64/*.rpm ./opflexrpms-$buildversion \ + && cp ./rpmbuild-rapidjson/RPMS/x86_64/*.rpm ./opflexrpms-$buildversion \ + && tar czvf opflexrpms-$buildversion.tar.gz ./opflexrpms-$buildversion \ + && cd / diff --git a/docker/rpms/Dockerfile-opflexrpm-build-base b/docker/rpms/Dockerfile-opflexrpm-build-base new file mode 100644 index 00000000..01ded2b4 --- /dev/null +++ b/docker/rpms/Dockerfile-opflexrpm-build-base @@ -0,0 +1,101 @@ +FROM registry.access.redhat.com/ubi8/ubi-minimal:latest +ARG proxy +RUN microdnf install --enablerepo codeready-builder-for-rhel-8-x86_64-rpms \ + libtool pkgconfig autoconf automake make cmake file python3-six openssl-devel \ + git gcc gcc-c++ boost-devel diffutils python3-devel libnetfilter_conntrack-devel \ + wget which curl-devel procps zlib-devel libmnl-devel vi rpmdevtools rpmlint \ + java-11-openjdk-devel checkpolicy graphviz groff selinux-policy-devel iproute-devel \ + doxygen libuv-devel libnsl2-devel selinux-policy-targeted \ + && microdnf clean all +RUN wget https://dlcdn.apache.org/maven/maven-3/3.9.7/binaries/apache-maven-3.9.7-bin.tar.gz \ + && tar zxvf apache-maven-3.9.7-bin.tar.gz \ + && rm apache-maven-3.9.7-bin.tar.gz +RUN if [ ! -z "$proxy" ]; then \ + mkdir -p /root/.m2 \ + && echo -e "\ +\n\ +\n\ + \n\ + httpproxy\n\ + true\n\ + http\n\ + $proxy\n\ + 80\n\ + localhost\n\ + \n\ + \n\ + httpsproxy\n\ + true\n\ + https\n\ + $proxy\n\ + 80\n\ + localhost\n\ + \n\ +\n\ +\n\ +" > /root/.m2/settings.xml; \ + fi +ENV PATH=/apache-maven-3.9.7/bin:$PATH +RUN pushd /root \ + && git clone https://github.com/noironetworks/3rdparty-rpm \ + && rpmdev-setuptree \ + && git clone https://github.com/openvswitch/ovs.git -b v2.12.0 \ + && pushd ovs \ + && cp ../3rdparty-rpm/noiro-openvswitch/noiro-openvswitch.spec /root/rpmbuild/SPECS \ + && patch -p1 < ../3rdparty-rpm/noiro-openvswitch/noiro-openvswitch.patch \ + && rm -f openvswitch*.tar.gz \ + && ./boot.sh \ + && ./configure \ + && make dist \ + && cp ./openvswitch*.tar.gz /root/rpmbuild/SOURCES \ + && rpmbuild -ba --without check --define '_topdir /root/rpmbuild' /root/rpmbuild/SPECS/noiro-openvswitch.spec --without=libcapng \ + && mv /root/rpmbuild /root/rpmbuild-ovs \ + && popd \ + && mkdir -p /root/rpmbuild-ovs/RPMS/ovn/x86_64 \ + && mv /root/rpmbuild-ovs/RPMS/x86_64/*ovn* /root/rpmbuild-ovs/RPMS/ovn/x86_64 \ + && rm -Rf /root/ovs +RUN pushd /root \ + && rpmdev-setuptree \ + && git clone https://github.com/libuv/libuv.git -b v1.20.2 \ + && pushd libuv \ + && cp ../3rdparty-rpm/libuv.spec /root/rpmbuild/SPECS \ + && rm -f libuv*.tar.gz \ + && sh autogen.sh \ + && ./configure \ + && make dist \ + && cp libuv-1.20.2.tar.gz /root/rpmbuild/SOURCES/libuv-v1.20.2.tar.gz \ + && rpmbuild -ba --define '_topdir /root/rpmbuild' /root/rpmbuild/SPECS/libuv.spec \ + && mv /root/rpmbuild /root/rpmbuild-libuv \ + && popd \ + && rm -Rf /root/libuv +RUN pushd /root \ + && rpmdev-setuptree \ + && git clone https://github.com/jupp0r/prometheus-cpp.git -b v1.0.1 \ + && pushd prometheus-cpp \ + && git submodule init \ + && git submodule update \ + && git apply ../3rdparty-rpm/prometheus/prometheus-cpp.patch \ + && mkdir _build \ + && popd \ + && mv prometheus-cpp prometheus-cpp-1.0.1 \ + && tar -czvf prometheus-cpp-1.0.1.tar.gz prometheus-cpp-1.0.1 \ + && mv prometheus-cpp-1.0.1.tar.gz /root/rpmbuild/SOURCES \ + && cp /root/3rdparty-rpm/prometheus-cpp.spec /root/rpmbuild/SPECS \ + && rpmbuild -ba --define '_topdir /root/rpmbuild' /root/rpmbuild/SPECS/prometheus-cpp.spec \ + && mv /root/rpmbuild /root/rpmbuild-prometheus \ + && popd \ + && rm -Rf /root/bin /root/doc /root/man /root/share /root/prometheus-cpp-1.0.1 +RUN pushd /root \ + && rpmdev-setuptree \ + && wget https://github.com/Tencent/rapidjson/archive/v1.1.0.tar.gz \ + && mv v1.1.0.tar.gz rpmbuild/SOURCES \ + && cp /root/3rdparty-rpm/rapidjson-devel.spec /root/rpmbuild/SPECS \ + && rpmbuild -ba --define '_topdir /root/rpmbuild' /root/rpmbuild/SPECS/rapidjson-devel.spec \ + && mv /root/rpmbuild /root/rpmbuild-rapidjson \ + && rm -Rf /root/3rdparty-rpm \ + && popd +RUN export OVS_NOARCH_INSTALLS=`ls /root/rpmbuild-ovs/RPMS/noarch/*.rpm` \ + && export OVS_INSTALLS=`ls /root/rpmbuild-ovs/RPMS/x86_64/*.x86_64.rpm` \ + && export RAPIDJSON_INSTALLS=`ls /root/rpmbuild-rapidjson/RPMS/x86_64/*.x86_64.rpm` \ + && export PROMETHEUS_INSTALLS=`ls /root/rpmbuild-prometheus/RPMS/x86_64/*.x86_64.rpm` \ + && rpm -i $OVS_NOARCH_INSTALLS $OVS_INSTALLS $RAPIDJSON_INSTALLS $PROMETHEUS_INSTALLS diff --git a/docker/rpms/README.txt b/docker/rpms/README.txt new file mode 100644 index 00000000..0fa167f8 --- /dev/null +++ b/docker/rpms/README.txt @@ -0,0 +1,63 @@ +The rpm build is completely containerized and has no host dependencies +except the following repos that need to be enabled on the rhel8 host so +the container can import them. Additionally the subscription manager +on the host needs to be setup to run in container mode since the +container itself will run as a non root user. + +Host repos to be enabled +======================== + +repo id repo name +codeready-builder-for-rhel-8-x86_64-rpms Red Hat CodeReady Linux Builder for RHEL 8 x86_64 (RPMs) +epel Extra Packages for Enterprise Linux 8 - x86_64 +rhel-8-for-x86_64-appstream-rpms Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs) +rhel-8-for-x86_64-baseos-rpms Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs) + +When setup correectly the following will be seen on a yum repolist +inside a container. + +[noiro@slave-06-rhel8 ~]$ podman run -it ubi8 sh +sh-4.4# yum repolist +Updating Subscription Management repositories. +Unable to read consumer identity +subscription-manager is operating in container mode. +repo id repo name +rhel-8-for-x86_64-appstream-rpms Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs) +rhel-8-for-x86_64-baseos-rpms Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs) +ubi-8-appstream-rpms Red Hat Universal Base Image 8 (RPMs) - AppStream +ubi-8-baseos-rpms Red Hat Universal Base Image 8 (RPMs) - BaseOS +ubi-8-codeready-builder-rpms Red Hat Universal Base Image 8 (RPMs) - CodeReady Builder + +Usage +===== + +There are 2 docker files and 2 build scripts corresponding to them. + +A. Dockerfile-opflexrpm-build-base / build_opflex_baserpm.sh +invoked as ./build_opflex_baserpm.sh noiro latest proxy.esl.cisco.com + +The last argument is optional unless running on a lab vm that needs proxy in +which case it would be the name of the proxy. +This script will build noiro/opflexrpm-build-base:latest +This image need not be build unless the opflex dependencies it installs within +change. These rarely change. + +These dependencies are +1. 3rdparty-rpm +2. ovs +3. libuv (built but not used because the system provided one compiles just fine) +4. prometheus-cpp +5. rapidjson + +B. Dockerfile-opflexrpm-build / build_opflexrpm.sh +invoked as ./build_opflexrpm.sh noiro latest noiro/opflexrpm-build-base:latest master 1.1 +3rd argument is the base image that was build in step A +4th argument is optional to build a particular branch, default master +5th argument is optional to build rpms with a particular build number, default private + +This script will build noiro/opflexrpm-build:latest and additionally copy all the opflexrpm +artifacts to /root/opflexrpms.tar.gz inside the container and also copy them out of the +container into the current directly. + +The result will be opflexrpms-1.1.tar.gz that can be posted to the customer for +installing inside the openstack container diff --git a/docker/rpms/build_opflex_baserpm.sh b/docker/rpms/build_opflex_baserpm.sh new file mode 100755 index 00000000..4b0a83ce --- /dev/null +++ b/docker/rpms/build_opflex_baserpm.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# Usage ./build_opflex_baserpm.sh + +set -x + +if test "$#" -lt 2; then + echo "Usage ./build_opflex_baserpm.sh " + exit -1 +fi + +DOCKER_USER=$1 +DOCKER_TAG=$2 +PROXY=$3 + +podman build --no-cache --build-arg proxy="$PROXY" -t "$DOCKER_USER"/opflexrpm-build-base:"$DOCKER_TAG" -f ./Dockerfile-opflexrpm-build-base . diff --git a/docker/rpms/build_opflexrpm.sh b/docker/rpms/build_opflexrpm.sh new file mode 100755 index 00000000..d64f2554 --- /dev/null +++ b/docker/rpms/build_opflexrpm.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# Usage ./build_opflexrpm.sh +# branch default master +# buildversion default private +set -x + +if test "$#" -lt 3; then + echo "Usage: ./build_opflexrpm.sh " + echo "branch default master" + echo "buildversion default private" + exit -1 +fi + +DOCKER_USER=$1 +DOCKER_TAG=$2 +BASEIMAGE=$3 +BRANCH=$4 +BUILDVER=$5 + +if [ -z "$4" ]; then + BRANCH="master" +fi + +if [ -z "$5" ]; then + BUILDVER="private" +fi + +podman build --no-cache --build-arg baseimage="$BASEIMAGE" --build-arg branch="$BRANCH" \ + --build-arg buildversion="$BUILDVER" -t "$DOCKER_USER"/opflexrpm-build:"$DOCKER_TAG" \ + -f ./Dockerfile-opflexrpm-build . +cid=$(podman create "$DOCKER_USER"/opflexrpm-build:"$DOCKER_TAG") +podman cp "$cid:/root/opflexrpms-$BUILDVER.tar.gz" ./opflexrpms-"$BUILDVER".tar.gz +podman rm "$cid"