1
0
mirror of https://github.com/142vip/408CSFamily.git synced 2026-02-03 02:23:38 +08:00
Files
408CSFamily/scripts/build_image.sh
喜欢芝士的妹妹 497fd0d9cf feat: 修改本地镜像
2023-02-01 22:06:12 +08:00

60 lines
1.6 KiB
Bash
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
## 功能本地前后端项目构建、打包镜像上传docker仓库
## 参考https://blog.csdn.net/Dontla/article/details/125210694
## 作者:储凡
## 使用示例bash xxx.sh 版本号
## - bash build_image.sh 0.0.1
##
## 日志颜色定义
readonly successLogger="\033[36m"
readonly errorLogger="\033[1;31m"
readonly warnLogger="\033[1;33m"
## 定义时间
readonly currentTime=$(date "+%Y-%m-%d %H:%M:%S")
## 项目名称
readonly projectName="408CSFamily"
## 仓库地址
readonly repoAddress="registry.cn-hangzhou.aliyuncs.com/142vip/doc_book:"
## 版本号
version=${1}
prepare_check(){
if test -z "${version}";then
echo -e "${errorLogger}${currentTime}:参数错误 版本号不能为空。参考版本: 0.0.x"
exit 0
fi
}
run(){
echo -e "${successLogger}---------------- shell ${projectName} start ---------------- "
docker build -t "${repoAddress}${projectName}-${version}" .
echo -e "${successLogger}---------------- shell ${projectName} end ---------------- "
push_docker_image
}
## 推送镜像
push_docker_image(){
if [[ "$(docker images -q "${repoAddress}${projectName}-${version}" 2> /dev/null)" != "" ]];
then
## 推送
docker push "${repoAddress}${projectName}-${version}"
echo -e "${successLogger}---------------- 上传镜像成功,删除本地镜像 ---------------- "
docker rmi "${repoAddress}${projectName}-${version}"
else
echo -e "${errorLogger}${currentTime}:镜像:${repoAddress}${projectName}-${version}不存在"
fi
exit 0
}
prepare_check
run