对于Angular项目,以前处理一个ticket的流程咱们的作法:javascript
npm start
npm run lint
npm run test
npm run build
tar -zcvf oneportal.gz -C dist .
每处理完一个任务都得搞一遍是否是很麻烦?重复并且效率低java
这种事情彻底能够交给CircleCI来处理。不用本身买服务器,比Jenkins简单。省去了维护和部署。 CircleCI的好处(截止当前的政策2019.2):node
Angular项目根目录新建.circleci
目录(注意以点开头),而后在这个目录里面再新建config.yml
文件 下面是我正在使用的配置,具体语法能够见官方介绍git
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
# See: https://github.com/ci-samples/angular-cli-circleci/blob/master/.circleci/config.yml
version: 2
jobs:
build:
docker:
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# specify the version you desire here
# - image: circleci/node:10.14-browsers
- image: finleyma/circleci-nodejs-browser-awscli
working_directory: ~/repo
# https://circleci.com/docs/2.0/env-vars/
environment:
ANGULAR_BUILD_DIR: ~/repo/dist
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: install-dependencies
command: npm install
- run: node -v
- run: npm -v
- run: npm run lint
- run: npm run ci-test
- run: npm run ci-build
- run: tar -zcvf oneportal.gz -C dist .
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
- run: aws --version
- run:
name: upload-to-aws-s3
command: 'aws s3 cp oneportal.gz s3://your-aws-bucket/path/ --region us-east-1'
workflows:
version: 2
build-deploy:
jobs:
- build:
filters:
branches:
only: daily-build
复制代码
须要解释几点:github
npm run ci-test
和npm run ci-build
须要在项目的package.json定义好,加入了一些参数,好比不输出过程,和加入环境参数配置"start": "npm run proxy",
...
"build": "ng build --prod",
"test": "ng test --configuration=testing",
"ci-build": "node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng build --configuration=dev --watch=false --progress=false",
"ci-test": "ng test --configuration=testing --watch=false --browsers=ChromeHeadless --progress=false",
"lint": "ng lint",
复制代码
固然,你能够直接经过SSH将项目传到站点服务器部署。也须要在后台配置下访问服务器的Key。docker