Implement smarter RPM-building artifact caching
authorDaniel Farrell <dfarrell@redhat.com>
Fri, 24 Jul 2015 16:51:21 +0000 (12:51 -0400)
committerDaniel Farrell <dfarrell@redhat.com>
Fri, 24 Jul 2015 18:50:15 +0000 (14:50 -0400)
Accept an optional cache path as a param to the RPM build and install
sctips, use those cache paths for all artifacts.

Also removed an some unnecessary software installs and fixed some docs.

Change-Id: I3f83035ca0d81caf3193923a3216856a4e620070
Signed-off-by: Daniel Farrell <dfarrell@redhat.com>
packaging/rpm/build.sh
packaging/rpm/install.sh

index f60372ad8da5b41293aff070fb2396f9107e0c73..70c1251d604c999a4b4d776e0bad5e95b27606d6 100755 (executable)
@@ -5,6 +5,17 @@
 # Echo commands as they are run
 set -x
 
+# Extract optional cache dir argument, default to `/vagrant`
+if [[ $# -eq 0 ]]; then
+  echo "Defaulting to /vagrant as cache_dir"
+  cache_dir="/vagrant"
+elif [[ $# -eq 1 ]]; then
+  cache_dir=$1
+else
+  echo "Usage: $0 [cache dir]" >&2
+  exit 1
+fi
+
 # NB: These will need to be updated for version bumps
 odl_version="0.3.0-Lithium"
 rpm_version="3.0.0"
@@ -18,8 +29,8 @@ odl_tarball="distribution-karaf-$odl_version.tar.gz"
 unitfile_tarball="opendaylight-systemd-$sysd_commit.tar.gz"
 
 # Common paths used in this script
-odl_tb_cache_path="/vagrant/$odl_tarball"
-unitfile_cache_path="/vagrant/$unitfile_tarball"
+odl_tb_cache_path="$cache_dir/$odl_tarball"
+unitfile_cache_path="$cache_dir/$unitfile_tarball"
 srpm_out_path="$HOME/rpmbuild/SRPMS/$odl_srpm"
 rpm_out_path="$HOME/rpmbuild/RPMS/noarch/$odl_rpm"
 odl_tb_url="https://nexus.opendaylight.org/content/groups/public/org/opendaylight/integration/distribution-karaf/$odl_version/$odl_tarball"
@@ -27,9 +38,11 @@ unitfile_url="https://github.com/dfarrell07/opendaylight-systemd/archive/$sysd_c
 rpmbuild_src_dir="$HOME/rpmbuild/SOURCES/"
 rpmbuild_spec_dir="$HOME/rpmbuild/SPECS/"
 
-# Install required software, add user to mock group for rpmbuild
+# Install required RPM building software and the repo that serves it
 sudo yum install -y epel-release
-sudo yum install -y @development-tools fedora-packager
+sudo yum install -y fedora-packager
+
+# Add user to mock group for rpmbuild
 sudo usermod -a -G mock $USER
 
 # Configure rpmbuild dir
@@ -46,11 +59,19 @@ fi
 # Put ODL release tarball in the location required by rpmbuild
 cp $odl_tb_cache_path $rpmbuild_src_dir
 
-# Put systemd unit file archive in rpmbuild's SOURCES dir
-# Need `-L` to follow redirects
-curl -L -o $rpmbuild_src_dir/$unitfile_tarball $unitfile_url
+# Download ODL systemd unitfile if it's not cached locally already
+if [ ! -f  $unitfile_cache_path ]; then
+    echo "No cached ODL systemd unitfile found, downloading..."
+    # Need `-L` to follow redirects
+    curl -L -o $unitfile_cache_path $unitfile_url
+else
+    echo "Using cached version of ODL systemd unitfile at $unitfile_cache_path"
+fi
+
+# Put systemd unitfile archive in rpmbuild's SOURCES dir
+cp $unitfile_cache_path $rpmbuild_src_dir
 
-# Put ODL RPM .spec file in location required by rpmbuild
+# Put ODL RPM .spec file in rpmbuild's SPECS dir
 cp opendaylight.spec $rpmbuild_spec_dir
 
 # Build ODL SRPM and noarch RPM
@@ -61,9 +82,9 @@ rpmbuild -ba opendaylight.spec
 if [ -f  $srpm_out_path ]; then
     echo "SRPM built!"
     echo "Location: $srpm_out_path"
-    if [ -d  /vagrant/ ]; then
-        echo "Assuming you want to move RPM off Vagrant box"
-        cp $srpm_out_path /vagrant/
+    if [ -d  $cache_dir ]; then
+        echo "Assuming you want to cache the SRPM"
+        cp $srpm_out_path $cache_dir
     fi
 else
     echo "SRPM seems to have failed. :(" >&2
@@ -73,9 +94,9 @@ fi
 if [ -f  $rpm_out_path ]; then
     echo "RPM built!"
     echo "Location: $rpm_out_path"
-    if [ -d  /vagrant/ ]; then
-        echo "Assuming you want to move RPM off Vagrant box"
-        cp $rpm_out_path /vagrant/
+    if [ -d  $cache_dir ]; then
+        echo "Assuming you want to cache the RPM"
+        cp $rpm_out_path $cache_dir
     fi
 else
     echo "RPM seems to have failed. :(" >&2
index 4d1c0d00c11bcaa20c4622d40cdca126257ac3dc..dac40a2bb4385e5d020085ef6ec6816a9e76bbaf 100755 (executable)
@@ -4,10 +4,22 @@
 # Echo commands as they are run
 set -x
 
+# Extract optional cache dir argument, default to `/vagrant`
+if [[ $# -eq 0 ]]; then
+  echo "Defaulting to /vagrant as cache_dir"
+  cache_dir="/vagrant"
+elif [[ $# -eq 1 ]]; then
+  cache_dir=$1
+else
+  echo "Usage: $0 [cache dir]" >&2
+  exit 1
+fi
+
 # NB: These will need to be updated for version bumps
 rpm_version="3.0.0"
 rpm_release="2.el7.centos"
-rpm_path="./opendaylight-$rpm_version-$rpm_release.noarch.rpm"
+odl_rpm="opendaylight-$rpm_version-$rpm_release.noarch.rpm"
+rpm_path="$cache_dir/$odl_rpm"
 
 # Install Java, required by ODL
 sudo yum install -y java