#!/usr/bin/env bash

set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly ROOT
readonly IMAGE="hugo-chiri-ai-02"
readonly RESULTS="${ROOT}/results"

cd "${ROOT}"
docker build --tag "${IMAGE}" .
if [[ "${RESULTS}" != "${ROOT}/results" ]]; then
  echo "refusing to clear an unexpected results directory" >&2
  exit 65
fi
rm -rf "${RESULTS}"
mkdir -p "${RESULTS}"

run_isolated() {
  docker run --rm \
    --cpus=2 \
    --memory=512m \
    --network=none \
    --volume "${RESULTS}:/experiment/results" \
    "${IMAGE}" "$@"
}

run_isolated php experiment.php
run_isolated php analyze.php

docker run --rm \
  --cpus=2 \
  --memory=512m \
  --volume "${RESULTS}:/experiment/results" \
  "${IMAGE}" php source-evidence.php

run_isolated php assemble.php
run_isolated php mutate.php
run_isolated php profile.php
run_isolated php source-manifest.php
run_isolated php verify-results.php
