0

我正在尝试从 CIRCLE 1.0 升级到 2.0,但无法构建 Docker 映像。我有以下工作:|

... There is another Job here which runs some tests
deploy-aws:
    # machine: true
    docker:
      - image: ecrurl/backend
        aws_auth:
              aws_access_key_id: ID1
              aws_secret_access_key: $ECR_AWS_SECRET_ACCESS_KEY  # or project UI envar reference
        environment:
            TAG: $CIRCLE_BRANCH-$CIRCLE_SHA1
            ECR_URL: ecrurl/backend
            DOCKER_IMAGE: $ECR_URL:$TAG
            STAGING_BUCKET: staging
            TESTING_BUCKET: testing
            PRODUCTION_BUCKET: production
            NPM_TOKEN: $NPM_TOKEN

    working_directory: ~/backend

    steps:
    - run:
        name: Install awscli
        command: sudo apt-get -y -qq install awscli

    - checkout

    - run:
        name: Build Docker image
        command: |
          if [ "${CIRCLE_BRANCH}" == "master" ]; then
            docker pull $ECR_URL:latest
            docker build -t backend NODE_ENV=$NODE_ENV  --build-arg NPM_TOKEN=$NPM_TOKEN .
            docker tag backend $DOCKER_IMAGE
            docker push $DOCKER_IMAGE
            docker tag -f $DOCKER_IMAGE $ECR_URL:latest
            docker push $ECR_URL:latest
          fi

workflows:
  version: 2
  build-deploy:
    jobs:
      - build # This one simply runs test
      - deploy-aws:
          requires:
            - build

运行它会引发以下错误:

#!/bin/bash -eo pipefail
sudo apt-get -y -qq install awscli
/bin/bash: sudo: command not found
Exited with code 127

我之前要做的就是:

dependencies:
  pre:
    - $(aws ecr get-login --region us-west-2)


deployment:
  staging:
    branch: staging
      - docker pull $ECR_URL:latest
      - docker build -t backend NODE_ENV=$NODE_ENV  --build-arg NPM_TOKEN=$NPM_TOKEN .
      - docker tag backend $DOCKER_IMAGE
      - docker push $DOCKER_IMAGE
      - docker tag -f $DOCKER_IMAGE $ECR_URL:latest
      - docker push $ECR_URL:latest
4

1 回答 1

1

这是我为使其工作而更改的配置:

deploy-aws:
docker:
  - image: docker:17.05.0-ce-git

 steps:
  - checkout
  - setup_remote_docker
  - run:
      name: Install dependencies
      command: |
        apk add --no-cache \
          py-pip=9.0.0-r1
        pip install \
          docker-compose==1.12.0 \
          awscli==1.11.76

  - restore_cache:
      keys:
        - v1-{{ .Branch }}
      paths:
        - /caches/app.tar
  - run:
      name: Load Docker image layer cache
      command: |
        set +o pipefail
        docker load -i /caches/app.tar | true

  - run:
      name: Build Docker image
      command: |
        if [ "${CIRCLE_BRANCH}" == "master" ]; then
          docker build -t backend --build-arg  .
        fi
  - run:
      name: Save Docker image layer cache
      command: |
        mkdir -p /caches
        docker save -o /caches/app.tar app

  - save_cache:
        key: v1-{{ .Branch }}-{{ epoch }}
        paths:
          - /caches/app.tar
  - run:
      name: Tag and push to ECR
      command: |
        if [ "${CIRCLE_BRANCH}" == "master" ]; then
          docker tag backend $DOCKER_IMAGE
          docker push $DOCKER_IMAGE
          docker tag -f $DOCKER_IMAGE $ECR_URL:latest
          docker push $ECR_URL:latest
        fi

查看此链接:https ://github.com/builtinnya/circleci-2.0-beta-docker-example/blob/master/.circleci/config.yml#L39

于 2017-12-20T00:02:21.477 回答