Circleci: stuck in build and push image to ECR

Viewed 272

My main goal is to build and push the docker image to AWS ECR. I try to build my dockerfile in circleci config yml file. But is there a better solution to build and push to ECR? https://circleci.com/docs/2.0/ecs-ecr/#build-and-push-the-docker-image-to-aws-ecr I checked docs but couldn't do it. I'm too rookie for that I guess. Can I build and push in one step like the one in the documents.

My Circleci config.yml:

version: 2.1
orbs:
  node: circleci/node@4.1.0
  aws-cli: circleci/aws-cli@1.3.1
  aws-ecr: circleci/aws-ecr@8.1.0
  aws-ecs: circleci/aws-ecs@2.2.1
jobs:
  build-app:
    docker:
      - image: "cimg/base:stable"
    steps:
      - checkout
      - setup_remote_docker:
          version: 19.03.13
          docker_layer_caching: true
      - run:
          name: App Build
          command: |     
            docker build -t sampleapp:latest .
      - deploy:
              name: push application docker image
              command: |
                login="$(aws ecr get-login)" \
                ${login} \
                aws ecr describe-repositories --repository-names sampleapp --region eu-west-1 || aws ecr create-repository --repository-name sampleapp --region eu-west-1 \
                docker tag 1.0.0:latest "${AWS_ECR_LOGIN_URL}/sampleapp:sampleapp-1.0.0" \
                docker push "${AWS_ECR_LOGIN_URL}/sampleapp:sampleapp-1.0.0"
workflows:
  version: 2
  plan_approve_apply:
    jobs:
      - build-app

My Dockerfile:

FROM node:carbon
RUN apt-get update && \
    apt-get -y install git
RUN git clone https://github.com/GermaVinsmoke/bmi-calculator.git && \
    cd bmi-calculator
#install git
RUN apt-get update \
    && apt-get install -y git
RUN npm install
COPY . .
EXPOSE 3000
CMD [“npm”, “start”]
0 Answers
Related