File scripts/worker.php changed (mode: 100644) (index 429c2b9..fa71818) |
... |
... |
function start_worker_build_tools($job, &$reason, &$reason2) |
416 |
416 |
. ' echo "M${@}" > /dev/virtio-ports/rgw' . "\n" |
. ' echo "M${@}" > /dev/virtio-ports/rgw' . "\n" |
417 |
417 |
. '}' . "\n" |
. '}' . "\n" |
418 |
418 |
. "\n" |
. "\n" |
|
419 |
|
. 'function rg_notify_err()' . "\n" |
|
420 |
|
. '{' . "\n" |
|
421 |
|
. ' echo "E${@}" > /dev/virtio-ports/rgw' . "\n" |
|
422 |
|
. '}' . "\n" |
|
423 |
|
. "\n" |
419 |
424 |
. 'rg_log_prefix=""' . "\n" |
. 'rg_log_prefix=""' . "\n" |
420 |
425 |
. 'function xecho()' . "\n" |
. 'function xecho()' . "\n" |
421 |
426 |
. '{' . "\n" |
. '{' . "\n" |
|
... |
... |
function start_worker_build_tools($job, &$reason, &$reason2) |
558 |
563 |
. ' local dir=${1}; shift' . "\n" |
. ' local dir=${1}; shift' . "\n" |
559 |
564 |
. "\n" |
. "\n" |
560 |
565 |
. ' xecho "rg_extract_rpm_info: dir=${dir} [`date`]"' . "\n" |
. ' xecho "rg_extract_rpm_info: dir=${dir} [`date`]"' . "\n" |
561 |
|
. ' spec_file=`find "${dir}" -type f -iname \'*.spec\' | head -n1`' . "\n" |
|
|
566 |
|
. ' spec_file=`find "${dir}" -iname \'*.spec\' -type f -printf "%d %p\n" | sort -n | head -n1 | awk \'{print $2}\'`' . "\n" |
562 |
567 |
. ' if [ "${spec_file}" = "" ]; then' . "\n" |
. ' if [ "${spec_file}" = "" ]; then' . "\n" |
563 |
568 |
. ' xecho " Cannot find any .spec file in ${dir}!"' . "\n" |
. ' xecho " Cannot find any .spec file in ${dir}!"' . "\n" |
564 |
569 |
. ' ls -l "${dir}"' . "\n" |
. ' ls -l "${dir}"' . "\n" |
|
... |
... |
function start_worker_build_repo($job, $conf, &$reason, &$reason2) |
906 |
911 |
. ' fi' . "\n" |
. ' fi' . "\n" |
907 |
912 |
. ' done' . "\n" |
. ' done' . "\n" |
908 |
913 |
. ' ;;' . "\n" |
. ' ;;' . "\n" |
909 |
|
. ' *) xecho "Unknown distro!"; E=1 ;;' . "\n" |
|
|
914 |
|
. ' *) xecho "Unsupported distro!"; E=1 ;;' . "\n" |
910 |
915 |
. ' esac' . "\n" |
. ' esac' . "\n" |
911 |
916 |
. ' rg_log_pop' . "\n" |
. ' rg_log_pop' . "\n" |
912 |
917 |
. ' [ "${E}" = "0" ] || break' . "\n\n"; |
. ' [ "${E}" = "0" ] || break' . "\n\n"; |
|
... |
... |
function start_worker_build_repo($job, $conf, &$reason, &$reason2) |
936 |
941 |
. ' rg_log_pop' . "\n" |
. ' rg_log_pop' . "\n" |
937 |
942 |
. ' done' . "\n" |
. ' done' . "\n" |
938 |
943 |
. ' ;;' . "\n" |
. ' ;;' . "\n" |
939 |
|
. ' *) xecho "Unknown distro!"; E=1 ;;' . "\n" |
|
|
944 |
|
. ' *) xecho "Unsupported distro!"; E=1 ;;' . "\n" |
940 |
945 |
. ' esac' . "\n" |
. ' esac' . "\n" |
941 |
946 |
. ' rg_log_pop' . "\n" |
. ' rg_log_pop' . "\n" |
942 |
947 |
. ' [ "${E}" = "0" ] || break' . "\n\n"; |
. ' [ "${E}" = "0" ] || break' . "\n\n"; |
943 |
948 |
|
|
944 |
|
// TODO: we have a race for 'rg_op cat a > b': writing to b may fail => break is executed, but E is not set! |
|
945 |
949 |
foreach ($job['pkg_maps'] as $junk => $info) { |
foreach ($job['pkg_maps'] as $junk => $info) { |
946 |
950 |
$pkg_subrepo_id = $info['pkg_subrepo_id']; |
$pkg_subrepo_id = $info['pkg_subrepo_id']; |
947 |
951 |
$si = $job['pkg_subrepos'][$pkg_subrepo_id]; |
$si = $job['pkg_subrepos'][$pkg_subrepo_id]; |
|
... |
... |
function start_worker_build_repo($job, $conf, &$reason, &$reason2) |
951 |
955 |
. ' export pkg_repo_id=' . $pkg_repo_id . "\n" |
. ' export pkg_repo_id=' . $pkg_repo_id . "\n" |
952 |
956 |
. ' export pkg_repo_uid=' . $ri['uid'] . "\n" |
. ' export pkg_repo_uid=' . $ri['uid'] . "\n" |
953 |
957 |
. ' export pkg_subrepo_id=' . $pkg_subrepo_id . "\n" |
. ' export pkg_subrepo_id=' . $pkg_subrepo_id . "\n" |
954 |
|
. "\n" |
|
|
958 |
|
. "\n" |
955 |
959 |
. ' echo' . "\n" |
. ' echo' . "\n" |
956 |
960 |
. ' rg_log_push "== rgfs phase pkg_repo_id=${pkg_repo_id} pkg_subrepo_id=${pkg_subrepo_id} ====="' . "\n" |
. ' rg_log_push "== rgfs phase pkg_repo_id=${pkg_repo_id} pkg_subrepo_id=${pkg_subrepo_id} ====="' . "\n" |
957 |
961 |
. ' xecho "Mounting rgfs pkg_repo_id/pkg_subrepo_id=${pkg_repo_id}/${pkg_subrepo_id}"' . "\n" |
. ' xecho "Mounting rgfs pkg_repo_id/pkg_subrepo_id=${pkg_repo_id}/${pkg_subrepo_id}"' . "\n" |
|
... |
... |
function start_worker_build_repo($job, $conf, &$reason, &$reason2) |
966 |
970 |
. ' rg_op_s /usr/bin/rgfs -s -o kernel_cache -o auto_cache \\' . "\n" |
. ' rg_op_s /usr/bin/rgfs -s -o kernel_cache -o auto_cache \\' . "\n" |
967 |
971 |
. ' -o noforget -o use_ino "${dir}" || break' . "\n" |
. ' -o noforget -o use_ino "${dir}" || break' . "\n" |
968 |
972 |
. ' rgfs_mounted[${pkg_repo_id}-${pkg_subrepo_id}]=1' . "\n" |
. ' rgfs_mounted[${pkg_repo_id}-${pkg_subrepo_id}]=1' . "\n" |
969 |
|
. "\n" |
|
|
973 |
|
. "\n" |
970 |
974 |
. ' rgfs_subrepo_root="/mnt/build2/rgfs/${pkg_repo_id}/${pkg_subrepo_id}"' . "\n" |
. ' rgfs_subrepo_root="/mnt/build2/rgfs/${pkg_repo_id}/${pkg_subrepo_id}"' . "\n" |
971 |
975 |
. ' xecho "DEBUG: env_distro=${env_distro}"' . "\n" |
. ' xecho "DEBUG: env_distro=${env_distro}"' . "\n" |
972 |
976 |
. ' case "${env_distro}" in' . "\n" |
. ' case "${env_distro}" in' . "\n" |
|
... |
... |
function start_worker_build_repo($job, $conf, &$reason, &$reason2) |
975 |
979 |
. ' rgfs="${rgfs_subrepo_root}/${env_distro}/${env_major}/${env_arch}/${i}"' . "\n" |
. ' rgfs="${rgfs_subrepo_root}/${env_distro}/${env_major}/${env_arch}/${i}"' . "\n" |
976 |
980 |
. ' rpms_dir="/mnt/build2/rpms/${pkg_repo_id}/${i}"' . "\n" |
. ' rpms_dir="/mnt/build2/rpms/${pkg_repo_id}/${i}"' . "\n" |
977 |
981 |
. ' pkg_list_file="${rpms_dir}/pkg.list"' . "\n" |
. ' pkg_list_file="${rpms_dir}/pkg.list"' . "\n" |
978 |
|
. ' pkg_common_list_file="${rpms_dir}/pkg.common.list"' . "\n" |
|
979 |
982 |
. ' pkg_filter_list_file="${rpms_dir}/pkg.filter.list"' . "\n" |
. ' pkg_filter_list_file="${rpms_dir}/pkg.filter.list"' . "\n" |
980 |
983 |
. ' pkg_pend_list_file="/mnt/tmp/pkg.list"' . "\n" |
. ' pkg_pend_list_file="/mnt/tmp/pkg.list"' . "\n" |
981 |
|
. ' > "${pkg_common_list_file}"' . "\n" |
|
982 |
984 |
. ' > "${pkg_pend_list_file}"' . "\n" |
. ' > "${pkg_pend_list_file}"' . "\n" |
983 |
|
. "\n" |
|
|
985 |
|
. "\n" |
984 |
986 |
. ' rg_log_push "== ${i} ====="' . "\n" |
. ' rg_log_push "== ${i} ====="' . "\n" |
985 |
987 |
. ' mkdir -p "${rpms_dir}" # when we do not build packages, we may not have this dir' . "\n" |
. ' mkdir -p "${rpms_dir}" # when we do not build packages, we may not have this dir' . "\n" |
986 |
|
. "\n" |
|
987 |
|
. ' rg_cp "${pkg_list_file}" "${pkg_common_list_file}" || break' . "\n" |
|
|
988 |
|
. "\n" |
988 |
989 |
. ' if [ "${job_uid}" = "0" ]; then' . "\n" |
. ' if [ "${job_uid}" = "0" ]; then' . "\n" |
989 |
990 |
. ' if [ -d "${rgfs}/+pending" ]; then' . "\n" |
. ' if [ -d "${rgfs}/+pending" ]; then' . "\n" |
990 |
991 |
. ' xecho "DEBUG: dir +pending found"' . "\n" |
. ' xecho "DEBUG: dir +pending found"' . "\n" |
991 |
992 |
. ' rg_create_list "${rgfs}/+pending" "${pkg_pend_list_file}" || break' . "\n" |
. ' rg_create_list "${rgfs}/+pending" "${pkg_pend_list_file}" || break' . "\n" |
992 |
|
. ' rg_op cat "${pkg_pend_list_file}" >> "${pkg_common_list_file}"' . "\n" |
|
993 |
993 |
. ' else' . "\n" |
. ' else' . "\n" |
994 |
994 |
. ' xecho "DEBUG: dir +pending does not exists."' . "\n" |
. ' xecho "DEBUG: dir +pending does not exists."' . "\n" |
995 |
995 |
. ' fi' . "\n" |
. ' fi' . "\n" |
996 |
996 |
. ' fi' . "\n" |
. ' fi' . "\n" |
997 |
|
. ' xecho "DEBUG pkg_common_list_file: ["`cat "${pkg_common_list_file}"`"]"' . "\n" |
|
998 |
|
. "\n" |
|
999 |
|
. ' if [ ! -s "${pkg_common_list_file}" ]; then' . "\n" |
|
1000 |
|
. ' xecho "pkg_common_list_files is empty"' . "\n" |
|
|
997 |
|
. "\n" |
|
998 |
|
. ' if [ ! -s "${pkg_list_file}" ] && [ ! -s "${pkg_pend_list_file}" ]; then' . "\n" |
|
999 |
|
. ' xecho "pkg_list_file/pkg_pend_list_file are both empty; continue"' . "\n" |
1001 |
1000 |
. ' rg_log_pop' . "\n" |
. ' rg_log_pop' . "\n" |
1002 |
1001 |
. ' continue' . "\n" |
. ' continue' . "\n" |
1003 |
1002 |
. ' fi' . "\n" |
. ' fi' . "\n" |
1004 |
|
. "\n" |
|
|
1003 |
|
. "\n" |
1005 |
1004 |
. ' rg_log_push "Filtering existing packages from pkg_list_file"' . "\n" |
. ' rg_log_push "Filtering existing packages from pkg_list_file"' . "\n" |
1006 |
1005 |
. ' > "${pkg_filter_list_file}"' . "\n" |
. ' > "${pkg_filter_list_file}"' . "\n" |
1007 |
1006 |
. ' while read file; do' . "\n" |
. ' while read file; do' . "\n" |
|
1007 |
|
. ' [ "${file}" = "" ] && continue' . "\n" |
1008 |
1008 |
. ' if [ -r "${rgfs}/${file}" ]; then' . "\n" |
. ' if [ -r "${rgfs}/${file}" ]; then' . "\n" |
1009 |
1009 |
. ' xecho "- ${rgfs}/${file}"' . "\n" |
. ' xecho "- ${rgfs}/${file}"' . "\n" |
1010 |
1010 |
. ' continue' . "\n" |
. ' continue' . "\n" |
1011 |
1011 |
. ' fi' . "\n" |
. ' fi' . "\n" |
1012 |
1012 |
. ' xecho "+ ${rgfs}/${file}"' . "\n" |
. ' xecho "+ ${rgfs}/${file}"' . "\n" |
1013 |
1013 |
. ' echo "${file}" >> ${pkg_filter_list_file}' . "\n" |
. ' echo "${file}" >> ${pkg_filter_list_file}' . "\n" |
1014 |
|
. ' done < "${pkg_common_list_file}"' . "\n" |
|
|
1014 |
|
. ' done < <(cat "${pkg_list_file}"; echo; cat "${pkg_pend_list_file}"; echo' . "\n" |
1015 |
1015 |
. ' rg_log_pop' . "\n" |
. ' rg_log_pop' . "\n" |
1016 |
|
. "\n" |
|
|
1016 |
|
. "\n" |
1017 |
1017 |
. ' if [ "${job_uid}" = "0" ]; then' . "\n" |
. ' if [ "${job_uid}" = "0" ]; then' . "\n" |
1018 |
1018 |
. ' if [ -d "${rgfs}/+pending" ]; then' . "\n" |
. ' if [ -d "${rgfs}/+pending" ]; then' . "\n" |
1019 |
1019 |
. ' xecho "+pending dir exists"' . "\n" |
. ' xecho "+pending dir exists"' . "\n" |
|
... |
... |
function start_worker_build_repo($job, $conf, &$reason, &$reason2) |
1040 |
1040 |
. ' rg_op_s mkdir -p "${rgfs}" || break' . "\n" |
. ' rg_op_s mkdir -p "${rgfs}" || break' . "\n" |
1041 |
1041 |
. ' if [ "${job_uid}" = "${pkg_repo_uid}" ]; then' . "\n" |
. ' if [ "${job_uid}" = "${pkg_repo_uid}" ]; then' . "\n" |
1042 |
1042 |
. ' rg_cp -av "${rpms_dir}"/*.rpm "${rgfs}/" || break' . "\n" |
. ' rg_cp -av "${rpms_dir}"/*.rpm "${rgfs}/" || break' . "\n" |
1043 |
|
. ' else' . "\n" |
|
|
1043 |
|
. ' else' . "\n" // TODO: shouldn't I copy directly to ${rgfs}/${repo_username} if do_sensitive_ops==1? Seems it cannot happen! when we are uid 0, we do not need to copy! |
1044 |
1044 |
. ' # "+" is used because it is not allowed in username' . "\n" |
. ' # "+" is used because it is not allowed in username' . "\n" |
1045 |
1045 |
. ' rg_op_s mkdir -p "${rgfs}/+pending/${repo_username}" || break' . "\n" |
. ' rg_op_s mkdir -p "${rgfs}/+pending/${repo_username}" || break' . "\n" |
1046 |
1046 |
. ' rg_cp -av "${rpms_dir}/${repo_username}"/*.rpm "${rgfs}/+pending/${repo_username}/" || break' . "\n" |
. ' rg_cp -av "${rpms_dir}/${repo_username}"/*.rpm "${rgfs}/+pending/${repo_username}/" || break' . "\n" |
1047 |
1047 |
. ' fi' . "\n" |
. ' fi' . "\n" |
|
1048 |
|
. "\n" |
|
1049 |
|
. ' if [ "`do_sensitive_ops`" != "1" ]; then' . "\n" |
|
1050 |
|
. ' xecho "Triggering the rebuild of subrepo"' . "\n" |
|
1051 |
|
. ' echo "${pkg_subrepo_id}" >> /mnt/build2/pkg_subrepo_dirty' . "\n" // TODO: Shouldn't be done by rgfs? |
|
1052 |
|
. ' fi' . "\n" |
1048 |
1053 |
. ' rg_log_pop' . "\n" |
. ' rg_log_pop' . "\n" |
1049 |
1054 |
. ' else' . "\n" |
. ' else' . "\n" |
1050 |
1055 |
. ' xecho "No packages in pkg_list_file."' . "\n" |
. ' xecho "No packages in pkg_list_file."' . "\n" |
1051 |
1056 |
. ' fi'. "\n" |
. ' fi'. "\n" |
1052 |
|
. "\n" |
|
1053 |
|
. ' if [ "`do_sensitive_ops`" != "1" ]; then' . "\n" |
|
1054 |
|
. ' xecho "Triggering the rebuild of subrepo"' . "\n" |
|
1055 |
|
. ' echo "${pkg_subrepo_id}" >> /mnt/build2/pkg_subrepo_dirty' . "\n" |
|
1056 |
|
. ' else' . "\n" |
|
|
1057 |
|
. "\n" |
|
1058 |
|
. ' if [ "`do_sensitive_ops`" = "1" ]; then' . "\n" |
1057 |
1059 |
. ' rg_rpm_createrepo "${env_distro}" "${rgfs}" \\' . "\n" |
. ' rg_rpm_createrepo "${env_distro}" "${rgfs}" \\' . "\n" |
1058 |
1060 |
. ' "${pkg_filter_list_file}" "${repo_username}" || break' . "\n" |
. ' "${pkg_filter_list_file}" "${repo_username}" || break' . "\n" |
1059 |
1061 |
. ' fi' . "\n"; |
. ' fi' . "\n"; |
|
... |
... |
function start_worker_build_repo($job, $conf, &$reason, &$reason2) |
1061 |
1063 |
$s .= "\n" |
$s .= "\n" |
1062 |
1064 |
. ' rg_log_pop' . "\n" |
. ' rg_log_pop' . "\n" |
1063 |
1065 |
. ' done ;;' . "\n" |
. ' done ;;' . "\n" |
1064 |
|
. ' *) xecho "Unknown distro!"; E=1 ;;' . "\n" |
|
|
1066 |
|
. ' *) xecho "Unsupported distro!"; E=1 ;;' . "\n" |
1065 |
1067 |
. ' esac' . "\n" |
. ' esac' . "\n" |
1066 |
1068 |
. ' [ "${E}" = "0" ] || break' . "\n" |
. ' [ "${E}" = "0" ] || break' . "\n" |
1067 |
|
. "\n" |
|
|
1069 |
|
. "\n" |
1068 |
1070 |
. ' if [ "${rgfs_mounted[${pkg_repo_id}-${pkg_subrepo_id}]}" = "1" ]; then' . "\n" |
. ' if [ "${rgfs_mounted[${pkg_repo_id}-${pkg_subrepo_id}]}" = "1" ]; then' . "\n" |
1069 |
1071 |
. ' xecho "Unmounting rgfs"' . "\n" |
. ' xecho "Unmounting rgfs"' . "\n" |
1070 |
1072 |
. ' umount "/mnt/build2/rgfs/${pkg_repo_id}/${pkg_subrepo_id}"' . "\n" |
. ' umount "/mnt/build2/rgfs/${pkg_repo_id}/${pkg_subrepo_id}"' . "\n" |
|
... |
... |
function start_worker($job) |
1367 |
1369 |
$p_i_cmd = ''; |
$p_i_cmd = ''; |
1368 |
1370 |
if (!empty($job['packages'])) { |
if (!empty($job['packages'])) { |
1369 |
1371 |
rg_log_debug('packages: ' . $job['packages'] . '.'); |
rg_log_debug('packages: ' . $job['packages'] . '.'); |
1370 |
|
$p_i_cmd .= 'echo "MInstalling webhook specified packages" > /dev/virtio-ports/rgw' . "\n"; |
|
|
1372 |
|
$p_i_cmd .= 'rg_notify "Installing webhook specified packages"' . "\n"; |
1371 |
1373 |
|
|
1372 |
1374 |
$pkgs = explode(' ', $job['packages']); |
$pkgs = explode(' ', $job['packages']); |
1373 |
1375 |
$p_i_cmd .= '> /mnt/packages.log' . "\n"; |
$p_i_cmd .= '> /mnt/packages.log' . "\n"; |
|
... |
... |
function start_worker($job) |
1411 |
1413 |
. "\n" |
. "\n" |
1412 |
1414 |
. 'source /mnt/build_tools.sh' . "\n" |
. 'source /mnt/build_tools.sh' . "\n" |
1413 |
1415 |
. "\n" |
. "\n" |
|
1416 |
|
. 'chmod a+rw /dev/virtio-ports/rgw # Else, we cannot signal from inside the build' . "\n" |
|
1417 |
|
. 'rg_notify "rg.sh started"' . "\n" |
|
1418 |
|
. "\n" |
1414 |
1419 |
. 'mkdir /mnt/tmp && chmod 1777 /mnt/tmp' . "\n" |
. 'mkdir /mnt/tmp && chmod 1777 /mnt/tmp' . "\n" |
1415 |
1420 |
. 'mount --bind /mnt/tmp /tmp' . "\n" |
. 'mount --bind /mnt/tmp /tmp' . "\n" |
1416 |
1421 |
. 'mkdir -p /mnt/var/tmp && chmod 1777 /mnt/var/tmp' . "\n" |
. 'mkdir -p /mnt/var/tmp && chmod 1777 /mnt/var/tmp' . "\n" |
|
... |
... |
function start_worker($job) |
1424 |
1429 |
. 'ERR=""' . "\n" |
. 'ERR=""' . "\n" |
1425 |
1430 |
. 'id' . "\n" |
. 'id' . "\n" |
1426 |
1431 |
. 'date +%s > /mnt/T_START' . "\n" |
. 'date +%s > /mnt/T_START' . "\n" |
1427 |
|
. 'chmod a+rw /dev/virtio-ports/rgw # Else, we cannot signal from inside the build' . "\n" |
|
1428 |
|
. 'echo "MVM started" > /dev/virtio-ports/rgw' . "\n" |
|
1429 |
1432 |
. "\n" |
. "\n" |
1430 |
|
. 'echo "MWaiting for net" > /dev/virtio-ports/rgw' . "\n" |
|
|
1433 |
|
. 'rg_notify "Waiting for net"' . "\n" |
1431 |
1434 |
. '# Waiting for net' . "\n" |
. '# Waiting for net' . "\n" |
1432 |
1435 |
. 'while [ "`ip ro li | grep ^default`" = "" ]; do' . "\n" |
. 'while [ "`ip ro li | grep ^default`" = "" ]; do' . "\n" |
1433 |
1436 |
. ' sleep 1' . "\n" |
. ' sleep 1' . "\n" |
1434 |
1437 |
. 'done' . "\n" |
. 'done' . "\n" |
1435 |
1438 |
. 'date +%s > /mnt/T_NET_OK' . "\n\n" |
. 'date +%s > /mnt/T_NET_OK' . "\n\n" |
|
1439 |
|
. 'rg_notify "Net OK"' . "\n" |
1436 |
1440 |
. "\n" |
. "\n" |
1437 |
1441 |
. $p_i_cmd |
. $p_i_cmd |
1438 |
1442 |
. 'date +%s > /mnt/T_PKGS_OK' . "\n\n" |
. 'date +%s > /mnt/T_PKGS_OK' . "\n\n" |
|
... |
... |
function start_worker($job) |
1484 |
1488 |
. ' fi' . "\n" |
. ' fi' . "\n" |
1485 |
1489 |
. ' fi' . "\n" |
. ' fi' . "\n" |
1486 |
1490 |
. "\n" |
. "\n" |
|
1491 |
|
. ' rg_notify "Stating build.sh script"' . "\n" |
1487 |
1492 |
. ' echo; echo "`date`: Running build.sh script"' . "\n" |
. ' echo; echo "`date`: Running build.sh script"' . "\n" |
1488 |
1493 |
. ' date +%s > /mnt/status/build.sh.start' . "\n" // TODO: not read and not exposed? |
. ' date +%s > /mnt/status/build.sh.start' . "\n" // TODO: not read and not exposed? |
1489 |
1494 |
. ' su - build -c "bash /mnt/build.sh" &>/mnt/status/build.log' . "\n" |
. ' su - build -c "bash /mnt/build.sh" &>/mnt/status/build.log' . "\n" |
1490 |
1495 |
. ' E=${?}' . "\n" |
. ' E=${?}' . "\n" |
1491 |
1496 |
. ' date +%s > /mnt/status/build.sh.stop' . "\n" // TODO: not read and not exposed? |
. ' date +%s > /mnt/status/build.sh.stop' . "\n" // TODO: not read and not exposed? |
|
1497 |
|
. ' rg_notify "build.sh finished with code ${E}"' . "\n" |
1492 |
1498 |
. ' if [ "${E}" != "0" ]; then' . "\n" |
. ' if [ "${E}" != "0" ]; then' . "\n" |
1493 |
1499 |
. ' echo "`date`: DEBUG: build.sh exited with code ${E}"' . "\n" |
. ' echo "`date`: DEBUG: build.sh exited with code ${E}"' . "\n" |
1494 |
1500 |
. ' ERR="build.sh returned ${E}"' . "\n" |
. ' ERR="build.sh returned ${E}"' . "\n" |
1495 |
1501 |
. ' break' . "\n" |
. ' break' . "\n" |
1496 |
1502 |
. ' fi' . "\n" |
. ' fi' . "\n" |
1497 |
1503 |
. "\n" |
. "\n" |
|
1504 |
|
. ' rg_notify "Stating build_rpms.sh script"' . "\n" |
1498 |
1505 |
. ' echo; echo "`date`: Running build_rpms.sh script"' . "\n" |
. ' echo; echo "`date`: Running build_rpms.sh script"' . "\n" |
1499 |
1506 |
. ' date +%s > /mnt/T_RPMS_START' . "\n" |
. ' date +%s > /mnt/T_RPMS_START' . "\n" |
1500 |
1507 |
. ' su - build -c "bash /mnt/build_rpms.sh" &>/mnt/status/build_rpms.log' . "\n" |
. ' su - build -c "bash /mnt/build_rpms.sh" &>/mnt/status/build_rpms.log' . "\n" |
1501 |
1508 |
. ' E=${?}' . "\n" |
. ' E=${?}' . "\n" |
1502 |
1509 |
. ' date +%s > /mnt/T_RPMS_END' . "\n" |
. ' date +%s > /mnt/T_RPMS_END' . "\n" |
|
1510 |
|
. ' rg_notify "build_rpms.sh finished with code ${E}"' . "\n" |
1503 |
1511 |
. ' if [ "${E}" != "0" ]; then' . "\n" |
. ' if [ "${E}" != "0" ]; then' . "\n" |
1504 |
1512 |
. ' ERR="build_rpms.sh returned ${E}"' . "\n" |
. ' ERR="build_rpms.sh returned ${E}"' . "\n" |
1505 |
1513 |
. ' break' . "\n" |
. ' break' . "\n" |
|
... |
... |
function start_worker($job) |
1510 |
1518 |
. ' [ -d /mnt/target/rocketgit ] && mv -f /mnt/target/rocketgit /mnt/build2' . "\n" |
. ' [ -d /mnt/target/rocketgit ] && mv -f /mnt/target/rocketgit /mnt/build2' . "\n" |
1511 |
1519 |
. ' chown -R build2:build2 /mnt/build2 /mnt/rpmbuild' . "\n" |
. ' chown -R build2:build2 /mnt/build2 /mnt/rpmbuild' . "\n" |
1512 |
1520 |
. "\n" |
. "\n" |
|
1521 |
|
. ' rg_notify "Stating build_rgfs.sh script"' . "\n" |
1513 |
1522 |
. ' echo; echo "`date`: Running build_rgfs.sh script"' . "\n" |
. ' echo; echo "`date`: Running build_rgfs.sh script"' . "\n" |
1514 |
1523 |
. ' bash /mnt/build_rgfs.sh &>/mnt/status/build_rgfs.log' . "\n" |
. ' bash /mnt/build_rgfs.sh &>/mnt/status/build_rgfs.log' . "\n" |
1515 |
1524 |
. ' if [ "${?}" != "0" ]; then' . "\n" |
. ' if [ "${?}" != "0" ]; then' . "\n" |
|
... |
... |
function start_worker($job) |
1517 |
1526 |
. ' fi' . "\n" |
. ' fi' . "\n" |
1518 |
1527 |
. "\n" |
. "\n" |
1519 |
1528 |
. ' if [ -x /mnt/build_repo.sh ]; then' . "\n" |
. ' if [ -x /mnt/build_repo.sh ]; then' . "\n" |
|
1529 |
|
. ' rg_notify "Stating build_repo.sh script"' . "\n" |
1520 |
1530 |
. ' echo; echo "`date`: Running build_repo.sh script"' . "\n" |
. ' echo; echo "`date`: Running build_repo.sh script"' . "\n" |
1521 |
1531 |
. ' date +%s > /mnt/T_REPO_START' . "\n" |
. ' date +%s > /mnt/T_REPO_START' . "\n" |
1522 |
1532 |
. ' su - build2 -c "bash /mnt/build_repo.sh" &>/mnt/status/build_repo.log' . "\n" |
. ' su - build2 -c "bash /mnt/build_repo.sh" &>/mnt/status/build_repo.log' . "\n" |
1523 |
1533 |
. ' E=${?}' . "\n" |
. ' E=${?}' . "\n" |
1524 |
1534 |
. ' date +%s > /mnt/T_REPO_END' . "\n" |
. ' date +%s > /mnt/T_REPO_END' . "\n" |
|
1535 |
|
. ' rg_notify "build_repo.sh finished with code ${E}"' . "\n" |
1525 |
1536 |
. ' if [ "${E}" != "0" ]; then' . "\n" |
. ' if [ "${E}" != "0" ]; then' . "\n" |
1526 |
1537 |
. ' ERR="build_repo.sh returned ${E}"' . "\n" |
. ' ERR="build_repo.sh returned ${E}"' . "\n" |
1527 |
1538 |
. ' break' . "\n" |
. ' break' . "\n" |
|
... |
... |
function start_worker($job) |
1532 |
1543 |
. 'done' . "\n" |
. 'done' . "\n" |
1533 |
1544 |
. 'if [ "${ERR}" != "" ]; then' . "\n" |
. 'if [ "${ERR}" != "" ]; then' . "\n" |
1534 |
1545 |
. ' echo "${ERR}" > /mnt/status/err' . "\n" |
. ' echo "${ERR}" > /mnt/status/err' . "\n" |
1535 |
|
. ' echo "EERROR: ${ERR}" > /dev/virtio-ports/rgw' . "\n" |
|
|
1546 |
|
. ' rg_notify_err "ERROR: ${ERR}"' . "\n" |
1536 |
1547 |
. 'fi' . "\n" |
. 'fi' . "\n" |
1537 |
1548 |
. 'date +%s > /mnt/T_DONE' . "\n\n" |
. 'date +%s > /mnt/T_DONE' . "\n\n" |
1538 |
|
. 'echo "MDONE" > /dev/virtio-ports/rgw' . "\n" |
|
|
1549 |
|
. 'rg_notify "DONE"' . "\n" |
1539 |
1550 |
. "\n" |
. "\n" |
1540 |
1551 |
. 'echo; echo "`date`: Syncing"' . "\n" |
. 'echo; echo "`date`: Syncing"' . "\n" |
1541 |
1552 |
. 'sync' . "\n" |
. 'sync' . "\n" |
1542 |
1553 |
. "\n" |
. "\n" |
|
1554 |
|
. 'rg_notify "Shutting down"' . "\n" |
1543 |
1555 |
. 'echo; echo "`date`: Shutting down"' . "\n" |
. 'echo; echo "`date`: Shutting down"' . "\n" |
1544 |
1556 |
. 'while [ -r /root/stop ]; do' . "\n" |
. 'while [ -r /root/stop ]; do' . "\n" |
1545 |
1557 |
. ' sleep 1' . "\n" |
. ' sleep 1' . "\n" |
File techdocs/rpm.txt added (mode: 100644) (index 0000000..db1d81c) |
|
1 |
|
Try to describe what happens when a build hook is present, |
|
2 |
|
a .spec file is present in the repo and the user pushes. |
|
3 |
|
|
|
4 |
|
== Scenario 1 == |
|
5 |
|
- User pushes |
|
6 |
|
- Web hook will trigger event 'rg_wh_build_send' |
|
7 |
|
- 'rg_wh_build_send' will trigger event 'rg_wh_build_send_one' for each enabled environments |
|
8 |
|
- 'rg_wh_build_send_one' will |
|
9 |
|
- get the pkg_maps, repo and subrepo info |
|
10 |
|
- sets exec:prepare_rpms and exec:copy_to_rgfs flags |
|
11 |
|
- will call 'rg_pkg_prepare_ev_for_dotrepo' to create user repositories |
|
12 |
|
- will call 'rg_builder_add' |
|
13 |
|
- Builer will send the job to a worker |
|
14 |
|
- Worker will start the VM |
|
15 |
|
- Inside VM, script rg.sh is started |
|
16 |
|
- Checkout correct branch |
|
17 |
|
- .spec file is searched are BuildRequires are installed |
|
18 |
|
- 'build.sh' starts [as user 'build'] |
|
19 |
|
- Secrets are exported |
|
20 |
|
- The commands defined in the webhook are run |
|
21 |
|
- 'build_rpms.sh' starts [as user 'build'] |
|
22 |
|
- 'rg_build_rpm' shell function is called for '/mnt/target' |
|
23 |
|
- for each job[rpm_repo_files] 'rg_build_dotrepo /mnt/target-dotrepo-<subrepo_id>' is called |
|
24 |
|
- 'build_rgfs.sh' starts [as user 'root'] |
|
25 |
|
- 'build_repo.sh' starts [as user 'build2'] |
|
26 |
|
- If no pkg mapping is defined, exit |
|
27 |
|
- gpg keys are stored in /mnt/build2 |
|
28 |
|
- Search for .rpm packages in /mnt/rpmbuild |
|
29 |
|
- Imports gpg keys |
|
30 |
|
- If flag exec:prepare_rpms is set: |
|
31 |
|
- .rpms are copied into /mnt/build2/rpms/<pkg_repo_id}/{debug,os,src}[/username] |
|
32 |
|
- A file A, containing the rpms, is created and rpms are signed |
|
33 |
|
- For each mapping |
|
34 |
|
- a rgfs is mounted |
|
35 |
|
- if '+pending' dir is found, we add the rpms to the file A |
|
36 |
|
- if file A is empty, continue with next mapping |
|
37 |
|
- If a rpm file is already in the repo, remove the name from file A |
|
38 |
|
- if the build is done as uid 0, sign the '+pending' rpms |
|
39 |
|
- if exec:copy_to_rgfs flag is present, copy the signed rpms to rgfs dir |
|
40 |
|
- if uid is not 0 and pkg_repo uid != job_uid, save the pkg_subrepo_id into /mnt/build2/pkg_subrepo_dirty |
|
41 |
|
- If uid is 0 or pkg_repo_uid == job_uid, call rg_rpm_createrepo |
|
42 |
|
- Unmount all rgfs dirs |
|
43 |
|
|
|
44 |
|
- VM is shutdown and logs and timings are collected |
|
45 |
|
- Worker notifies the Builder |
|
46 |
|
- Builder calls 'builder_done' function which will trigger 'wh_build_job_done' |
|
47 |
|
|
|
48 |
|
|
|
49 |
|
== Scenario 2 == |
|
50 |
|
- User, from the web interface, edits a pkg_repo/subrepo: |
|
51 |
|
- 'pkg_subrepo_edit' event is triggered (user edited a pkg subrepo) |
|
52 |
|
triggers 'rg_pkg_subrepo_event_edit' event |
|
53 |
|
- or 'rg_pkg_subrepo_event_pkg_repo_changed' event is triggered (user edited a pkg repo) |
|
54 |
|
triggers 'rg_pkg_subrepo_event_edit' event |
|
55 |
|
|
|
56 |
|
|
|
57 |
|
== Events called from the scenarios == |
|
58 |
|
- Event 'wh_build_job_done' [function rg_wh_build_job_done] |
|
59 |
|
If callbacks are present, add events for all of them |
|
60 |
|
|
|
61 |
|
- Event 'rg_pkg_subrepo_event_edit': |
|
62 |
|
- flag force_regenerate_dotrepo is set to 1 because version was incremented |
|
63 |
|
- only for environments which already have a dotrepo (no build for empty pkg repos) |
|
64 |
|
- calls 'pkg_generate_dotrepo_rpm' event for all enabled envs |
|
65 |
|
|
|
66 |
|
- Event 'pkg_generate_dotrepo_rpm' [function rg_pkg_event_generate_dotrepo_rpm]: |
|
67 |
|
- sets 'exec:worker_must_be_global' flag - we do not trust user workers |
|
68 |
|
- prepares a fake pkg_maps from the pkg_repo/subrepo passed in the event |
|
69 |
|
- calls 'rg_pkg_prepare_ev_for_dotrepo' function |
|
70 |
|
- calls 'rg_builder_add' |
|
71 |
|
|
|
72 |
|
- Event 'pkg_subrepo_regenerate' [function rg_pkg_subrepo_event_regenerate]: |
|
73 |
|
- 'uid' is set to 0 |
|
74 |
|
- for each subrepo passed in the event a fake pkg_maps is created |
|
75 |
|
- calls 'rg_pkg_prepare_ev_for_dotrepo' function |
|
76 |
|
- calls 'rg_builder_add' |
|
77 |
|
|
|
78 |
|
- Function 'rg_pkg_prepare_ev_for_dotrepo': |
|
79 |
|
- it avoids not enabled environments (state::distros) |
|
80 |
|
- for each pkg mapping: |
|
81 |
|
- if (event uid != pkg_repo uid) skip (we do not allow a user to influence other repos) |
|
82 |
|
TODO: what if event uid is 0?! |
|
83 |
|
- if (!force_regenerate_dotrepo && we already generated the last version of dotrepo) skip |
|
84 |
|
- adds files which will go in /etc/yum.repos.d and gpg keys |
|
85 |
|
- it will add an event callback: 'pkg_generate_dotrepo_rpm_callback' |
|
86 |
|
|
|
87 |
|
- Event 'rg_pkg_subrepo_update_distro_info' [function rg_pkg_event_generate_dotrepo_rpm_callback function] |
|
88 |
|
it calls: rg_pkg_subrepo_update_distro_info and |
|
89 |
|
triggers pkg_subrepo_regenerate if ev[status][pkg_subrepo_dirty'] is present |
|
90 |
|
this flag is set when build_repo.sh is copying something to +pending |
|
91 |
|
|
|
92 |
|
- Event 'pkg_generate_dotrepo_rpm_callback' [function rg_pkg_event_generate_dotrepo_rpm_callback]: |
|
93 |
|
- called when a dotrepo was done |
|
94 |
|
- for each (subrepo, ver), call 'rg_pkg_subrepo_update_distro_info' |
|
95 |
|
- if 'status:pkg_subrepo_dirty' is present, trigger 'pkg_subrepo_regenerate' event |
|
96 |
|
Set by the 'worker', based on /root/build2/pkg_subrepo_dirty file |
|
97 |
|
Set by exec:copy_to_rgfs phase of build_repo.sh when some .rpm are copied on rgfs |
|
98 |
|
|
|
99 |
|
|
|
100 |
|
== old == |
|
101 |
|
- The .spec file is found and .rpm files are generated. |
|
102 |
|
- The .rpm files are moved to '+pending folder'. |
|
103 |
|
We do not create directly the repo because we do not trust the |
|
104 |
|
environment anymore. |
|
105 |
|
- The finish of the job will trigger the rebuild of the repo. |
|
106 |
|
- If a "dotrepo" .rpm file (containing files which will be put in |
|
107 |
|
/etc/yum.repos.d) is not built for that repo/distro/major/arch |
|
108 |
|
the build is triggered. |
|
109 |
|
== old end == |
|
110 |
|
|