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

cd /workspace/hwlab-boot/repo

export HWLAB_SERVICE_ID="${HWLAB_SERVICE_ID:-hwlab-user-billing}"
export HWLAB_ARTIFACT_KIND="${HWLAB_ARTIFACT_KIND:-go-service}"
export HWLAB_USER_BILLING_PORT="${HWLAB_USER_BILLING_PORT:-6670}"
export PORT="${PORT:-$HWLAB_USER_BILLING_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-user-billing
go build -trimpath -o /tmp/hwlab-user-billing/hwlab-user-billing ./cmd/hwlab-user-billing
exec /tmp/hwlab-user-billing/hwlab-user-billing
