1

最后几天努力从 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工作会导致代码重复,这是我不想要的。

4

2 回答 2

1

您可能希望保留到工作区并将其附加到您的部署作业中。之后你不需要使用'- checkout'

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
于 2019-09-26T10:48:13.420 回答
0

If you label the image built by the build stage, you can then reference it in the deploy stage: https://docs.docker.com/compose/compose-file/#labels

于 2019-02-06T10:32:19.800 回答