Pin pip to 20.3.3 and disable tmpfs in DIB
[ta/build-tools.git] / build_images.sh
index 9d94f59..281b166 100755 (executable)
 # limitations under the License.
 
 set -x
-set -eu
+set -e
+set -o pipefail
 
 usage() {
-    echo "Usage: $0 -m <manifest-path> -w <work-dir-path>"
+    echo "Usage: $0 -m <manifest-dir> -w <work-dir> [-r <rpmbuilder-dir> -p <rpm-create-search-dir>]"
     exit 1
 }
 
-[ "$#" -ne 4 ] && usage
-while getopts "m:w:" OPT; do
+rpm_search_paths=""
+while getopts "m:w:p:r:" OPT; do
     case $OPT in
     m)
         export MANIFEST_PATH=$(readlink -f $OPTARG)
@@ -30,20 +31,46 @@ while getopts "m:w:" OPT; do
     w)
         export WORK=$OPTARG
         ;;
+    r)
+        export RPMBUILDER_PATH=$(readlink -f $OPTARG)
+        ;;
+    p)
+        rpm_search_paths+=" $OPTARG"
+        ;;
     *)
         usage
         ;;
     esac
 done
 
+[ -z "$MANIFEST_PATH" ] && usage
+[ -z "$WORK" ] && usage
+[ -n "$rpm_search_paths" -a -z "$RPMBUILDER_PATH" ] && usage
+shift "$((OPTIND-1))"
+[ "$#" -ne 0 ] && usage
+
 scriptdir="$(dirname $(readlink -f ${BASH_SOURCE[0]}))"
 source $scriptdir/lib.sh
 
 _initialize_work_dirs
 
+dib_file="${scriptdir}/docker-context/Dockerfile-dib"
+dib_patch="${dib_file}.$(uname -m).patch"
+if [ -e "${dib_patch}" ] && ! patch -R --dry-run "${dib_file}" "${dib_patch}"; then
+    patch "${dib_file}" "${dib_patch}"
+fi
+
+docker build --network=host -f $scriptdir/docker-context/Dockerfile-dib -t dib $scriptdir/docker-context
+docker build --network=host -f $scriptdir/docker-context/Dockerfile-buildtools -t buildtools $scriptdir/docker-context
+
 # Create manifest RPM
 $LIBDIR/create_manifest_rpm.sh
 
+# Create RPMs
+if [ -n "$rpm_search_paths" ]; then
+    $LIBDIR/build_rpms.sh $rpm_search_paths
+fi
+
 # Create repo config
 $LIBDIR/build_step_create_yum_repo_files.sh