From b1b9d159344c1a21e48eeaaf1e5da27ae7be9623 Mon Sep 17 00:00:00 2001 From: Trevor Batley Date: Sat, 2 Sep 2023 14:37:19 +1000 Subject: [PATCH] refactor install to handle multiple builders --- install-koji-farm.sh | 99 +++++++++++++++++++++++----- koji-setup/deploy-koji-builder.sh | 1 + koji-setup/deploy-koji-nfs-server.sh | 2 + koji-setup/deploy-koji.sh | 20 ------ koji-setup/parameters.sh | 4 -- 5 files changed, 86 insertions(+), 40 deletions(-) mode change 100755 => 100644 koji-setup/deploy-koji.sh diff --git a/install-koji-farm.sh b/install-koji-farm.sh index 7f0501d..548f05f 100644 --- a/install-koji-farm.sh +++ b/install-koji-farm.sh @@ -25,6 +25,8 @@ fi # pull down the deploy scripts SCRIPT_GIT="https://src.koozali.org/smedev/smeserver-koji/raw/branch/master/koji-setup" SCRIPT_DIR="$(echo ~)/bin" +KOJI_PKI_DIR="/etc/pki/koji" + mkdir -p $SCRIPT_DIR curl $SILENT $SCRIPT_GIT/gencert.sh > $SCRIPT_DIR/gencert.sh curl $SILENT $SCRIPT_GIT/deploy-koji.sh > $SCRIPT_DIR/deploy-koji.sh @@ -57,13 +59,6 @@ while true ; do read -p "Org Unit (eg. Koji) " ORG_UNIT if [ $ORG_UNIT ] ; then break ; else echo "Organizational Unit MUST be entered" ; fi done -read -p "Build server FQDN (will default to hub FQDN '$KOJI_HUB_FQDN' if left blank) " KOJI_BUILD_FQDN -if [ $KOJI_BUILD_FQDN ] ; then - echo "$KOJI_BUILD_FQDN will be made a Koji Build server" -else - KOJI_BUILD_FQDN=$KOJI_HUB_FQDN - echo "All-in-one: Hub will now be a build server as well" -fi # create the parameter scripts used by deploy scripts cat > $SCRIPT_DIR/globals.sh <<- EOT @@ -110,17 +105,89 @@ EOT deploy-koji.sh # if there is a separate koji builder deploy that -if [ "$KOJI_BUILD_FQDN" != "$KOJI_HUB_FQDN" ] ; then - # add nfs share for koji files direcory - curl $SILENT $SCRIPT_GIT/deploy-koji-nfs-server.sh > $SCRIPT_DIR/deploy-koji-nfs-server.sh - chmod o+x $SCRIPT_DIR/deploy-koji-nfs-server.sh - deploy-koji-nfs-server.sh - # create a ssh key and add to authorized keys on build server - mkdir -p ~/.ssh - ssh-keygen -t rsa -f /root/.ssh/id_rsa -N "" +PROMPT="Build server FQDN (will default to hub FQDN '$KOJI_HUB_FQDN' if left blank) " +BSNO=1 +while true ; do + read -p "$PROMPT" KOJI_BUILD_FQDN + PROMPT="Build server FQDN. (will stop asking if left blank) " + if [ -z $KOJI_BUILD_FQDN ] ; then + if [[ $BSNO -gt 1 ]] ; then + break + else + KOJI_BUILD_FQDN=$KOJI_HUB_FQDN + echo "All-in-one: Hub will now be a build server as well" + curl $SILENT $SCRIPT_GIT/deploy-koji-builder.sh > $SCRIPT_DIR/deploy-koji-builder.sh + chmod o+x $SDRIPT_DIR/deploy-koji-builder.sh + deploy-koji-builder.sh + break + fi + fi + # check if server available on port 22 + until (nc -z $KOJI_BUILD_FQDN 22) + do + echo "I cannot connect to $KOJI_BUILD_FQDN! Is it online? " + echo "Options:" + echo "- FQDN= # if you've mis-typed the name" + echo "- IP= # I'll add this to your /etc/hosts file" + echo "- # try again (I've started the server)" + echo "- Q # quit this loop" + read RESPONSE + case $RESPONSE in + Q | q ) + break + ;; + null ) + continue + ;; + IP=* ) + BIP=${RESPONSE#*=} + echo "$BIP $KOJI_BUILD_FQDN\n" >> /etc/hosts + continue + ;; + FQDN=* ) + KOJI_BUILD_FQDN=${RESPONSE#*=} + ;; + *) + continue + ;; + esac + done + # we found the server and will deploy to it + echo "$KOJI_BUILD_FQDN will be Koji Build server No. $BSNO" + ((BSNO=BSNO+1)) + + ## On the HUB + # check if nfs has been installed on the hub (only need to install once) + if [ ! -f /etc/exports ] ; then + # add nfs share for koji files direcory to hub + curl $SILENT $SCRIPT_GIT/deploy-koji-nfs-server.sh > $SCRIPT_DIR/deploy-koji-nfs-server.sh + chmod o+x $SCRIPT_DIR/deploy-koji-nfs-server.sh + deploy-koji-nfs-server.sh $KOJI_BUILD_FQDN + else + # add build server to nfs exports line + echo " $KOJI_BUILD_FQDN(ro,no_root_squash)" >> /etc/exports + fi + # Add the host entry for the koji builder to the database + sudo -u kojiadmin koji add-host "$KOJI_BUILD_FQDN" "$RPM_ARCH" + # Add the host to the createrepo channel + sudo -u kojiadmin koji add-host-to-channel "$KOJI_BUILD_FQDN" createrepo + # A note on capacity + sudo -u kojiadmin koji edit-host --capacity="$KOJID_CAPACITY" "$KOJI_BUILD_FQDN" + # Generate a certificate for the builder + pushd "$KOJI_PKI_DIR" + ./gencert.sh "$KOJI_BUILD_FQDN" "/C=$COUNTRY_CODE/ST=$STATE/L=$LOCATION/O=$ORGANIZATION/CN=$KOJI_BUILD_FQDN" + popd + # generate a hub ssl key if there isn't one already (for scp & ssh to builders) + if [ ! -f /root/.ssh/id-rsa ] ; then + # create a ssh key on build server + mkdir -p ~/.ssh + ssh-keygen -t rsa -f /root/.ssh/id_rsa -N "" + fi + + ## On the BUILDER + # copy the server key into authorized keys on the build server ssh-copy-id -i ~/.ssh/id_rsa.pub $KOJI_BUILD_FQDN # copy across the ssl keys - KOJI_PKI_DIR="/etc/pki/koji" ssh $QUIET root@$KOJI_BUILD_FQDN mkdir $KOJI_PKI_DIR scp $QUIET $KOJI_PKI_DIR/$KOJI_BUILD_FQDN.pem root@$KOJI_BUILD_FQDN:$KOJI_PKI_DIR/. scp $QUIET $KOJI_PKI_DIR/koji_ca_cert.crt root@$KOJI_BUILD_FQDN:$KOJI_PKI_DIR/. diff --git a/koji-setup/deploy-koji-builder.sh b/koji-setup/deploy-koji-builder.sh index 33387bd..6052a7e 100755 --- a/koji-setup/deploy-koji-builder.sh +++ b/koji-setup/deploy-koji-builder.sh @@ -7,6 +7,7 @@ SCRIPT_DIR="$(dirname "$(realpath "$0")")" source "$SCRIPT_DIR"/globals.sh source "$SCRIPT_DIR"/parameters.sh +KOJI_BUILD_FQDN="$(hostname -f)" # Install the koji builder componelts from epel dnf install -y epel-release dnf install -y koji-builder diff --git a/koji-setup/deploy-koji-nfs-server.sh b/koji-setup/deploy-koji-nfs-server.sh index 99e27a0..a51e253 100755 --- a/koji-setup/deploy-koji-nfs-server.sh +++ b/koji-setup/deploy-koji-nfs-server.sh @@ -7,6 +7,8 @@ SCRIPT_DIR="$(dirname "$(realpath "$0")")" source "$SCRIPT_DIR"/globals.sh source "$SCRIPT_DIR"/parameters.sh +KOJI_BUILD_FQDN=$1 + dnf install -y nfs-utils # Export server directory to be mounted by clients diff --git a/koji-setup/deploy-koji.sh b/koji-setup/deploy-koji.sh old mode 100755 new mode 100644 index 2d44fa2..deadaf3 --- a/koji-setup/deploy-koji.sh +++ b/koji-setup/deploy-koji.sh @@ -319,26 +319,6 @@ systemctl enable --now httpd sudo -u kojiadmin koji moshimoshi -## KOJI DAEMON - BUILDER -# Add the host entry for the koji builder to the database -sudo -u kojiadmin koji add-host "$KOJI_BUILD_FQDN" "$RPM_ARCH" - -# Add the host to the createrepo channel -sudo -u kojiadmin koji add-host-to-channel "$KOJI_BUILD_FQDN" createrepo - -# A note on capacity -sudo -u kojiadmin koji edit-host --capacity="$KOJID_CAPACITY" "$KOJI_BUILD_FQDN" - -# Generate certificates -pushd "$KOJI_PKI_DIR" -./gencert.sh "$KOJI_BUILD_FQDN" "/C=$COUNTRY_CODE/ST=$STATE/L=$LOCATION/O=$ORGANIZATION/CN=$KOJI_BUILD_FQDN" -popd - -if [[ "$KOJI_BUILD_FQDN" = "$KOJI_HUB_FQDN" ]]; then - "$SCRIPT_DIR"/deploy-koji-builder.sh -fi - - ## KOJIRA - DNF|YUM REPOSITORY CREATION AND MAINTENANCE # Add the user entry for the kojira user sudo -u kojiadmin koji add-user kojira diff --git a/koji-setup/parameters.sh b/koji-setup/parameters.sh index 0107af2..d425293 100644 --- a/koji-setup/parameters.sh +++ b/koji-setup/parameters.sh @@ -5,10 +5,6 @@ ## KOJI RPM BUILD AND TRACKER export KOJI_DIR=/mnt/koji export KOJI_HUB_FQDN="$(hostname -f)" -# Use master FQDN if a combined build and master server -#export KOJI_BUILD_FQDN="$KOJI_MASTER_FQDN" -# Build server FQDN if different from master -export KOJI_BUILD_FQDN="kojibuild1.koozali.org" export KOJI_URL=http://"$KOJI_HUB_FQDN" export KOJID_CAPACITY=16 export TAG_NAME=sme