持续集成
持续集成是一种软件开发实践,即团队开发成员经常集成他们的工作,通常每个成员每天至少集成一次,也就意味着每天可能会发生多次集成。每次集成都通过自动化的构建(包括编译,发布,自动化测试)来验证,从而尽快地发现集成错误。许多团队发现这个过程可以大大减少集成的问题,让团队能够更快的开发内聚的软件。
要素
- 统一的代码库
- 自动构建
- 自动测试
- 每个人每天都要向代码库主干提交代码
- 每次代码递交后都会在持续集成服务器上触发一次构建
- 保证快速构建
- 模拟生产环境的自动测试
- 每个人都可以很容易的获取最新可执行的应用程序
- 每个人都清楚正在发生的状况
- 自动化的部署
常用的CI
- circle CI
- jenkins
- gitlab CI
- travis CI
一个gitlab CI的配置文件
stages:
- install_deps
- test
- build
- deploy_test
- deploy_production
cache:
key: ${CI_BUILD_REF_NAME}
paths:
- node_modules/
- dist/
# 安装依赖
install_deps:
stage: install_deps
only:
- develop
- master
script:
- npm install
# 运行测试用例
test:
stage: test
only:
- develop
- master
script:
- npm run test
# 编译
build:
stage: build
only:
- develop
- master
script:
- npm run clean
- npm run build:client
- npm run build:server
# 部署测试服务器
deploy_test:
stage: deploy_test
only:
- develop
script:
- pm2 delete app || true
- pm2 start app.js --name app
# 部署生产服务器
deploy_production:
stage: deploy_production
only:
- master
script:
- bash scripts/deploy/deploy.sh
私有gitlab
- 查看服务状态
- sudo gitlab-ctl status
- 启动Gitlab所有组件
- sudo gitlab-ctl start
- 停止Gitlab所有组件
- sudo gitlab-ctl stop
- 重启Gitlab所有组件
- sudo gitlab-ctl restart
配置external URL 显示正常的clone URL
Add or edit the following line in /etc/gitlab/gitlab.rb
external_url "http://gitlab.example.com"
sudo gitlab-ctl reconfigure
runner
通常是docker或者是shell
为CI配置一个runner 需要一个runner 这个runner可以安装在widnows和mac/linux上,runner通过API和gitlab通信