feat(project): init

This commit is contained in:
2026-03-10 17:06:22 +08:00
commit 1ae8509cce
70 changed files with 5141 additions and 0 deletions

93
build.sh Executable file
View File

@@ -0,0 +1,93 @@
#!/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_labelui
DOCKER_FILE=$SHELL_FOLDER/Dockerfile
if [[ $OUTPUT_TYPE == export ]]; then
DOCKER_FILE=$SHELL_FOLDER/docker/nginx.dockerfile
MAIN_NAME=digitalspace_labelui_static
elif [[ $OUTPUT_TYPE == standalone ]]; then
DOCKER_FILE=$SHELL_FOLDER/docker/node.dockerfile
MAIN_NAME=digitalspace_labelui_ssr
fi
echo -e "${GREEN}Building docker image...${NC}"
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}"
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}"