自动化部署 CI 脚本编写

在代码目录下新建一个文件:
文件名:.gitlab-ci.yml

# .gitlab-ci.yml
deploy_name::
  stage: deploy
  script:
    - echo "自动推送算法代码"
    - git log -3 > version.txt
    - docker build -t docker_image:TAG  .
    - docker push docker_image:TAG
    - docker system prune -f
    - ssh -p PORT user@IP "docker pull docker_image:TAG"
    - ssh -p PORT user@IP "cd /opt/apps && docker-compose down && docker-compose up -d &&  docker system prune -f"
    - echo "更新完毕"
  only:
    - master
devbuild:
  stage: Build
  script:
    - bash -c " git log -3 >version.txt "
    - bash -c "cd ./apps/summary_generator && docker build -t docker_image:TAG ."
    - docker push docker_image:TAG
  only:
    - master


devaliyun:
  stage: Deploy
  script:
    - echo "Do your deploy here"
    - ssh -p PORT user@IP " docker pull  docker_image:TAG "
    - ssh -p PORT user@IP " cd /opt/apps && docker-compose down "
    - ssh -p PORT user@IP " cd /opt/apps && docker-compose up -d && docker system prune -f "
  after_script:
    - echo "end deploy"
  only:
    - master

你可能感兴趣的:(docker进阶,自动化,ci/cd,git)