aboutsummaryrefslogtreecommitdiff
path: root/leg-cloud-image-debian.yaml
blob: fe8b740fe05d1a8a6f131a88bd094f9e7c0e2262 (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
- job:
    name: leg-cloud-image-debian
    project-type: freestyle
    defaults: global
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
            linaro:
                - job-read
                - job-extended-read
                - job-build
                - job-cancel
        - build-discarder:
            days-to-keep: 30
            num-to-keep: 30
    disabled: false
    node: docker-centos7-aarch64
    display-name: 'LEG Cloud image Debian'
    wrappers:
        - timestamps
    builders:
        - linaro-publish-token:
            host: builds.96boards.org
        - shell: |
            #!/bin/bash

            export image_name=debian-cloud-image

            set -ex

            trap cleanup_exit INT TERM EXIT

            cleanup_exit()
            {
              cd ${WORKSPACE}
              sudo virsh destroy ${image_name} || true
              sudo virsh undefine ${image_name} || true
              sudo rm -f /var/lib/libvirt/images/${image_name}.qcow2 ${image_name}.qcow2
              rm -rf out
            }

            sudo yum install -y qemu-img virt-install libguestfs-tools-c

            sudo virsh pool-list --all
            sudo virsh net-list --all

            cat > preseed.cfg << EOF
                d-i debian-installer/locale string en_US.UTF-8
                d-i localechooser/supported-locales multiselect en_US.UTF-8, en_GB.UTF-8
                d-i keyboard-configuration/xkb-keymap select us
                d-i netcfg/choose_interface select auto
                d-i netcfg/get_hostname string unassigned-hostname
                d-i netcfg/get_domain string unassigned-domain
                d-i netcfg/wireless_wep string
                d-i mirror/country string manual
                d-i mirror/http/hostname string ftp.debian.org
                d-i mirror/http/directory string /debian
                d-i mirror/http/proxy string
                d-i passwd/root-login boolean false
                d-i passwd/user-fullname string Debian User
                d-i passwd/username string debian
                d-i passwd/user-password password insecure
                d-i passwd/user-password-again password insecure
                d-i clock-setup/utc boolean true
                d-i time/zone string UTC
                d-i clock-setup/ntp boolean true
                d-i partman-auto/method string regular
                d-i partman-lvm/device_remove_lvm boolean true
                d-i partman-md/device_remove_md boolean true
                d-i partman-lvm/confirm boolean true
                d-i partman-lvm/confirm_nooverwrite boolean true
                d-i partman-auto/choose_recipe select atomic
                d-i partman-partitioning/confirm_write_new_label boolean true
                d-i partman/choose_partition select finish
                d-i partman/confirm boolean true
                d-i partman/confirm_nooverwrite boolean true
                d-i partman-md/confirm boolean true
                d-i partman-partitioning/confirm_write_new_label boolean true
                d-i partman/choose_partition select finish
                d-i partman/confirm boolean true
                d-i partman/confirm_nooverwrite boolean true
                d-i apt-setup/services-select multiselect security, updates, backports
                d-i apt-setup/local0/repository string http://repo.linaro.org/ubuntu/linaro-overlay jessie main
                d-i apt-setup/local0/comment string Linaro Overlay
                d-i apt-setup/local0/source boolean true
                d-i apt-setup/local0/key string http://repo.linaro.org/ubuntu/linarorepo.key
                d-i pkgsel/upgrade select full-upgrade
                tasksel tasksel/first multiselect standard
                d-i pkgsel/include string openssh-server cloud-init cloud-utils/jessie-backports cloud-initramfs-growroot linux-image-reference-arm64
                popularity-contest popularity-contest/participate boolean false
                d-i grub-installer/only_debian boolean true
                d-i grub-installer/with_other_os boolean true
                d-i grub-installer/bootdev  string default
                d-i finish-install/reboot_in_progress note
                d-i preseed/late_command string \
                    mkdir -p /target/boot/efi/EFI/BOOT ; \
                    cp /target/boot/efi/EFI/debian/grubaa64.efi /target/boot/efi/EFI/BOOT/BOOTAA64.EFI
            EOF

            sudo virt-install \
              --name ${image_name} \
              --initrd-inject preseed.cfg \
              --extra-args "interface=auto noshell auto=true DEBIAN_FRONTEND=text" \
              --disk=pool=default,size=10,format=qcow2,bus=virtio \
              --memory 2048 \
              --location http://ftp.debian.org/debian/dists/stable/main/installer-arm64/ \
              --noreboot

            set +ex
            while [ true ]; do
              sleep 1
              vm_running=$(sudo virsh list --name --state-running | grep "^${image_name}" | wc -l)
              [ "${vm_running}" -eq "0" ] && break
            done
            set -ex

            sudo virsh list --all
            sudo virsh pool-list --all
            sudo virsh net-list --all

            mkdir out
            mv preseed.cfg out/debian-jessie-arm64-preseed.cfg
            sudo cp -a /var/lib/libvirt/images/${image_name}.qcow2 .
            sudo qemu-img convert -c -O qcow2 ${image_name}.qcow2 out/${image_name}.qcow2
            # extract kernel and initramfs from image
            # --unversioned-names may be handy to get vmlinuz/initrd.img names if needed
            sudo LIBGUESTFS_BACKEND=direct virt-copy-out -a ${image_name}.qcow2 /boot/ .
            sudo cp -a boot/*-arm64 out/
            sudo chown -R buildslave:buildslave out

            # Publish
            test -d ${HOME}/bin || mkdir ${HOME}/bin
            wget -q https://git.linaro.org/ci/publishing-api.git/blob_plain/HEAD:/linaro-cp.py -O ${HOME}/bin/linaro-cp.py
            time python ${HOME}/bin/linaro-cp.py \
              --server ${PUBLISH_SERVER} \
              --link-latest \
              out snapshots/developer-cloud/debian/cloud-image/${BUILD_NUMBER}
    publishers:
        - email:
            recipients: 'fathi.boudra@linaro.org marcin.juszkiewicz@linaro.org'