#!/bin/bash

set -e

if [[ -z "$1" ]]; then
  echo "Error: requires region to start" >&2
  echo "" >&2
  echo "Usage $0 <region>" >&2
  echo "    region: china or global." >&2
  exit 1
fi

if [[ ! -f ".env.production.$1.runtime" ]]; then
    echo "Error: environment file .env.production.$1 not found" >&2
  exit 1
fi

docker build . \
  --tag "${IMAGE_PREFIX}/tidb-labs-$1-frontend:latest" \
  --platform linux/amd64 \
  --build-arg LABS_FRONTEND_VERSION=latest \
  --build-arg LABS_FRONTEND_REGION="$1" \
  --secret "id=env-$1,src=.env.production.$1"
