Skip to content

Commit 561c6b1

Browse files
author
Ubuntu
committed
new
1 parent ac9f2cc commit 561c6b1

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

.github/workflows/deploy.yml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@ name: Deploy to EC2
22

33
on:
44
push:
5-
branches: [master]
5+
branches: [main] # or 'main' if your branch is main
66

77
jobs:
88
deploy:
99
runs-on: ubuntu-latest
1010

1111
steps:
12-
- name: Checkout code
13-
uses: actions/checkout@v3
12+
- name: Checkout code
13+
uses: actions/checkout@v3
1414

15-
- name: Set up SSH
16-
run: |
17-
mkdir -p ~/.ssh
18-
echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_rsa
19-
chmod 600 ~/.ssh/id_rsa
20-
ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
15+
- name: Set up SSH access to EC2
16+
run: |
17+
mkdir -p ~/.ssh
18+
echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_rsa
19+
chmod 600 ~/.ssh/id_rsa
20+
ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
2121
22-
- name: Copy files to EC2
23-
run: |
24-
rsync -avz --exclude '.git' --exclude 'vendor' -e "ssh -i ~/.ssh/id_rsa" ./ ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/${{ secrets.EC2_USER }}/app/
22+
- name: Copy project to EC2 instance
23+
run: |
24+
rsync -avz --exclude '.git' --exclude 'vendor' -e "ssh -i ~/.ssh/id_rsa" ./ ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/${{ secrets.EC2_USER }}/app/
2525
26-
- name: Build and restart Docker container on EC2
27-
run: |
28-
ssh -i ~/.ssh/id_rsa ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
29-
cd /home/${{ secrets.EC2_USER }}/app
30-
docker compose down
31-
docker compose up --build -d
32-
EOF
26+
- name: SSH into EC2 and deploy Docker container
27+
run: |
28+
ssh -i ~/.ssh/id_rsa ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
29+
cd /home/${{ secrets.EC2_USER }}/app
30+
docker compose down
31+
docker compose up --build -d
32+
EOF
3333

0 commit comments

Comments
 (0)