如何构建Docker镜像并将其推送到ECR,并使用CIRCLE 2.0?

我正在尝试从CIRCLE 1.0升级到2.0 &我无法获取Docker映像来构建。我有以下工作:|如何构建Docker镜像并将其推送到ECR,并使用CIRCLE 2.0?

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

回答:

这是我改变,使这项工作的配置:

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

以上是 如何构建Docker镜像并将其推送到ECR,并使用CIRCLE 2.0? 的全部内容, 来源链接: utcz.com/qa/262122.html

回到顶部