From 78b0f246af03e56a4a8c244c7f2dde574d0ee250 Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Tue, 25 Aug 2015 09:03:00 -0300 Subject: Adapt tools scripts for pfSense main repo (round #1): - Move SCRATCHDIR to ./tmp and add it to .gitignore - Move logs to ./logs and add it to .gitignore - Add build.conf to .gitignore - Rename BUILDER_TOOLS to BUILDER_ROOT that makes more sense in new infrastructure - Change some (cd DIR && git) to git -C DIR - Remove BASE_DIR - Remove TOOLS_DIR - Remove update_product_repository() - Remove TOOLS_*_COMMIT variables - Rename PRODUCT_CURRENT_COMMIT and PRODUCT_LAST_COMMIT to simply CURRENT_COMMIT and LAST_COMMIT - Remove all use of GIT_REPO_DIR, GIT_REPO_UTL and GIT_REPO_TOOLS - Change clone_to_staging_area() to clone ./src instad of ./ - Detect if script was called from / or /tools and set BUILDER_ROOT and BUILDER_SCRIPTS properly - Create SCRATCHDIR if it doesn't exist --- .gitignore | 3 ++ tools/build_snapshots.sh | 27 +++++---------- tools/builder_common.sh | 85 ++++------------------------------------------- tools/builder_defaults.sh | 21 +++++------- 4 files changed, 26 insertions(+), 110 deletions(-) diff --git a/.gitignore b/.gitignore index 2b2fe03..267142b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ .DS_Store _notes/ +/tmp/ +/logs/ +/build.conf # Ignore Vim swap files .*.swp diff --git a/tools/build_snapshots.sh b/tools/build_snapshots.sh index e1fe313..7e1c1e1 100755 --- a/tools/build_snapshots.sh +++ b/tools/build_snapshots.sh @@ -78,9 +78,8 @@ echo "" > $SNAPSHOTSLASTUPDATE git_last_commit() { if [ -d "${1}/.git" ]; then - (cd ${1} && git fetch origin && git rebase) >/dev/null - CURRENT_COMMIT=$(cd ${1} && git log -1 --format='%H') - echo "$CURRENT_COMMIT" + git -C "${1}" pull -q + git -C "${1}" log -1 --format='%H' fi } @@ -91,17 +90,11 @@ sleep_between_runs() { COUNTER=0 while [ $COUNTER -lt $maxsleepvalue ]; do sleep 60 - PRODUCT_CURRENT_COMMIT=$(git_last_commit "${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG}") - if [ "${PRODUCT_LAST_COMMIT}" != "${PRODUCT_CURRENT_COMMIT}" ]; then - update_status ">>> New commit: $CURRENT_AUTHOR - $PRODUCT_CURRENT_COMMIT .. No longer sleepy." + CURRENT_COMMIT=$(git_last_commit "${BUILDER_ROOT}") + if [ "${LAST_COMMIT}" != "${CURRENT_COMMIT}" ]; then + update_status ">>> New commit: $CURRENT_AUTHOR - $CURRENT_COMMIT .. No longer sleepy." COUNTER=$(($maxsleepvalue + 60)) - export PRODUCT_LAST_COMMIT="${PRODUCT_CURRENT_COMMIT}" - fi - TOOLS_CURRENT_COMMIT=$(git_last_commit "${BUILDER_TOOLS}") - if [ "${TOOLS_LAST_COMMIT}" != "${TOOLS_CURRENT_COMMIT}" ]; then - update_status ">>> New commit: $CURRENT_AUTHOR - $TOOLS_CURRENT_COMMIT .. No longer sleepy." - COUNTER=$(($maxsleepvalue + 60)) - export TOOLS_LAST_COMMIT="${TOOLS_CURRENT_COMMIT}" + export LAST_COMMIT="${CURRENT_COMMIT}" fi COUNTER=$(($COUNTER + 60)) done @@ -345,12 +338,10 @@ else export maxsleepvalue=86400 # Initialize variables that keep track of last commit - [ -z "${PRODUCT_LAST_COMMIT}" ] \ - && export PRODUCT_LAST_COMMIT="$(cd "${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG}" && git log | head -n1 | cut -d' ' -f2)" - [ -z "${TOOLS_LAST_COMMIT}" ] \ - && export TOOLS_LAST_COMMIT="$(cd "${BUILDER_SCRIPTS}" && git log | head -n1 | cut -d' ' -f2)" + [ -z "${LAST_COMMIT}" ] \ + && export LAST_COMMIT="$(git -C ${BUILDER_ROOT} log | head -n1 | cut -d' ' -f2)" - update_status ">>> Sleeping for at least $minsleepvalue, at most $maxsleepvalue in between snapshot builder runs. Last known commit ${PRODUCT_LAST_COMMIT}/${TOOLS_LAST_COMMIT}" + update_status ">>> Sleeping for at least $minsleepvalue, at most $maxsleepvalue in between snapshot builder runs. Last known commit ${LAST_COMMIT}" update_status ">>> Freezing build process at `date`." sleep $minsleepvalue update_status ">>> Thawing build process and resuming checks for pending commits at `date`." diff --git a/tools/builder_common.sh b/tools/builder_common.sh index 8ff0b39..3ea3142 100644 --- a/tools/builder_common.sh +++ b/tools/builder_common.sh @@ -55,14 +55,10 @@ lc() { } git_last_commit() { - if [ -d "${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG}/.git" ]; then - CURRENT_COMMIT=$(cd ${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG} && git log -1 --format='%H') - CURRENT_AUTHOR=$(cd ${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG} && git log -1 --format='%an') - echo ">>> Last known commit $CURRENT_AUTHOR - $CURRENT_COMMIT" - echo "$CURRENT_COMMIT" > $SCRATCHDIR/build_commit_info.txt - else - echo ">>> WARNING: git repo is not cloned! Previous commit functions disabled." - fi + CURRENT_COMMIT=$(git -C ${TOOLS_ROOT} log -1 --format='%H') + CURRENT_AUTHOR=$(git -C ${TOOLS_ROOT} log -1 --format='%an') + echo ">>> Last known commit $CURRENT_AUTHOR - $CURRENT_COMMIT" + echo "$CURRENT_COMMIT" > $SCRATCHDIR/build_commit_info.txt } # Create core pkg (base, kernel) @@ -374,7 +370,6 @@ print_flags() { echo printf " Product version: %s\n" $PRODUCT_VERSION - printf " BASE_DIR: %s\n" $BASE_DIR printf " Stage DIR: %s\n" $STAGE_CHROOT_DIR printf " Updates dir: %s\n" $UPDATESDIR printf " Image Preparation Stage DIR: %s\n" $FINAL_CHROOT_DIR @@ -383,7 +378,6 @@ print_flags() { printf " FreeBSD-src branch: %s\n" $FREEBSD_BRANCH printf " FreeBSD original branch: %s\n" $FREEBSD_PARENT_BRANCH printf " BUILD_KERNELS: %s\n" $BUILD_KERNELS - printf " Git Repository: %s\n" $GIT_REPO_URL printf " Git Branch or Tag: %s\n" $GIT_REPO_BRANCH_OR_TAG printf " MODULES_OVERRIDE: %s\n" $MODULES_OVERRIDE printf " OVADISKSIZE: %s\n" $OVADISKSIZE @@ -405,58 +399,6 @@ fi echo } -# This updates the product sources -update_product_repository() { - if [ ! -d "${GIT_REPO_DIR}" ]; then - echo ">>> Creating ${GIT_REPO_DIR}" - mkdir -p ${GIT_REPO_DIR} - fi - - echo ">>> Using GIT to checkout ${GIT_REPO_BRANCH_OR_TAG}" - - # There is already a cloned repo, test if branch is correct - if [ -d "${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG}/.git" ]; then - if ! (cd ${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG} && git rev-parse --verify ${GIT_REPO_BRANCH_OR_TAG} >/dev/null 2>&1); then - echo -n ">>> ${PRODUCT_NAME} git repo is at wrong branch, removing it... " - rm -rf ${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG} - echo "Done!" - fi - fi - - if [ ! -d "${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG}/.git" ]; then - echo -n ">>> Cloning ${GIT_REPO_URL} (${GIT_REPO_BRANCH_OR_TAG})... " - (git clone --depth 1 --single-branch --branch ${GIT_REPO_BRANCH_OR_TAG} ${GIT_REPO_URL} ${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG}) 2>&1 | \ - egrep -B3 -A3 -wi -E '(error)|fatal' - if [ ! -d "${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG}/conf.default" ]; then - echo "Failed!" - echo - echo "!!!! An error occurred while checking out ${PRODUCT_NAME}" - echo " Could not locate ${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG}/conf.default" - echo - print_error_pfS - fi - echo "Done!" - else - # It is necessary for the case when a tag has moved - local TAG=$(cd ${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG} && git tag) - if [ "${TAG}" = "${GIT_REPO_BRANCH_OR_TAG}" ]; then - RESET_TARGET="${GIT_REPO_BRANCH_OR_TAG}" - else - RESET_TARGET="origin/${GIT_REPO_BRANCH_OR_TAG}" - fi - - # Fetch an update of the repository - if ! (cd ${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG} && \ - git fetch origin; \ - git reset --hard ${RESET_TARGET}; \ - git clean -fxd ) >/dev/null 2>&1 - then - echo ">>> ERROR: Something went wrong while checking out GIT." - print_error_pfS - fi - fi -} - # This builds FreeBSD (make buildworld) # Imported from FreeSBIE make_world() { @@ -1099,13 +1041,6 @@ clean_obj_dir() { echo "Done!" if [ -z "${NO_CLEANREPOS}" ]; then - if [ -d "${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG}" ]; then - echo -n ">>> Cleaning ${PRODUCT_NAME} repo checkout..." - echo -n "." - rm -rf "${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG}" - echo "Done!" - fi - if [ -d "$SRCDIR" ]; then echo -n ">>> Ensuring $SRCDIR is clean..." rm -rf ${SRCDIR} @@ -1128,8 +1063,6 @@ clean_obj_dir() { # and is ready for action / building. ensure_source_directories_present() { update_freebsd_sources - - update_product_repository } clone_directory_contents() { @@ -1151,13 +1084,7 @@ clone_to_staging_area() { echo -n ">>> Cloning everything to ${STAGE_CHROOT_DIR} staging area..." LOGFILE=${BUILDER_LOGS}/cloning.${TARGET}.log - if [ ! -d ${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG} ]; then - echo "ERROR!" - echo ">>> ERROR: ${PRODUCT_NAME} repository does not seem to be there please fix...STOPPING!" | tee -a ${LOGFILE} - print_error_pfS - fi - - tar --exclude=\.git -C ${GIT_REPO_DIR}/${GIT_REPO_BRANCH_OR_TAG} -c -f - . | \ + tar -C ${TOOLS_ROOT}/src -c -f - . | \ tar -C ${STAGE_CHROOT_DIR} -x -p -f - if [ -f ${STAGE_CHROOT_DIR}/etc/master.passwd ]; then @@ -2004,7 +1931,7 @@ poudriere_bulk() { poudriere_create_ports_tree - local CUR_BRANCH=$(cd ${BUILDER_TOOLS} && git branch | grep '^\*' | cut -d' ' -f2) + local CUR_BRANCH=$(cd ${BUILDER_ROOT} && git branch | grep '^\*' | cut -d' ' -f2) [ -d /usr/local/etc/poudriere.d ] || \ mkdir -p /usr/local/etc/poudriere.d diff --git a/tools/builder_defaults.sh b/tools/builder_defaults.sh index 0b094c5..a01b31d 100644 --- a/tools/builder_defaults.sh +++ b/tools/builder_defaults.sh @@ -62,13 +62,13 @@ local _curdir=$(basename $(dirname ${0})) if [ "${_curdir}" = "tools" ]; then export BUILDER_SCRIPTS=$(realpath ${_curdir}) - export BUILDER_TOOLS=$(realpath "${_curdir}/..") + export BUILDER_ROOT=$(realpath "${_curdir}/..") else export BUILDER_SCRIPTS=$(realpath "${_curdir}/tools") - export BUILDER_TOOLS=$(realpath "${_curdir}") + export BUILDER_ROOT=$(realpath "${_curdir}") fi -BUILD_CONF="${BUILDER_TOOLS}/build.conf" +BUILD_CONF="${BUILDER_ROOT}/build.conf" # Ensure file exists if [ -f ${BUILD_CONF} ]; then @@ -109,15 +109,15 @@ export PRODUCT_URL=${PRODUCT_VERSION:-"https://www.pfsense.org/"} export GIT_REPO_BRANCH_OR_TAG=${GIT_REPO_BRANCH_OR_TAG:-master} # Directory to be used for writing temporary information -export SCRATCHDIR=${SCRATCHDIR:-/tmp} +export SCRATCHDIR=${SCRATCHDIR:-"${BUILDER_ROOT}/tmp"} +if [ ! -d ${SCRATCHDIR} ]; then + mkdir -p ${SCRATCHDIR} +fi # Area that the final image will appear in export MAKEOBJDIRPREFIXFINAL=${MAKEOBJDIRPREFIXFINAL:-${SCRATCHDIR}/${PRODUCT_NAME}/} -export TOOLS_DIR=${TOOLS_DIR:-$(basename ${BUILDER_TOOLS})} -export BASE_DIR=${BASE_DIR:-$(realpath ${BUILDER_TOOLS}/..)} - -export BUILDER_LOGS=${BUILDER_LOGS:-${BUILDER_TOOLS}/logs} +export BUILDER_LOGS=${BUILDER_LOGS:-${BUILDER_ROOT}/logs} if [ ! -d ${BUILDER_LOGS} ]; then mkdir -p ${BUILDER_LOGS} fi @@ -208,11 +208,6 @@ export NANO_BOOT0CFG="-o packet -s 1 -m 3" # " - UNBREAK TEXTMATE FORMATTING - PLEASE LEAVE. -# GIT repositories settings -export GIT_REPO_URL=${GIT_REPO_URL:-"git@git.pfmechanics.com:pfsense/pfsense.git"} -export GIT_REPO_DIR="${BASE_DIR}/${PRODUCT_NAME}_GIT_REPO" -export GIT_REPO_TOOLS=${GIT_REPO_TOOLS:-"git@git.pfmechanics.com:pfsense/pfsense-tools.git"} - # Host to rsync pkg repos from poudriere export PKG_RSYNC_HOSTNAME=${PKG_RSYNC_HOSTNAME:-"beta.pfsense.org"} export PKG_RSYNC_USERNAME=${PKG_RSYNC_USERNAME:-"wwwsync"} -- cgit v1.1