Commit 4a4bbe39 authored by jinkaiqiang's avatar jinkaiqiang

修改

parent 9adef247
#!/bin/bash
cmd=$1
docker_file_name=$2
# 清除release镜像版本
function clear_release_image() {
......@@ -18,6 +19,10 @@ function foramt_image_version() {
else
image_version="v"`echo $CI_COMMIT_REF_NAME | grep -Eo '[0-9]+.[0-9]+'`
fi
if [[ $image_version == "v" ]] || [[ $image_version == "v_beta" ]]; then
echo "修正后的镜像版本有误:"$image_version",原版本为:"$CI_COMMIT_REF_NAME
exit 1
fi
echo "版本:"$CI_COMMIT_REF_NAME"成功修正为:"$image_version
}
# 写入版本号
......@@ -30,7 +35,11 @@ function log_version() {
function build_docker_image() {
log_version
foramt_image_version
docker build -t ${APP_IMAGE}:$image_version .
if [ -z "$docker_file_name" ]; then
docker build -t ${APP_IMAGE}:$image_version . || exit 1
else
docker build -f $docker_file_name -t ${APP_IMAGE}:$image_version . || exit 1
fi
# 正式版本构建后,清除release版本
tags_reg='^[0-9]+.[0-9]+.[0-9]+$'
if [[ "$CI_COMMIT_REF_NAME" =~ $tags_reg ]]; then
......@@ -41,7 +50,7 @@ function build_docker_image() {
# 主流程
if [ -z "$cmd" ]; then
echo "命令不能为空"
exit 0
exit 1
elif [ "$cmd" == "build" ]; then
echo "build..."
build_docker_image
......@@ -52,9 +61,9 @@ elif [ "$cmd" == "push" ]; then
elif [ "$cmd" == "push_ali" ]; then
echo "push_ali..."
foramt_image_version
docker tag ${APP_IMAGE}:$image_version ${ALI_IMAGE}:$image_version
docker push ${ALI_IMAGE}:$image_version
docker tag ${APP_IMAGE}:$image_version ${ALI_IMAGE}:$image_version || exit 1
docker push ${ALI_IMAGE}:$image_version || exit 1
else
echo "无效命令:$cmd"
exit 0
exit 1
fi
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment