Builder Setup – Fedora 17 v6 buildroot

Setting up a v6 buildroot
First create the certificates using the certs-gen.sh script which is located on Japan:

cd /etc/pki/koji/
./certs-gen.sh [hostname]

You then press enter for all the confirming options UNTIL you it asks if you’d like to commit, press y and press y again.

Add the host to koji

su - kojiadmin
koji -s 'http://japan.proxiomity.on.ca/kojihub' add-host [hostname] armv6hl armhfp noarch

If the host is a heavy builder then you need to add it to the heavy builder channel:

koji -s 'http://japan.proxiomity.on.ca/kojihub' add-channel [hostname] heavybuilder

Setup of the builder:
– Make sure that it has the proper autthorized_keys file inside the /root/.ssh/ folder.

I have now create a script to automate the rest of the builder install process, though the initial setup of the script takes a moment.

Initial Setup:
Due to a slightly complicated network setup, the builders are hosted on a private network on hongkong and the certificates are generated and stored on another computer japan, the script does a little ssh jumping around. Because of this setup, japan requires ssh access to a hongkong account that has access to the builders… So allow the kojiadmin account on japan to ssh with a password to an account on hongkong(User: builder). Then make sure the new user on hongkong has access to all the builders. Finally copy the v6 buildroot into the hongkong users directory(v6.tgz).

Script(The script is a little hacky and will be replace by some management system like bcfg2/ansible):

#!/bin/bash
# ssh from japan to hongkong and install f17v6 buildroots on hosts

hosts="$1"
user="kojiadmin"
pemdir="/etc/pki/koji"

if [ "$USER" != "$user" ]; then
        echo "Wrong user: Please use $user"
fi

if [[ "$1" == "" || "$1" == "-h" ]]; then
cat <<+ 

        Usage: ./install-f17v6 [option/hostname]
        example: ./install-f17v6 --all
        example: ./install-f17v6 --check "cu-15-1"
        example: ./install-f17v6 --check "cu-15-1 cu-15-2"
        example: ./install-f17v6 --fix "cu-15-1"
        example: ./install-f17v6 --fix "cu-15-1 cu-15-2"
        example: ./install-f17v6 "cu-15-1"
        example: ./install-f17v6 "cu-15-1 cu-15-2"
        Options:
        [no-options] will copy and install a new rootfs along with koji certs and starts koji service.
        --all   - Reinstall rootfs on all builders. Takes forever.
        --check - Only checks if builder is network capable and online.
        --fix   - Does not copy new rootfs, but copies koji certs and starts koji service

+
        exit
elif [ "$1" = "--all" ]; then
        hosts="$(koji -q -s 'http://japan.proximity.on.ca/kojihub' list-hosts | awk '{OFS=":";print $1,$5}')"
elif [ "$1" = "--check" ]; then
        if [ "$2" == "" ];then
                hosts="$(koji -q -s 'http://japan.proximity.on.ca/kojihub' list-hosts | awk '{OFS=":";print $1}')"
        else   
                hosts="$2"
        fi
elif [ "$1" = "--fix" ]; then
        hosts="$2"
else   
        hosts="$1"
fi

# Copies the v6 buildroot
function copybuildroot {
        echo -n "Making buildroot:      "
        ssh builder@hongkong "ssh root@$host 'mkdir ~/f17v6/ 2> /dev/null; echo \"- ready\"'"
        echo -n "Copying buildroot:     "
        ssh builder@hongkong "scp ~/v6.tgz root@$host:~/f17v6/; echo \"- ready\""
        echo -n "Extracting buildroot:  "
        ssh builder@hongkong "ssh root@$host 'cd ~/f17v6; tar -xzf v6.tgz 2> /dev/null; rm ~/f17v6/v6.tgz; echo \"- ready\"'"
}

# Copies certs and mounts binds /dev /proc /sys
function fixbuilders {
        echo -n "Copying $host.pem:     "
        scp -q $pemdir/$host.pem builder@hongkong:
        ssh builder@hongkong "scp ~/$host.pem root@$host:~/f17v6/etc/kojid/kojid.pem; echo \"- ready\""
        echo -n "Unmounting buildroot:  "
        ssh builder@hongkong "ssh root@$host 'umount ~/f17v6/dev/ 2> /dev/null; umount ~/f17v6/sys/ 2> /dev/null; umount ~/f17v6/proc/ 2> /dev/null; echo \"- ready\"'"
        echo -n "Binding buildroot:     "
        ssh builder@hongkong "ssh root@$host 'mount -o bind /dev/ ~/f17v6/dev/; mount -o bind /sys/ ~/f17v6/sys/; mount -o bind /proc/ ~/f17v6/proc/; echo \"- ready\"'"
        echo -n "Copying koji-start:    "
        scp -q "$pemdir/koji-start" builder@hongkong:; echo "- ready"
        ssh builder@hongkong "scp -q ~/koji-start root@$host:~/f17v6/"
}

# Used only on builders that require build space separated from their sd cards
function mountnfs {
        echo -n "Mounting fs0:          "
        ssh builder@hongkong "ssh root@$host 'mkdir ~/f17v6/fs0 2> /dev/null; umount ~/f17v6/fs0 2> /dev/null; mount /hkexport/fs0.ext4 ~/f17v6/fs0 2> /dev/null; echo \"- ready\"'"
        echo -n "Creating links:                "
        ssh builder@hongkong "ssh root@$host 'rm -rf ~/f17v6/var/lib/mock; ln -s /fs0/mock/lib/mock /root/f17v6/var/lib/mock 2> /dev/null'"
        ssh builder@hongkong "ssh root@$host 'rm -rf ~/f17v6/var/cache/mock; ln -s /fs0/mock/cache/mock /root/f17v6/var/cache/mock 2> /dev/null; echo \"- ready\"'"
}

# Start!
for item in $hosts; do
        host="$(echo $item | cut -d':' -f1)"
        arch="$(echo $item | cut -d':' -f2)"
        group="$(echo $item | cut -c 1-2)"
        # Check if the builder is a arm builder or not
        if [[ "$arch" != "fake" && "$1" != "--check"  ]]; then
                echo -n "[$host]:               "
                # Check if the koji pem file exists
                if [ ! -f "$pemdir/$host.pem" ]; then
                        echo " - file not found: $pemdir/$host.pem"
                        echo "Run script as root: - $pemdir/certs-gen.sh $host"
                        exit
                fi
                # Add host to known hosts
                ssh -o StrictHostKeyChecking=no builder@hongkong "ssh -o StrictHostKeyChecking=no root@$host 'echo \"- ready\" '"
                if [ "$1" != "--fix" ]; then
                        copybuildroot
                fi
                fixbuilders
                if [[ "$group" == "pa" || "$group" == "st" ]]; then
                        mountnfs
                fi
                # Start koji inside the chroot by running the koji-start script
                ssh builder@hongkong "ssh root@$host 'chmod 755 ~/f17v6/koji-start; chroot ~/f17v6 /koji-start 2> /dev/null'"
        elif [ "$1" == "--check" ]; then
                host="$(echo $item | cut -d':' -f1)"
                arch="$(echo $item | cut -d':' -f2)"
                group="$(echo $item | cut -c 1-2)"
                echo -n "-> $host:"
                ssh -o StrictHostKeyChecking=no builder@hongkong "ssh -o StrictHostKeyChecking=no root@$host 'echo \" - ready\" '"
        fi
done
Advertisements

About oatleywillisa

Computer Networking Student
This entry was posted in SBR600 and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s