2019-10-20 TIL

  • circleci로 도커 이미지를 빌드하고 push를 하다가 aws-cli를 통해 빌드 푸쉬를 해보았다. ```shell // ECR Login ubuntu@ip-172-31-35-39:~$ aws ecr get-login –no-include-email –region ap-notrheast-2 ubuntu@ip-172-31-35-39:~/test$ aws ecr get-login –no-include-email –region ap-northeast-2 docker login -u AWS -p eyJwYXlxNTcxNDA3NjA5fQeyJwYXlxNTcxNDA3NjA5fQeyJwYXlxNTcxNDA3NjA5fQeyJwYXlxNTcxNDA3NjA5fQeyJwYXlxNTcxNDA3NjA5fQeyJwYXlxNTcxNDA3NjA5fQeyJwYXlxNTcxNDA3NjA5fQeyJwYXlxNTcxNDA3NjA5fQeyJwYXlxNTcxNDA3NjA5fQeyJwYXlxNTcxNDA3NjA5fQeyJwYXlxNTcxNDA3NjA5fQeyJwYXlxNTcxNDA3NjA5fQ== https://xxxxxxxxxxxx.dkr.ecr.ap-northeast-2.amazonaws.com

// Docker image push to ECR docker tag test:latest 213998520210.dkr.ecr.ap-northeast-2.amazonaws.com/jaeyeon/test:latest => image에 태그를 새로 만든다.

- 위의 코드는 awscli를 이용한것이고 밑에 코드는 circleci를 이용한 방식이다. 언뜻보면 밑에 코드가 더 복잡해 보였는데, 막상해보면 위에코드가 엄청 복잡하다.

version: 2.1 orbs: aws-s3: circleci/aws-s3@1.0.11 aws-ecr: circleci/aws-ecr@6.5.0 aws-cli: circleci/aws-cli@0.1.15 slack: circleci/slack@3.4.0

workflows: jimmy-custom-build: jobs: - build-and-push-image jobs: build-and-push-image: docker: - image: circleci/node:10 # the primary container, where your job’s commands are run environment: REACT_APP_NODE_API_URL: $REACT_APP_NODE_API_URL REACT_APP_IMAGE_URI: $REACT_APP_IMAGE_URI DB_SCHEMA: $DB_SCHEMA DB_USER: $DB_USER DB_PASSWORD: $DB_PASSWORD PROD_DB_URL: $PROD_DB_URL DEV_DB_URL: $DEV_DB_URL TEST_DB_URL: $TEST_DB_URL MIGRATE_dbConnectionUri: $MIGRATE_dbConnectionUri JWT_SECRET: $JWT_SECRET GOOGLE_API_CLIENT_ID: $GOOGLE_API_CLIENT_ID GOOGLE_API_CLIENT_SECRET: $GOOGLE_API_CLIENT_SECRET GOOGLE_API_REDIRECT_URL: $GOOGLE_API_REDIRECT_URL GOOGLE_API_SCOPE: $GOOGLE_API_SCOPE parameters: account-url: default: AWS_ECR_ACCOUNT_URL type: env_var_name aws-access-key-id: default: AWS_ACCESS_KEY_ID type: env_var_name aws-secret-access-key: default: AWS_SECRET_ACCESS_KEY type: env_var_name dockerfile: default: Dockerfile type: string steps: - when: condition: «parameters.checkout» steps: - checkout - aws-cli/install - aws-cli/configure: aws-access-key-id: «parameters.aws-access-key-id» aws-region: «parameters.region» aws-secret-access-key: «parameters.aws-secret-access-key» profile-name: «parameters.profile-name» - when: condition: «parameters.attach-workspace» steps: - attach_workspace: at: «parameters.workspace-root» - aws-ecr/ecr-login: region: «parameters.region» - aws-ecr/build-image: account-url: «parameters.account-url» dockerfile: «parameters.dockerfile» extra-build-args: «parameters.extra-build-args» path: «parameters.path» repo: «parameters.repo» tag: «parameters.tag» - when: condition: «parameters.create-repo» steps: - run: > aws ecr describe-repositories –profile «parameters.profile-name» –region $«parameters.region» –repository-names «parameters.repo» > /dev/null 2>&1 || \

            aws ecr create-repository --profile <<parameters.profile-name>>
            --region $<<parameters.region>> --repository-name
            <<parameters.repo>>
  - aws-ecr/push-image:
      account-url: <<parameters.account-url>>
      repo: <<parameters.repo>>
      tag: <<parameters.tag>> ``` - ci는 써야되는거다. ci를 통해 자동화를 시키고 유지보수가 용이해졌다.
Written on October 20, 2019