0

I'm trying to upgrade from CIRCLE 1.0 to 2.0 & I'm having trouble getting the Docker images to build. I've got the following job:|

... 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

Running this throws the following error:

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

All I had todo before was this:

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

1 Answer 1

1

Here is the config I've changed to make this work:

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

Check out this link: https://github.com/builtinnya/circleci-2.0-beta-docker-example/blob/master/.circleci/config.yml#L39

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.