1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#!/usr/bin/env bash
#
# test_buildah_build_rpm.sh
#
# Meant to run on a freshly installed VM.
# Installs the latest Git and Buildah and then
# Builds and installs Buildah's RPM in a Buildah Container.
# The baseline test is then run on this vm and then the
# newly created BUILDAH rpm is installed and the baseline
# test is rerun.
#
########
# Setup
########
IMAGE=registry.fedoraproject.org/fedora
SBOX=/tmp/sandbox
PACKAGES=/tmp/packages
mkdir -p ${SBOX}/buildah
GITROOT=${SBOX}/buildah
TESTSDIR=${GITROOT}/tests
# Change packager as appropriate for the platform
PACKAGER=dnf
${PACKAGER} install -y git
${PACKAGER} install -y buildah
########
# Clone buildah from GitHub.com
########
cd $SBOX
git clone https://github.com/containers/buildah.git
cd $GITROOT
########
# Build a container to use for building the binaries.
########
CTRID=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json $IMAGE)
ROOTMNT=$(buildah mount $CTRID)
COMMIT=$(git log --format=%H -n 1)
SHORTCOMMIT=$(echo ${COMMIT} | cut -c-7)
mkdir -p ${ROOTMNT}/rpmbuild/{SOURCES,SPECS}
########
# Build the tarball.
########
(git archive --format tar.gz --prefix=buildah-${COMMIT}/ ${COMMIT}) > ${ROOTMNT}/rpmbuild/SOURCES/buildah-${SHORTCOMMIT}.tar.gz
########
# Update the .spec file with the commit ID.
########
sed s:REPLACEWITHCOMMITID:${COMMIT}:g ${GITROOT}/contrib/rpm/buildah.spec > ${ROOTMNT}/rpmbuild/SPECS/buildah.spec
########
# Install build dependencies and build binary packages.
########
buildah run $CTRID -- dnf -y install 'dnf-command(builddep)' rpm-build
buildah run $CTRID -- dnf -y builddep --spec /rpmbuild/SPECS/buildah.spec
buildah run $CTRID -- rpmbuild --define "_topdir /rpmbuild" -ba /rpmbuild/SPECS/buildah.spec
########
# Build a second new container.
########
CTRID2=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json $IMAGE)
ROOTMNT2=$(buildah mount $CTRID2)
########
# Copy the binary packages from the first container to the second one and to
# /tmp. Also build a list of their filenames.
########
rpms=
mkdir -p ${ROOTMNT2}/${PACKAGES}
mkdir -p ${PACKAGES}
for rpm in ${ROOTMNT}/rpmbuild/RPMS/*/*.rpm ; do
cp $rpm ${ROOTMNT2}/${PACKAGES}
cp $rpm ${PACKAGES}
rpms="$rpms "${PACKAGES}/$(basename $rpm)
done
########
# Install the binary packages into the second container.
########
buildah run $CTRID2 -- dnf -y install $rpms
########
# Run the binary package and compare its self-identified version to the one we tried to build.
########
id=$(buildah run $CTRID2 -- buildah version | awk '/^Git Commit:/ { print $NF }')
bv=$(buildah run $CTRID2 -- buildah version | awk '/^Version:/ { print $NF }')
rv=$(buildah run $CTRID2 -- rpm -q --queryformat '%{version}' buildah)
echo "short commit: $SHORTCOMMIT"
echo "id: $id"
echo "buildah version: $bv"
echo "buildah rpm version: $rv"
test $SHORTCOMMIT = $id
test $bv = $rv
########
# Clean up Buildah
########
buildah rm $(buildah containers -q)
buildah rmi -f $(buildah images -q)
########
# Kick off baseline testing against the installed Buildah
########
/bin/bash -v ${TESTSDIR}/test_buildah_baseline.sh
########
# Install the Buildah we just built locally and run
# the baseline tests again.
########
${PACKAGER} -y install ${PACKAGES}/*.rpm
/bin/bash -v ${TESTSDIR}/test_buildah_baseline.sh
########
# Clean up
########
rm -rf ${SBOX}
rm -rf ${PACKAGES}
buildah rm $(buildah containers -q)
buildah rmi -f $(buildah images -q)
${PACKAGER} remove -y buildah
|