Files
labelimage/build.sh
2026-03-27 15:13:41 +08:00

94 lines
2.5 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
SHELL_FOLDER=$(cd "$(dirname "$0")";pwd)
HOME_PATH=$(cd ~;pwd)
# ./build.sh # stage + standalone
# ./build.sh stage # stage + standalone
# ./build.sh prod # prod + standalone
# ./build.sh -csr # stage + export
# ./build.sh prod -csr # prod + export
# ./build.sh stage -ssr # stage + standalone默认
# -------------------------
# 1. 默认环境 & 默认输出类型
# -------------------------
ENV=stage
OUTPUT_TYPE=standalone # 默认 SSRstandalone
# -------------------------
# 2. 解析参数
# -------------------------
for arg in "$@"; do
case "$arg" in
prod)
ENV=prod
;;
stage)
ENV=stage
;;
-csr)
OUTPUT_TYPE=export # 静态导出
;;
-ssr)
OUTPUT_TYPE=standalone # SSR 部署
;;
esac
done
# -------------------------
# 3. 计算 BUILD_FLAG && FLAG_PROD
# -------------------------
# build:{standalone|export}-{stage|prod}
BUILD_FLAG="build:${OUTPUT_TYPE}-${ENV}"
# {stage|prod}_latest
FLAG_PROD="${ENV}_latest"
cd $SHELL_FOLDER
# # 检查git状态
# echo -e "${GREEN}Checking git status...${NC}"
# git fetch
# git merge
# if [[ $? != 0 ]]; then echo -e "${RED}git pull error${NC}"; exit 100; fi
BRANCH_NAME=`git branch | grep "*"`
echo -e "${GREEN}Current branch: ${BRANCH_NAME/* /}${NC}"
# 安装依赖
echo -e "${GREEN}Installing dependencies...${NC}"
pnpm install
if [[ $? != 0 ]]; then echo -e "${RED}pnpm install failed${NC}"; exit 100; fi
# 执行构建
echo -e "${GREEN}Building project...${NC}"
pnpm run $BUILD_FLAG
if [[ $? != 0 ]]; then echo -e "${RED}build error${NC}"; exit 100; fi
# Docker构建和推送
MAIN_NAME=digitalspace_labelimage
DOCKER_FILE=$SHELL_FOLDER/Dockerfile
if [[ $OUTPUT_TYPE == export ]]; then
DOCKER_FILE=$SHELL_FOLDER/docker/nginx.dockerfile
MAIN_NAME=digitalspace_labelimage_static
elif [[ $OUTPUT_TYPE == standalone ]]; then
DOCKER_FILE=$SHELL_FOLDER/docker/node.dockerfile
MAIN_NAME=digitalspace_labelimage_ssr
fi
echo -e "${GREEN}Building docker image...${NC}"
sudo docker build -f $DOCKER_FILE -t $MAIN_NAME $SHELL_FOLDER
if [[ $? != 0 ]]; then echo -e "${RED}build docker with error${NC}"; exit 100; fi
echo -e "${GREEN}Tagging and pushing docker image...${NC}"
sudo docker tag $MAIN_NAME harbor.cowarobot.cn/gopro/$MAIN_NAME:$FLAG_PROD
# docker push harbor.cowarobot.cn/gopro/$MAIN_NAME:$FLAG_PROD
echo -e "${GREEN}Build completed successfully${NC}"