【发布时间】:2017-12-19 18:17:56
【问题描述】:
每个人。我需要一些帮助来解决我在为我的 Angular 项目配置 circleCi 时遇到的一些问题。
下面详细介绍了我用于构建和部署过程的 config.yml。目前我决定为每个环境做单独的工作,每个工作都包括构建和部署。这种方法的问题是我在重复自己,我找不到正确的方法来部署在之前的工作中为相同的工作流构建的工件。
version: 2
jobs:
build:
docker:
- image: circleci/node:8-browsers
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: Install dependencies
command: npm install
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- .node_modules
- run:
name: Build Application (Production mode - aot enabled)
command: npm run build:prod
- store_artifacts:
path: dist
destination: dist
deploy_prod:
docker:
- image: circleci/node:8-browsers
environment:
- FIREBASE_TOKEN: "1/AFF2414141ASdASDAKDA4141421sxscq"
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: Install dependencies
command: npm install
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- .node_modules
- run:
name: Build Application (Production mode - aot enabled)
command: npm run build:prod
- store_artifacts:
path: dist
destination: dist
- run:
command: ./node_modules/.bin/firebase use default
- deploy:
command: ./node_modules/.bin/firebase deploy --token=$FIREBASE_TOKEN
deploy_qa:
docker:
- image: circleci/node:8-browsers
environment:
- FIREBASE_TOKEN: "1/AFF2414141ASdASDAKDA4141421sxscq"
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: Install dependencies
command: npm install
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- .node_modules
- run:
name: Build Application (Production mode - aot enabled)
command: npm run build:prod
- store_artifacts:
path: dist
destination: dist
- run:
command: ./node_modules/.bin/firebase use qa
- deploy:
command: ./node_modules/.bin/firebase deploy --token=$FIREBASE_TOKEN
workflows:
version: 2
build-and-deploy:
jobs:
- build:
filters:
branches:
only:
- master
ignore:
- /feat-.*/
- deploy_prod:
filters:
branches:
ignore:
- /.*/
tags:
only:
- /v[0-9]+(\.[0-9]+){2}/
- deploy_qa:
filters:
branches:
ignore:
- /.*/
tags:
only:
- /v[0-9]+(\.[0-9]+){2}-BETA-([0-9]*)/
-
我了解每个作业都使用不同的 docker 映像,因此这会阻止我在同一个工作区工作。
问:如何在同一个工作流程中为不同的作业使用同一个 docker 镜像?
-
我认为 store_artifacts 对我有帮助,但我读到它只适用于通过仪表板或 API 使用。
问:我能否恢复需要存储工件的不同作业的作业上的工件?
-
我知道我在重复自己,我的目标是根据标签的名称为每个环境的部署作业提供一个构建作业。所以我的 deploy_{env} 工作主要是 firebase 命令。
workflows: version: 2 build-and-deploy: jobs: - build: filters: branches: only: - master ignore: - /feat-.*/ tags: only: - /v[0-9]+(\.[0-9]+){2}/ - /v[0-9]+(\.[0-9]+){2}-BETA-([0-9]*)/ - deploy_prod: requires: - build filters: branches: ignore: - /.*/ tags: only: - /v[0-9]+(\.[0-9]+){2}/ - deploy_qa: requires: - build filters: branches: ignore: - /.*/ tags: only: - /v[0-9]+(\.[0-9]+){2}-BETA-([0-9]*)/问:此解决方案的推荐步骤(最佳做法)是什么?
【问题讨论】: