#!/bin/sh -eu

: "${DOCKER_BIN:=docker}"
: "${UNWIND_PORT:=8097}"

cd "$RUN_DIR"

[ -z "${DEBUG:-}" ] || set -x

version=$(cat build/version)

localhost=127.0.0.1
localport=8000
netloc="$localhost:$localport"

echo >&2 "Unwind will be available on http://$netloc/
"

$DOCKER_BIN run \
    --init \
    -it --rm \
    --read-only \
    --memory '500m' \
    --publish "$netloc":"$UNWIND_PORT" \
    --volume "$RUN_DIR"/data:/data \
    "code.dumpr.org/ducklet/unwind":"$version"
