
#!/bin/bash
git checkout $gitTag

repo=registry.hncy.info/hncy/cd-comprehensive-web
tag=${1:-$gitTag}
echo $tag

# init son modules
echo "init..."
git submodule init

# init regist-to-eureka son module
echo "init regist-to-eureka ..."
git submodule update --init regist-to-eureka

# check init regist-to-eureka
if [ ! -f regist-to-eureka/reg2eureka.sh ]; then
    echo "error:init regist-to-eureka fail"
    exit 1
fi

# init CooglMap son module
echo "init CooglMap ..."
git submodule update --init src/components/CooglMap || {
    echo "error:init CooglMap fail"

    if [ -d "src/components/CooglMap" ]; then
        echo "CooglMap Directory exists, try to reset..."
        cd src/components/CooglMap
        git fetch origin main
        git reset --hard origin/main
        cd ../../../
    else
        echo "CooglMap Directory not exist. try to clone..."
        mkdir -p src/components/CooglMap
        git clone ssh://git@171.217.92.33:2224/cityLevel/cooglMap.git src/components/CooglMap
    fi
}

echo "Clean up old builds..."
rm -rf dist

echo "start new builds..."
yarn
yarn build

#docker buildx build --platform linux/amd64 -t $repo:$tag . --push
docker buildx build --platform linux/arm64 -t $repo:$tag . --push
