Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CircleCI deployment to AWS EC2

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?

like image 885
ChrisRich Avatar asked Dec 24 '22 05:12

ChrisRich


1 Answers

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 ./ [email protected]:/home/circleci-aws/
        #Run script inside of machine
        ssh -o StrictHostKeyChecking=no [email protected] "./deploy.sh"

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

like image 191
jwillker Avatar answered Jan 01 '23 19:01

jwillker