首页 > 其他分享 > GitLab CICD Day 23 - 手动部署 Production 环境

GitLab CICD Day 23 - 手动部署 Production 环境

时间:2023-02-11 23:32:06浏览次数:45  
标签:compose 23 CICD GitLab 128.153 ssh && 172.16 docker

  • 从开发到上线流程:

    GitLab CICD Day 23 - 手动部署 Production 环境_Gitlab CICD

  • 部署到Prod
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
- test
- deploy_to_prod


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

run_test_prod:
stage: test
tags:
- shell
script:
- echo "running test"

deploy_to_prod: #部署到prod
stage: deploy_to_prod
needs: # run_test_prod完成后,才进行此job运行
- run_test_prod
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=9000 && export COMPOSE_PROJECT_NAME=stagging &&
docker-compose down && docker-compose up -d
"
environment:
name: prod
url: 172.16.128.153:9000
  • 部署暂停,等待领导审批后,再部署到Prod生产 (when: manual)

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
- test
- deploy_to_prod


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

run_test_prod:
stage: test
tags:
- shell
script:
- echo "running test"

deploy_to_prod: #部署到prod
stage: deploy_to_prod
when: manual #等到领导审批后,再部署到生产
needs: # run_test_prod完成后,才进行此job运行
- run_test_prod
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=9000 && export COMPOSE_PROJECT_NAME=stagging &&
docker-compose down && docker-compose up -d
"
environment:
name: prod
url: 172.16.128.153:9000

效果:

    GitLab CICD Day 23 - 手动部署 Production 环境_Gitlab CICD_02

标签:compose,23,CICD,GitLab,128.153,ssh,&&,172.16,docker
From: https://blog.51cto.com/u_12391275/6051029

相关文章