# 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
container:
  use_container: 1

var:
  ubuntu_version: 22.04

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

  export SOURCE_DATE_EPOCH='[% c("timestamp") %]'
  tar -xf [% c('input_files_by_name/mmdebstrap') %]
  ./mmdebstrap/mmdebstrap --mode=unshare --arch=[% c("var/container/arch") %] [% 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
        debian_mirror: >
          "deb [signed-by=/usr/share/keyrings/debian-archive-removed-keys.gpg] http://deb.debian.org/debian jessie main"
          "deb [signed-by=/usr/share/keyrings/debian-archive-removed-keys.gpg] http://deb.debian.org/debian jessie-updates main"
          "deb [signed-by=/usr/share/keyrings/debian-archive-removed-keys.gpg] http://security.debian.org/debian-security jessie/updates main"

  jessie-armhf:
    var:
      minimal_apt_version: 1.0.9.8.6

      container:
        suite: jessie
        arch: armhf
        debian_mirror: >
          "deb [signed-by=/usr/share/keyrings/debian-archive-removed-keys.gpg] http://deb.debian.org/debian jessie main"
          "deb [signed-by=/usr/share/keyrings/debian-archive-removed-keys.gpg] http://deb.debian.org/debian jessie-updates main"
          "deb [signed-by=/usr/share/keyrings/debian-archive-removed-keys.gpg] http://security.debian.org/debian-security jessie/updates main"

  stretch-arm64:
    var:
      minimal_apt_version: 1.4.9
      container:
        suite: stretch
        arch: arm64

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

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

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: df6fe77cee11bd216ac532f0ee082bdc4da3c0cc1f1d9cb20f3f743196bc4b07
    enable: '[% c("buildconf/deb_native_arch") == "amd64" %]'
  - URL: 'https://cdimage.ubuntu.com/ubuntu-base/releases/[% c("var/ubuntu_version") %]/release/ubuntu-base-[% c("var/ubuntu_version") %]-base-arm64.tar.gz'
    filename: 'container-image_ubuntu-base-[% c("var/ubuntu_version") %]-base-arm64.tar.gz'
    sha256sum: 6dd67ec02fdc64b5bba4125066462d01e66a2ae14c4c9e571541fba617d7e721
    enable: '[% c("buildconf/deb_native_arch") == "arm64" %]'
