CircleCI deployment to AWS EC2

老子叫甜甜 提交于 2019-12-09 18:33:57

问题


Can you help me find a useful step-by-step guide or a Gist outlining in detail how to configure CircleCI (using 2.0 syntax) to deploy to AWS EC2?

I understand the basic requirements and the moving pieces, but unsure what to put in the .circleci/config.yml file in the deploy step.

So far I got:

  • A "Hello World" Node.js app which is building successfully in CircleCI (just without the deploy step)
  • A running EC2 instance (Ubuntu 16.04)
  • An IAM user with sufficient permissions added to CircleCI for that particular job

Can you help out with the CircleCI deploy step?


回答1:


Following your repository, you could create a script just like that: deploy.sh

#!/bin/bash

echo "Start deploy"
cd ~/circleci-aws
git pull
npm i
npm run build 
pm2 stop build/server
pm2 start build/server
echo "Deploy end"

And in your .circleci/conf.yml you do it:

deploy:
docker:
  - image: circleci/node:chakracore-8.11.1
steps:
  - restore_cache:
      keys:
      - v1-dependencies-{{ checksum "package.json" }}
  - run:
      name: AWS EC2 deploy
      command: |
        #upload all the code to machine
        scp -r -o StrictHostKeyChecking=no ./ ubuntu@13.236.1.107:/home/circleci-aws/
        #Run script inside of machine
        ssh -o StrictHostKeyChecking=no ubuntu@13.236.1.107 "./deploy.sh"

But this is so ugly, try something like AWS Codedeploy or ecs for using containers.



来源:https://stackoverflow.com/questions/51626275/circleci-deployment-to-aws-ec2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!