#!/usr/bin/env sh
set -eu

cd /workspace/hwlab-boot/repo

export HWLAB_SERVICE_ID="${HWLAB_SERVICE_ID:-hwlab-workbench-runtime}"
export HWLAB_ARTIFACT_KIND="${HWLAB_ARTIFACT_KIND:-go-service}"
export HWLAB_WORKBENCH_RUNTIME_PORT="${HWLAB_WORKBENCH_RUNTIME_PORT:-6671}"
export PORT="${PORT:-$HWLAB_WORKBENCH_RUNTIME_PORT}"
export GOMODCACHE="${GOMODCACHE:-/opt/hwlab-env/go/pkg/mod}"
export GOCACHE="${GOCACHE:-/opt/hwlab-env/go/cache}"
export GOPROXY="${GOPROXY:-https://goproxy.cn,direct}"
export GOTOOLCHAIN="${GOTOOLCHAIN:-local}"
export CGO_ENABLED="${CGO_ENABLED:-0}"

mkdir -p "$GOMODCACHE" "$GOCACHE" /tmp/hwlab-workbench-runtime
go build -trimpath -o /tmp/hwlab-workbench-runtime/hwlab-workbench-runtime ./cmd/hwlab-workbench-runtime
exec /tmp/hwlab-workbench-runtime/hwlab-workbench-runtime
