aboutsummaryrefslogtreecommitdiff
path: root/tcwg-test-container-matrix.yaml
blob: b832fc22ae611d93479eef6e9d505845d25f4bf3 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
- 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-coordinator
    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"