# vim: filetype=yaml sw=2
filename: 'container-image_[% c("var/container/suite") %]-[% c("var/container/arch") %]-[% sha256(c("pre")).substr(0, 12) %].tar.[% c("compress_tar") %]'
pkg_type: build
container:
  use_container: 1

var:
  container:
    suite: '[% pc(c("origin_project"), "var/container/suite", { step => c("origin_step") }) %]'
    arch: '[% pc(c("origin_project"), "var/container/arch", { step => c("origin_step") }) %]'

lsb_release:
  id: Debian
  codename: stretch
  release: 9.13

targets:
  no_containers:
    filename: containers_disabled
    pre: ''
    input_files: []
    build: |
      mkdir -p [% dest_dir %]
      touch [% dest_dir _ '/' _ c('filename') %]

pre: |
  #!/bin/sh
  # Version: 2
  # [% c('var/container/suite') %]
  set -e
  export DEBIAN_FRONTEND=noninteractive
  # Update the package cache so the container installs the most recent
  # version of required packages.
  apt-get update -y -q
  [% IF pc(c('origin_project'), 'var/pre_pkginst', { step => c('origin_step') }) -%]
    [% pc(c('origin_project'), 'var/pre_pkginst', { step => c('origin_step') }) %]
    [% IF c("var/linux-cross") && ! pc(c('origin_project'), 'var/no_crosscompile', { step => c('origin_step') }) -%]
      dpkg --add-architecture [% c("var/arch_debian") %]
    [% END -%]
    # Update the package cache again because `pre_pkginst` may change the
    # package manager configuration.
    apt-get update -y -q
  [% END -%]
  apt-get upgrade -y -q
  [%
     deps = [];
     IF pc(c('origin_project'), 'var/essential_deps', { step => c('origin_step') });
       CALL deps.import(pc(c('origin_project'), 'var/essential_deps', { step => c('origin_step') }));
     END;
     IF pc(c('origin_project'), 'var/deps', { step => c('origin_step') });
       CALL deps.import(pc(c('origin_project'), 'var/deps', { step => c('origin_step') }));
     END;
     IF pc(c('origin_project'), 'var/arch_deps', { step => c('origin_step') });
       CALL deps.import(pc(c('origin_project'), 'var/arch_deps', { step => c('origin_step') }));
     END;
     res_deps = [];
     FOREACH pkg IN deps;
       SET res_pkg = tmpl(pkg);
       IF res_pkg;
         res_deps.push(res_pkg);
       END;
     END;
     IF pc(c('origin_project'), 'var/sort_deps', { step => c('origin_step') });
       res_deps = res_deps.sort.unique;
     END;
     IF res_deps.size;
       SET no_install_recommends = pc(c('origin_project'), 'var/no_install_recommends', { step => c('origin_step') });
       FOREACH pkg IN res_deps;
         GET c('install_package', { pkg_name => pkg, no_install_recommends => no_install_recommends });
         GET "\n";
       END;
     END;
  -%]
  [% IF pc(c('origin_project'), 'var/post_pkginst', { step => c('origin_step') }) -%]
  [% pc(c('origin_project'), 'var/post_pkginst', { step => c('origin_step') }) %]
  [% END -%]
  apt-get clean

remote_get: |
  #!/bin/sh
  set -e
  [%
    SET src = shell_quote(c('get_src', { error_if_undef => 1 }));
    SET dst = shell_quote(c('get_dst', { error_if_undef => 1 }));
  -%]
  mkdir -p "[% dst %]"
  [% c("rbmdir") %]/container archive '[% c("container/dir") %]' "[% dst %]/[% c("filename") %]"

input_files:
  - project: mmdebstrap-image
    target:
      - '[% c("var/container/suite") %]-[% c("var/container/arch") %]'
