jenkins docker rancher harbor

金阳华
2023-12-01

//jenkins打包shell脚本

#!/bin/bash

source /etc/profile

##set color##

echoRed() { echo $'\e[0;31m'"$1"$'\e[0m'; }

echoGreen() { echo $'\e[0;32m'"$1"$'\e[0m'; }

echoYellow() { echo $'\e[0;33m'"$1"$'\e[0m'; }

##set color##

# 设置变量

project="pay"

version="1.0.0"

harbor_user="admin"

harbor_pwd="Harbor12345"

harbor_host="127.0.0.1:8000"

port=6065

echo -------------------------------------

# mvn打包

#cd $WORKSPACE

#mvn clean install -DskipTests=true

#if [ $? -eq 0 ];then

# echoGreen "mvn package is success!"

#else

# echoRed "mvn package is Failed!" && exit 1

#fi

#sleep 2

# 进入target目录

cd $WORKSPACE/$project/target/ && mv $project-1.0.0.jar app.jar

# 创建docker镜像

cat > run.sh << EOF

#!/bin/bash

source /etc/profile

java -jar /home/app.jar --server.port=${port} --spring.profiles.active=test

EOF

chmod +x run.sh

cat >Dockerfile << EOF

FROM 127.0.0.1:8000/library/jdk1.8:1.0.0

EXPOSE 6065

MAINTAINER wsc <123@qq.com>

ENV LANG en_US.UTF-8

ADD app.jar /home

ADD run.sh /

ENTRYPOINT [ "sh", "-c", "/run.sh" ]

EOF

# 编译镜像

echoGreen "开始构建当次镜像!"

docker build -t $harbor_host/library/$project:$version .

# 登录远程Harbor仓库

echoGreen "开始登录远程Harbor仓库!"

docker login -u $harbor_user -p $harbor_pwd $harbor_host

[ $? != 0 ] && echoRed "请注意,登录Harbor时出错,故而退出!" && exit 1

# 上传到docker私服

echoGreen "开始push新镜像到私服!"

docker push $harbor_host/library/$project:$version

[ $? != 0 ] && echoRed "请注意,在执行push上传时出错,故而退出!" && exit 1

docker rmi $harbor_host/library/$project:$version

//jenkins启动rancher配置

Deploy/Upgrade Rancher Service

API Endpoint

http://127.0.0.1:8080/v2-beta

Rancher API Key

/******76F0029/******

Rancher Environment Id

1a5

Service Name

ttos/pay

Docker Image

127.0.0.1:8000/library/ttos-pay:1.0.0

 类似资料:

相关阅读

相关文章

相关问答