# Large image, expressly to be able to do lava-server tests inside
# which needs lots of dependencies & space for postgresql.
# able to use lava packages from Debian buster for django1.11
# and python3.

# lava reports & can check the checksum of the compressed image
# after download.

- job:
    name: lava-debian-buster-amd64-vm
    project-type: freestyle
    defaults: global
    logrotate:
        daysToKeep: 14
        numToKeep: 5
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
            platform-leads:
                - job-build
                - job-cancel
    disabled: true
    node: docker-stretch-amd64
    display-name: 'DELETE ME'
    wrappers:
        - timestamps
    builders:
        - linaro-publish-token
        - shell: |
            #!/bin/bash

            set -ex

            export LANG=C

            echo "deb http://mirror.bytemark.co.uk/debian stretch-backports main" > stretch-backports.list
            sudo mv stretch-backports.list /etc/apt/sources.list.d/
            sudo apt-get update
            sudo apt-get install -y --no-install-recommends vmdebootstrap grub2-common

            mkdir out
            sudo vmdebootstrap \
              --verbose \
              --image=${WORKSPACE}/out/large-buster.img \
              --size=3G \
              --distribution=buster \
              --mirror=http://mirror.bytemark.co.uk/debian \
              --enable-dhcp \
              --systemd-networkd \
              --configure-apt \
              --grub \
              --serial-console \
              --log=${WORKSPACE}/out/vmdebootstrap.log \
              --log-level=debug \
              --log-mode=0644

            cat > ${WORKSPACE}/out/debian-buster-amd64-readme.html <<EOF
            <html><body><pre>
            lava-debian-buster-amd64-vm build instructions"
            ===============================================

            This image can be used for any tests on buster (django1.11 and
            later).

            The image uses a prompt of "root@debian:"
            </pre>
            <p><a href="https://ci.linaro.org/view/lava-ci/job/lava-debian-buster-amd64-vm/">
            https://ci.linaro.org/view/lava-ci/job/lava-debian-buster-amd64-vm/</a></p>

            <p><a href="https://ci.linaro.org/view/lava-ci/job/lava-debian-buster-amd64-vm/console">
            https://ci.linaro.org/view/lava-ci/job/lava-debian-buster-amd64-vm/console</a></p>

            <p><a href="https://git.linaro.org/ci/job/configs.git/blob/HEAD:/lava-debian-buster-amd64-vm.yaml">
            https://git.linaro.org/ci/job/configs.git/blob/HEAD:/lava-debian-buster-amd64-vm.yaml</a></p>

            <p><a href="http://snapshots.linaro.org/components/lava/standard/debian/buster/amd64/${BUILD_NUMBER}">
            http://snapshots.linaro.org/components/lava/standard/debian/buster/amd64/${BUILD_NUMBER}</a></p>


            <pre>
            The base system is a Debian Stretch VM with stretch-backports enabled.

            echo "deb http://mirror.bytemark.co.uk/debian stretch-backports main" > stretch-backports.list
            sudo mv stretch-backports.list /etc/apt/sources.list.d/
            sudo apt-get update
            sudo apt-get install -y --no-install-recommends -t stretch-backports vmdebootstrap grub2-common

            See vmdebootstrap.log for the full log.
            </pre></body></html>
            EOF

            gzip -9 ${WORKSPACE}/out/large-buster.img

            md5sum ${WORKSPACE}/out/large-buster.img.gz > ${WORKSPACE}/out/large-buster.img.gz.md5sum.txt
            sha256sum ${WORKSPACE}/out/large-buster.img.gz > ${WORKSPACE}/out/large-buster.img.gz.sha256sum.txt

            # echo final location
            echo Publishing to: http://snapshots.linaro.org/components/lava/standard/debian/buster/amd64/${BUILD_NUMBER}

            # 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 python3 ${HOME}/bin/linaro-cp.py --api_version 3 --link-latest out components/lava/standard/debian/buster/amd64/${BUILD_NUMBER}
    publishers:
        - email:
            recipients: 'neil.williams@linaro.org fathi.boudra@linaro.org'
