#!/bin/bash set -e project_dir=$(pwd) version='1.0.1' env='dev' image_name='ai-flow-py' registry='registry.cn-shenzhen.aliyuncs.com/bantbox' REMOTE_DEV="root@192.168.0.155" REMOTE_TEST="root@34.146.228.227" REMOTE_PRO="root@34.146.222.45" usage() { echo -e "\n" echo -e "Usage: \n\t$0 [-e env] [-v version] [-h]\n" echo -e "[-h]: Show usage\n" echo -e "[-e] Env: Build env. (dev/test/pro)" echo -e "[-v] Version: Version of build.\n" } login() { echo "[+] Logging in to Docker registry..." docker login --username=arche@1030463161912241 --password=bantbox@2021 registry.cn-shenzhen.aliyuncs.com } build() { local full_tag="${registry}/${image_name}:${version}-${env}" echo "[+] ================================" echo "[+] Start building..." echo "[+] Image: ${image_name}" echo "[+] Version: ${version}" echo "[+] Env: ${env}" echo "[+] Tag: ${full_tag}" echo "[+] ================================" echo "[+] Building Docker image (linux/amd64)..." docker buildx build --platform linux/amd64 -t "${image_name}:${version}" . echo "[+] Tagging image..." docker tag "${image_name}:${version}" "${full_tag}" echo "[+] Pushing image to registry..." docker push "${full_tag}" echo "[+] Build & push finished" echo "[+] ================================" restart_app } restart_app() { echo "[+] Restart ${image_name}" echo "[+] --------------------------------" local remote='' local cmd='' local full_tag="${registry}/${image_name}:${version}-${env}" local redis_host='' local redis_password='redis@aitori!@#' local redis_port='6379' local redis_db='1' case $env in dev) remote=$REMOTE_DEV redis_host='10.146.0.2' ;; test) remote=$REMOTE_TEST redis_host='10.146.0.2' ;; pro) remote=$REMOTE_PRO redis_host='10.146.0.3' ;; esac cmd="docker run -d \ --name ${image_name} \ --restart always \ -p 8080:8080 \ -m 2g \ -e AI_FLOW_REDIS_HOST=${redis_host} \ -e AI_FLOW_REDIS_PORT=${redis_port} \ -e AI_FLOW_REDIS_PASSWORD=${redis_password} \ -e AI_FLOW_REDIS_DB=${redis_db} \ -e AI_FLOW_STORE_BACKEND=redis \ -v /data/ai-flow/data:/app/data \ -v /data/ai-flow/resources:/app/resources \ --volume /etc/localtime:/etc/localtime \ ${full_tag}" ssh "$remote" << EEOOFF docker rm -f ${image_name} 2>/dev/null || true docker pull ${full_tag} ${cmd} exit EEOOFF echo "[+] Restart ${image_name} finished" echo "[+] --------------------------------" } while getopts "e:v:h" arg; do case $arg in e) env=$OPTARG echo "[+] Build env: $env" ;; v) version=$OPTARG echo "[+] Build version: $version" ;; h) usage exit 0 ;; esac done login build