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

var:
  ubuntu_version: 22.04.3

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 zstd

  export SOURCE_DATE_EPOCH='[% c("timestamp") %]'
  tar -xf [% c('input_files_by_name/mmdebstrap') %]
  ./mmdebstrap/mmdebstrap --mode=unshare [% c("var/container/mmdebstrap_opt") %] [% c("var/container/suite") %] output.tar.[% c('compress_tar') %] [% c("var/container/debian_mirror") %]

  [% IF c("var/minimal_apt_version") -%]
    mkdir base-image
    tar -C base-image -xf output.tar.[% c('compress_tar') %] ./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.[% c('compress_tar') %] [% dest_dir %]/[% c("filename") %]

targets:
  stretch-amd64:
    var:
      minimal_apt_version: 1.4.11
      container:
        suite: stretch
        arch: amd64
        debian_mirror: >
          "deb [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] http://archive.debian.org/debian-archive/debian/ stretch main"
          "deb [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] http://archive.debian.org/debian-archive/debian-security/ stretch/updates main"

  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

  bookworm-amd64:
    var:
      minimal_apt_version: 2.6.1
      container:
        suite: bookworm
        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: ad33b7ae47b75c92c2e2fe21fd4612e15357e67679d8751d6ce892a475be24fe
