- job: name: tcwg-test-container-matrix project-type: matrix defaults: global properties: - authorization: anonymous: - job-read - job-extended-read linaro: - job-build - job-cancel - build-discarder: days-to-keep: 30 num-to-keep: 30 parameters: - string: name: container_name default: docker-trusty-arm64-tcwg-test description: 'Container name' - string: name: container_user default: tcwg-buildslave description: 'Non-root user inside container' - string: name: public_key default: '' description: 'SSH public key. Leave empty to not install additional public keys or use "ldap" to fetch from LDAP' - string: name: upstream_dest default: '' description: 'SSH destination to write connection parameters to, e.g., dev-01.tcwglab:22:/tmp/my-abe-test-container.param.' - string: name: watchdog default: exit description: 'Watchdog to determine when to stop testing container: exit, file or upstream' disabled: false node: tcwg-apm_64-test child-workspace: $label concurrent: true display-name: 'TCWG BBB Test Container' axes: - axis: type: slave name: label values: - docker-trusty-arm64-tcwg-test-tx1 - docker-trusty-armhf-tcwg-test-tx1 - docker-trusty-arm64-tcwg-build-tx1 - docker-trusty-arm64-tcwg-build-tx1-01 - docker-trusty-arm64-tcwg-build-tx1-02 - docker-trusty-armhf-tcwg-build-tx1 - docker-trusty-armhf-tcwg-build-tx1-01 - docker-trusty-armhf-tcwg-build-tx1-02 - docker-trusty-arm64-tcwg-test - docker-trusty-armhf-tcwg-test - docker-trusty-arm64-tcwg-build - docker-trusty-armhf-tcwg-build - docker-trusty-amd64-tcwg-build - docker-trusty-i386-tcwg-build execution-strategy: sequential: false combination-filter: | label=="$container_name" wrappers: - timeout: timeout: 600 - timestamps - ssh-agent-credentials: # tcwg-buildslave user id users: - 'e0958a95-204f-4c14-a66c-5e2be6c5d50a' - build-name: name: '#${BUILD_NUMBER}' builders: - shell: | #!/bin/bash set -ex if [ x"$public_key" = x"ldap" ]; then public_key="$(ssh -o StrictHostKeyChecking=no aus-colo.linaro.org /etc/ssh/ssh_keys.py $container_user)" fi if [ x"$public_key" != x"" ]; then echo "" >> ~/.ssh/authorized_keys || true echo "$public_key" >> ~/.ssh/authorized_keys || true fi if ! getent passwd $container_user; then container_user_data="$(ssh -o StrictHostKeyChecking=no aus-colo.linaro.org getent passwd $container_user)" container_user_uid="$(echo "$container_user_data" | cut -d: -f 3)" if [ x"$container_user_uid" != x"" ]; then container_user_uid_opt="-u $container_user_uid" fi sudo useradd -m $container_user_uid_opt -s /bin/bash $container_user sudo rsync -a ~/.ssh/ /home/$container_user/.ssh/ sudo chown -R $container_user /home/$container_user/.ssh/ fi docker_host="$(echo $DOCKER_HOST | sed -e "s#^tcp://\(.*\):.*#\1#")" ssh_port="$(ssh $docker_host docker port $DOCKER_CONTAINER_ID 22)" ssh_port="$(echo $ssh_port | cut -d: -f 2)" if [ x"$upstream_dest" != x"" ]; then upstream_machine="$(echo "$upstream_dest" | cut -d: -f 1)" upstream_port="$(echo "$upstream_dest" | cut -d: -f 2)" upstream_file="$(echo "$upstream_dest" | cut -d: -f 3)" echo "$container_user@$docker_host:$ssh_port" | ssh -o Port=$upstream_port $upstream_machine tee $upstream_file ssh -v -o Port=$upstream_port $upstream_machine ls -l $upstream_file fi if [ x"$container_user" != x"$USER" ]; then # If the job is started with a custom $container_user, # (not tcwg-buildslave), then we assume that this job is for # a developer to investigate a problem. Make sure we save # the data volumes if this container is killed on the job # timeout. backup_container_image="$(ssh $docker_host docker commit --pause=false $DOCKER_CONTAINER_ID)" backup_container_name="$container_user-$BUILD_ID" ssh $docker_host docker create --name $backup_container_name --volumes-from $DOCKER_CONTAINER_ID -P $backup_container_image set +x echo "NOTE: To restart a copy of this container from TCWG Lab: ssh $docker_host sudo -u $USER docker start $backup_container_name" echo "NOTE: then get container ssh port: port=\$(ssh $docker_host sudo -u $USER docker port $backup_container_name 22 | cut -d: -f 2)" echo "NOTE: then (to get sudo-enabled shell): ssh -p\$port -t $USER@$docker_host /bin/bash" echo "NOTE: or (to get no-sudo shell): ssh -p\$port $container_user@$docker_host" echo "NOTE: to stop the backup container: ssh -p\$port $USER@$docker_host sudo kill 1" set -x fi set +x echo "Testing container: $container_user@$docker_host:$ssh_port" echo "Hosting tests" set -x case "$watchdog" in "exit") ;; "file") sudo touch /keep-container sudo chmod 0777 /keep-container echo "1" > /keep-container echo "To stop container run: ssh -o Port=$ssh_port $container_user@$docker_host sh -c 'echo 0 > /keep-container'" while [ -e /keep-container ] && [ x"$(cat /keep-container)" = x"1" ]; do sleep 60 echo "Running processes: $(ps ax | wc -l)" done ;; "upstream") echo "To stop container remove $upstream_dest" retry=3 while [ $retry -gt 0 ]; do while ssh -o Port=$upstream_port $upstream_machine test -e $upstream_file; do retry=3 sleep 60 echo "Running processes: $(ps ax | wc -l)" done retry=$(($retry-1)) echo "Retrying check: $retry" sleep 10 done ;; *) echo "ERROR: Wrong watchdog parameter: $watchdog" ;; esac echo "Exiting"