對於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