type: container

container:
  containerfile: |
    FROM docker.io/i386/ubuntu:bionic

    # https://stackoverflow.com/questions/25193161/chfn-pam-system-error-intermittently-in-docker-hub-builds/25267015
    RUN ln -s -f /bin/true /usr/bin/chfn

    RUN linux32 apt-get update && linux32 apt-get install -y python-dev systemd sudo git
    RUN useradd --create-home pcpbuild
    RUN echo 'pcpbuild ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/pcpbuild

    # allow services to be started during installation
    # pmcd will create the file /var/lib/pcp/pmns/stdpmid, which is required by QA tests
    RUN printf '#!/bin/sh\nexit 0\n' > /usr/sbin/policy-rc.d

    CMD ["/bin/systemd"]

tasks:
  setup: |
    sudo linux32 apt-get -y update
    pkgs=$(linux32 qa/admin/list-packages -m -v -x cpan -x pip3 -x not4ci)
    sudo DEBIAN_FRONTEND=noninteractive linux32 apt-get install -y $pkgs
  build: |
    linux32 ./Makepkgs --nonrpm --verbose
    linux32 dpkg -I build/deb/pcp_*.deb | grep Depends | grep -q libuv1
  copy_build_artifacts: |
    cp build/deb/*.deb ../artifacts/build
  install: |
    sudo linux32 dpkg -i build/deb/*.deb
    echo 'pcpqa ALL=(ALL) NOPASSWD: ALL' | sudo tee /etc/sudoers.d/pcpqa
  init_qa: |
    sudo -i -u pcpqa linux32 ./check 002
  qa_sanity: |
    set -o pipefail
    sudo -i -u pcpqa linux32 ./check -TT -g sanity -x not_in_ci -x not_in_container |& tee ../artifacts/test/test.log
  qa: |
    set -o pipefail
    DEFAULT_PCP_QA_ARGS="-x x11 -x remote -x not_in_ci -x not_in_container"
    sudo -i -u pcpqa ./check -CI -TT ${PCP_QA_ARGS:-${DEFAULT_PCP_QA_ARGS}} |& tee ../artifacts/test/test.log
  copy_test_artifacts: |
    cp /var/lib/pcp/testsuite/check.timings ../artifacts/test
    # add current timestamp if the last QA test got stuck
    [ $(awk 'END{print NF}' ../artifacts/test/check.timings) = 2 ] && date '+%s' >> ../artifacts/test/check.timings
    shopt -s nullglob
    for test in /var/lib/pcp/testsuite/*.out.bad; do cp $test ../artifacts/test; [ -f ${test/.out.bad/.full} ] && cp ${test/.out.bad/.full} ../artifacts/test; done
    [ -x /var/lib/pcp/testsuite/admin/whatami ] && /var/lib/pcp/testsuite/admin/whatami >../artifacts/test/whatami
