Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Gitihub actions for CI CD on aws ec2 machine?

i am new github actions workflow and was wondering that is it possible that i set my ec2 machine directly for CI and CD after every push.

I have seen that it is possible with ECS , but i wanted a straight forward solution as we are trying this out on our Dev environment we don't want over shoot our budget.

is it possible , if yes how can i achieve it ?

like image 302
sumanth shetty Avatar asked Oct 16 '25 18:10

sumanth shetty


2 Answers

If you build your code in GitHub Actions, and just want to copy the package over existing EC2, you can use SCP files action plugin

https://github.com/marketplace/actions/scp-files

- name: copy file via ssh key
  uses: appleboy/scp-action@master
  with:
    host: ${{ secrets.HOST }}
    username: ${{ secrets.USERNAME }}
    port: ${{ secrets.PORT }}
    key: ${{ secrets.KEY }}
    source: "tests/a.txt,tests/b.txt"
    target: "test"

If you have any other AWS resource which interacts with EC2 (or any other AWS service) and you want to use AWS CLI, you can use AWS Credentials Action

https://github.com/aws-actions/configure-aws-credentials

- name: Configure AWS credentials from Test account
  uses: aws-actions/configure-aws-credentials@v1
  with:
     aws-access-key-id: ${{ secrets.TEST_AWS_ACCESS_KEY_ID }}
     aws-secret-access-key: ${{ secrets.TEST_AWS_SECRET_ACCESS_KEY }}
     aws-region: us-east-1

 - name: Copy files to the test website with the AWS CLI
   run: |
     aws s3 sync . s3://my-s3-test-website-bucket
like image 85
saurabh14292 Avatar answered Oct 19 '25 07:10

saurabh14292


Here there is a nice article. The goal of article is to build a CI/CD stack with Github Actions + AWS EC2, CodeDeploy and S3.

like image 34
nntona Avatar answered Oct 19 '25 09:10

nntona