# vim: filetype=yaml sw=2
filename: 'container-image_[% c("var/container/suite") %]-[% c("var/container/arch") %]-[% c("version") %].tar.gz'
version: 1
pkg_type: build

var:
  ubuntu_version: 20.04.1

  container:
    use_container: 1

pre: |
  #!/bin/sh
  set -e
  rootdir=$(pwd)
  export DEBIAN_FRONTEND=noninteractive
  apt-get update -y -q
  apt-get install -y -q debian-archive-keyring ubuntu-keyring mmdebstrap gnupg patch

  export SOURCE_DATE_EPOCH='[% c("timestamp") %]'
  tar -xf [% c('input_files_by_name/mmdebstrap') %]
  # As a user namespace inside an other user namespace doesn't seem to work,
  # we patch mmdebstrap to avoid creating a new user namespace
  patch -d mmdebstrap -p1 < mmdebstrap-no-user-ns.patch
  ./mmdebstrap/mmdebstrap --mode=unshare [% c("var/container/mmdebstrap_opt") %] [% c("var/container/suite") %] output.tar.gz [% c("var/container/debian_mirror") %]

  [% IF c("var/minimal_apt_version") -%]
    mkdir base-image
    tar -C base-image -xf output.tar.gz ./var/lib/dpkg
    apt_version=$(dpkg --admindir=$rootdir/base-image/var/lib/dpkg -s apt | grep '^Version: ' | cut -d ' ' -f 2)
    echo "apt version: $apt_version"
    dpkg --compare-versions "$apt_version" ge '[% c("var/minimal_apt_version") %]'
  [% END -%]

  mv output.tar.gz [% dest_dir %]/[% c("filename") %]

targets:
  jessie-amd64:
    var:
      minimal_apt_version: 1.0.9.8.6

      container:
        suite: jessie
        arch: amd64

  buster-amd64:
    var:
      minimal_apt_version: 1.8.2
      container:
        suite: buster
        arch: amd64

  bullseye-amd64:
    var:
      minimal_apt_version: 2.2.4
      container:
        suite: bullseye
        arch: amd64

input_files:
  - project: mmdebstrap
    name: mmdebstrap
  - URL: 'https://cdimage.ubuntu.com/ubuntu-base/releases/[% c("var/ubuntu_version") %]/release/ubuntu-base-[% c("var/ubuntu_version") %]-base-amd64.tar.gz'
    filename: 'container-image_ubuntu-base-[% c("var/ubuntu_version") %]-base-amd64.tar.gz'
    sha256sum: 97f6cbcf41f39272c84e32b6f926ed5d6906c6e463a557025181f4aa191ad667
  - filename: mmdebstrap-no-user-ns.patch
