-
Notifications
You must be signed in to change notification settings - Fork 0
34 lines (28 loc) · 971 Bytes
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
name: Deploy to EC2
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout repository
- name: Checkout repository
uses: actions/checkout@v3
# Step 2: Set up SSH private key
- name: Set up SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
# Step 3: Add EC2 host to known_hosts
- name: Add EC2 host to known_hosts
run: |
mkdir -p ~/.ssh
chmod 700 ~/.ssh # Ensure proper permissions for the SSH folder
ssh-keyscan -H ${{ secrets.EC2_PUBLIC_IP }} >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts # Ensure proper permissions for known_hosts file
# Step 4: Deploy to EC2 using rsync
- name: Deploy to EC2 using rsync
run: |
rsync -avz -e "ssh" ./ ec2-user@${{ secrets.EC2_PUBLIC_IP }}:/home/ec2-user/let_me_know