Files
sso-portal/build.sh
2026-07-11 18:24:15 +08:00

75 lines
1.7 KiB
Bash
Executable File
Raw Permalink 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 预发布(默认 staging
# ./build.sh prod 生产
TAG=stage_latest
BUILD_FLAG=build:stage
if [[ $1 == prod ]]; then
TAG=prod_latest
BUILD_FLAG=build
fi
cd $SHELL_FOLDER
ENV=stage
# 解析参数
for arg in "$@"; do
case "$arg" in
prod)
ENV=prod
;;
stage)
ENV=stage
;;
dev)
ENV=dev
;;
esac
done
# # 检查 git 状态
# echo -e "${GREEN}Checking git status...${NC}"
# git fetch
# git merge
# if [[ $? != 0 ]]; then echo -e "${RED}git merge 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=web_sso_portal
DOCKER_FILE=$SHELL_FOLDER/Dockerfile
HARBOR_REPO=softrepo
if [[ $ENV == prod ]]; then
HARBOR_REPO=softpro
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/$HARBOR_REPO/$MAIN_NAME:$TAG
docker push harbor.cowarobot.cn/$HARBOR_REPO/$MAIN_NAME:$TAG
echo -e "${GREEN}Build completed successfully${NC}"