#!/bin/sh

# A simple script to build VAST inside a Debian Buster Docker image and export
# the artifacts as tar.gz files.

set -x

VERSION=${1:-$(git describe)}

if ! DOCKER_BUILDKIT=1 docker build -t tenzir/vast:${VERSION} .; then
  echo Error building docker image
  exit 1
fi

# Tag the builder
BUILDER=$(docker images --filter "label=builder=true" --format '{{.CreatedAt}}\t{{.ID}}' | sort -nr | head -n 1 | cut -f2)
docker tag ${BUILDER} tenzir/vast:"builder-${VERSION}"

# Export the images to gzipped archives
docker save tenzir/vast:latest | gzip > vast-${VERSION}-docker.tar.gz
docker save tenzir/vast:builder | gzip > vast-builder-${VERSION}-docker.tar.gz
