善用搜索

shell脚本将本地docker镜像push到阿里云镜像仓库教程

\#!/bin/bash

\# 将本地打包的jar包生成docker镜像并push到aliyun的镜像仓库中

\# api jar 所在的目录

api\_files=find /Users/yunshuodeng/Work/powerusercenter/power-dubbo-api/target -name "\*.jar"

\# provider jar 所在的目录

provider\_files=find /Users/yunshuodeng/Work/powerusercenter/power-dubbo-provider/target -name "\*.jar"

\# consumer jar 所在的目录

consumer\_files=find /Users/yunshuodeng/Work/powerusercenter/power-dubbo-consumer/target -name "\*.jar"

\# 构建consumer docker镜像目录

consumer\_des\_dir="/Users/yunshuodeng/Work/mydocker/app/consumer"

\# 构建provider docker镜像目录

provider\_des\_dir="/Users/yunshuodeng/Work/mydocker/app/provider"

\# 进入构建provider docker镜像目录

cd $provider\_des\_dir

\# 遍历api jar

for file in $api\_files

do

# 判断jar文件是否存在

if [ !-f"$provider\_des\_dir/$file" ]; then

rm -rf "$provider\_des\_dir/$file"

fi

# 将api jar 复制到构建provider docker镜像目录

cp -p $file $provider\_des\_dir

# 判断jar文件是否存在

if [ !-f"$consumer\_des\_dir/$file" ]; then

rm -rf "$consumer\_des\_dir/$file"

fi

# 将api jar 复制到构建consumer docker镜像目录

cp -p $file $consumer\_des\_dir

((file\_count++))

done

\# 复制provider jar文件

for file in $provider\_files

do

# 判断jar文件是否存在

if [ !-f"$provider\_des\_dir/$file" ]; then

rm -rf "$provider\_des\_dir/$file"

fi

cp -p $file $provider\_des\_dir

((file\_count++))

done

\# 复制consumer jar文件

for file in $consumer\_files

do

# 判断jar文件是否存在

if [ !-f"$consumer\_des\_dir/$file" ]; then

rm -rf "$consumer\_des\_dir/$file"

fi

cp -p $file $consumer\_des\_dir

((file\_count++))

done

echo "all copy success"

\# 进入构建provider docker镜像目录

cd $provider\_des\_dir

consumer\_first=0

consumer\_second=0

consumer\_third=1

consumer\_third\_version=docker images | grep registry.cn-shanghai.aliyuncs.com/huinongtx/user\_center\_consumer | sort -k2,2r | head -n 1 | awk '{print $2}'|cut -d '.' -f 3

consumer\_second\_version=docker images | grep registry.cn-shanghai.aliyuncs.com/huinongtx/user\_center\_consumer | sort -k2,2r | head -n 1 | awk '{print $2}'|cut -d '.' -f 2

consumer\_first\_version=docker images | grep registry.cn-shanghai.aliyuncs.com/huinongtx/user\_center\_consumer | sort -k2,2r | head -n 1 | awk '{print $2}'|cut -d '.' -f 1

echo $consumer\_third\_version

if [ ! -n $consumer\_third\_version ];then

echo "is null"

else

let consumer\_third=$consumer\_third\_version+1

fi

echo $consumer\_third

if [ ! -n $consumer\_second\_version ];then

echo "is null"

else

let consumer\_second=$consumer\_second\_version

fi

if [ ! -n $consumer\_first\_version ];then

echo "is null"

else

let consumer\_first=$consumer\_first\_version

fi

\#echo "$versionstr"

if [ $consumer\_third -gt 9 ];then

let consumer\_third=0

let consumer\_second=$consumer\_second+1

if [ $consumer\_second -gt 9 ];then

let consumer\_third=0

let consumer\_second=0

let consumer\_first=$consumer\_third+1

fi

fi

consumer\_next\_version="$consumer\_first.$consumer\_second.$consumer\_third"

echo $consumer\_next\_version

provider\_first=0

provider\_second=0

provider\_third=1

provider\_third\_version=docker images | grep registry.cn-shanghai.aliyuncs.com/huinongtx/user\_center\_provider | sort -k2,2r | head -n 1 | awk '{print $2}'|cut -d '.' -f 3

provider\_second\_version=docker images | grep registry.cn-shanghai.aliyuncs.com/huinongtx/user\_center\_provider | sort -k2,2r | head -n 1 | awk '{print $2}'|cut -d '.' -f 2

provider\_first\_version=docker images | grep registry.cn-shanghai.aliyuncs.com/huinongtx/user\_center\_provider | sort -k2,2r | head -n 1 | awk '{print $2}'|cut -d '.' -f 1

if [ ! -n $provider\_third\_version ];then

echo "is null"

else

let provider\_third=$provider\_third\_version+1

fi

if [ ! -n $provider\_second\_version ];then

echo "is null"

else

let provider\_second=$provider\_second\_version

fi

if [ ! -n $provider\_first\_version ];then

echo "is null"

else

let provider\_first=$provider\_first\_version

fi

if [ $provider\_third -gt 9 ];then

let provider\_third=0

let provider\_second=$provider\_second+1

if [ $provider\_second -gt 9 ];then

let provider\_third=0

let provider\_second=0

let provider\_first=$provider\_first+1

fi

fi

provider\_next\_version=$provider\_first.$provider\_second.$provider\_third

echo $provider\_next\_version

cd $provider\_des\_dir

\# 判断镜像是否存在

\# 构建provider镜像

docker build -t power-dubbo-provider:$provider\_next\_version .

\# 进入构建consumer docker镜像目录

cd $consumer\_des\_dir

\# 构建consumer镜像

docker build -t power-dubbo-consumer:"$consumer\_next\_version" .

echo "all build success"

\# 上传镜像到aliyun仓库

\# 登录到仓库

cat /Users/yunshuodeng/Work/mydocker/app/aliyun\_images\_repository\_password.txt | docker login -u 阿里云账户名 --password-stdin registry.cn-shanghai.aliyuncs.com

\# 将provider docker 镜像上传到user\_center仓库

docker tag power-dubbo-provider:"$provider\_next\_version" registry.cn-shanghai.aliyuncs.com/huinongtx/user\_center\_provider:"$provider\_next\_version"

docker push registry.cn-shanghai.aliyuncs.com/huinongtx/user\_center\_provider:"$provider\_next\_version"

\# 将consumer docker 镜像上传到user\_center\_consumer仓库

docker tag power-dubbo-consumer:"$consumer\_next\_version" registry.cn-shanghai.aliyuncs.com/huinongtx/user\_center\_consumer:"$consumer\_next\_version"

docker push registry.cn-shanghai.aliyuncs.com/huinongtx/user\_center\_consumer:"$consumer\_next\_version"

echo "all push success "

发表评论
退出移动版