为从CircleCI 1.0迁移到2.0而苦苦挣扎的最后几天,虽然构建过程完成了,但部署仍然是一个大问题。 CircleCI文档并没有太大帮助。
这与我的config.yml
类似:
version 2
jobs:
build:
docker:
- image: circleci/node:8.9.1
steps:
- checkout
- setup_remote_docker
- run
name: Install required stuff
command: [...]
- run:
name: Build
command: docker build -t project .
deploy:
docker:
- image: circleci/node:8.9.1
steps:
- checkout
- run:
name: Deploy
command: |
bash scripts/deploy/deploy.sh
docker tag project [...]
docker push [...]
workflows:
version: 2
build-deploy:
jobs:
- build
- deploy:
requires:
- build
filters:
branches:
only: develop
问题出在deploy
工作中。我必须指定docker: -image
点,但是我想重用build
作业中已经安装了所有必需内容的环境。当然,我可以将它们安装在deploy
作业中,但是拥有多个deploy
作业会导致代码重复,这是我不希望的。
答案 0 :(得分:0)
如果标记由build
阶段构建的图像,则可以在deploy
阶段引用它:https://docs.docker.com/compose/compose-file/#labels
答案 1 :(得分:0)
您可能想保留到工作区并将其附加到部署作业中。 之后,您将不需要使用“-结帐”
https://circleci.com/docs/2.0/configuration-reference/#persist_to_workspace
jobs:
build:
docker:
- image: circleci/node:8.9.1
steps:
- checkout
- setup_remote_docker
- run
name: Install required stuff
command: [...]
- run:
name: Build
command: docker build -t project .
- persist_to_workspace:
root: ./
paths:
- ./
deploy:
docker:
- image: circleci/node:8.9.1
steps:
- attach_workspace:
at: ./
- run:
name: Deploy
command: |
bash scripts/deploy/deploy.sh
docker tag project [...]
docker push [...]
workflows:
version: 2
build-deploy:
jobs:
- build
- deploy:
requires:
- build
filters:
branches:
only: develop