1. 服务部署到目标服务器上
variables:
user: eric
pwd: Admin@1234
harbor: http://172.16.128.215:8080
image_hellocat: 172.16.128.215:8080/hive/hellocat
stages:
- testing
- build
- deploy_qa
deploy_to_qa:
stage: deploy_qa
tags:
- shell
before_script:
- eval $(ssh-agent -s) #执行ssh
- ssh-add <(echo "$SERVER_PRIVATE_KEY") #读取密钥并加入列表
script:
- echo "start deploying"
# 在目标机器:172.16.128.153上部署服务,先登录docker harbor,再拉镜像,并部署
- ssh -o StrictHostKeyChecking=no root@172.16.128.153 "
docker login -u $user -p $pwd $harbor &&
docker run -p 80:8000 -d 172.16.128.215:8080/hive/hellocat:latest
"
- 执行结果: