aboutsummaryrefslogtreecommitdiff
path: root/tcwg-abe-test-container.yaml
blob: 160a437c8c7c60971b739c8fc87f3cad65742cac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
- job:
    name: tcwg-abe-test-container
    project-type: freestyle
    defaults: global
    logrotate:
        daysToKeep: 30
        numToKeep: 30
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
            linaro:
                - job-build
                - job-cancel
    parameters:
        - 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:/tmp/my-abe-test-container.param.  Location must be writable by tcwg-buildslave.'
    disabled: false
    node: docker-trusty-i386-tcwg
    concurrent: true
    display-name: 'TCWG ZZZ ABE Test Container'
    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 $container_user

              sudo rsync -a ~/.ssh/ /home/$container_user/.ssh/
              sudo chown -R $container_user /home/$container_user/.ssh/
            fi

            sudo touch /keep-container
            sudo chmod 0777 /keep-container
            echo "1" > /keep-container

            docker_host="$(echo $DOCKER_HOST | sed -e "s#^tcp://\(.*\):.*#\1#")"
            docker_host="$(echo $docker_host | sed -e "s/-x86//")"
            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_file="$(echo "$upstream_dest" | cut -d: -f 2)"
              echo "$container_user@$docker_host:$ssh_port" | ssh $upstream_machine tee $upstream_file > /dev/null
            fi

            set +x
            echo "Testing container: $container_user@$docker_host:$ssh_port"
            echo "To stop container run: ssh -o Port=$ssh_port $container_user@$docker_host sh -c 'echo 0 > /keep_container'"

            echo "Hosting tests"
            while [ -e /keep-container ] && [ x"$(cat /keep-container)" = x"1" ]; do
              sleep 60
              echo "Running processes: $(ps ax | wc -l)"
            done
            echo "Exiting"