Skip to content

Update main.yml

Update main.yml #6

Workflow file for this run

name: Deploy to EC2
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup SSH Key
env:
EC2_PRIVATE_KEY: ${{ secrets.EC2_KEY }}
run: |
echo "$EC2_PRIVATE_KEY" > ~/ec2-key.pem
chmod 600 ~/ec2-key.pem
- name: Create SSH directory
run: |
mkdir -p ~/.ssh
- name: Add known host
run: |
ssh-keyscan ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
- name: Connect to EC2 and Run Commands
run: |
ssh -i ~/ec2-key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
echo "Connected to EC2"
EOF