#!/bin/ash
set -e

# linter
# TODO: Replace develop/sim with the base branch of PR
MERGE_BASE=$(git merge-base HEAD origin/develop/sim)
git diff --relative --name-only HEAD ${MERGE_BASE} | xargs ls -dp 2>/dev/null | grep -v /$ | xargs git-lint $1

set -o pipefail


export DOCKER_HOST=unix:///var/run/ci_docker.sock
export TESTCONTAINERS_RYUK_DISABLED=true
# metrics sub modules
# metrics-reader-service
./gradlew --no-daemon :metrics:metrics-reader-service:clean :metrics:metrics-reader-service:build
docker build ./metrics/metrics-reader-service -f metrics.Dockerfile --build-arg project=metrics-reader-service

# restapi
# build gitinfo file that can be later copied by Dockerfile
echo "Generating gitinfo"
./gradlew --no-daemon -Dorg.gradle.jvmargs="-Xmx1g" :restapi:build -Pgitinfo -x test
docker build .
# for kafka sub modules, set PATH to be driving/sim (i.e ../../)
# databricks-scheduler-consumer
docker build ../../ -f kafka.Dockerfile --build-arg project=databricks-scheduler-consumer
# echo-sim-results-consumer
docker build ../../ -f kafka.Dockerfile --build-arg project=echo-sim-results-consumer
# run-summaries-consumer
docker build ../../ -f kafka.Dockerfile --build-arg project=run-summaries-consumer
