- Stagging部署
- 修改docker-compose.yml
version: "3.9"
services:
cat:
image: 172.16.128.215:8080/hive/hellocat:latest
ports:
- ${APP_PORT}:8000
restart: always
- 修改Gitlab-ci.yml文件
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_staging
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.."
- scp -o StrictHostKeyChecking=no ./docker-compose.yml [email protected]:/root #拷贝docker-compose.yml到目标机器
# 启动docker服务到目标机器,配置APP_PORT 和 COMPOSE_PROJECT_NAME
- ssh -o StrictHostKeyChecking=no [email protected] "
export APP_PORT=3000 && export COMPOSE_PROJECT_NAME=qa &&
docker-compose down && docker-compose up -d
"
deploy_to_staging:
stage: deploy_to_staging
tags:
- shell
before_script:
- eval $(ssh-agent -s) #执行ssh
- ssh-add <(echo "$SERVER_PRIVATE_KEY") #读取密钥并加入列表
script:
- echo "start deploying"
- scp -o StrictHostKeyChecking=no ./docker-compose.yml [email protected]:/root #拷贝docker-compose.yml到目标机器
# 启动docker服务到目标机器,配置APP_PORT 和 COMPOSE_PROJECT_NAME
- ssh -o StrictHostKeyChecking=no [email protected] "
export APP_PORT=8000 && export COMPOSE_PROJECT_NAME=stagging &&
docker-compose down && docker-compose up -d
"
- 执行结果:
- enviornment用法:(用于直观检查,多个项目的部署情况与进度)
- 配置gitlab.yml
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_staging
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.."
- scp -o StrictHostKeyChecking=no ./docker-compose.yml [email protected]:/root #拷贝docker-compose.yml到目标机器
# 启动docker服务到目标机器,配置APP_PORT 和 COMPOSE_PROJECT_NAME
- ssh -o StrictHostKeyChecking=no [email protected] "
export APP_PORT=3000 && export COMPOSE_PROJECT_NAME=qa &&
docker-compose down && docker-compose up -d
"
# 在Gitlab中->Operations -> environment便于管理
environment:
name: qa
url: 172.16.128.153:3000
deploy_to_staging:
stage: deploy_to_staging
tags:
- shell
before_script:
- eval $(ssh-agent -s) #执行ssh
- ssh-add <(echo "$SERVER_PRIVATE_KEY") #读取密钥并加入列表
script:
- echo "start deploying"
- scp -o StrictHostKeyChecking=no ./docker-compose.yml [email protected]:/root #拷贝docker-compose.yml到目标机器
# 启动docker服务到目标机器,配置APP_PORT 和 COMPOSE_PROJECT_NAME
- ssh -o StrictHostKeyChecking=no [email protected] "
export APP_PORT=8000 && export COMPOSE_PROJECT_NAME=stagging &&
docker-compose down && docker-compose up -d
"
environment:
name: staging
url: 172.16.128.153:8000
- 查看结果: