Skip to content

Commit 7c25f9c

Browse files
author
Ubuntu
committed
update
1 parent 281a5dc commit 7c25f9c

File tree

8 files changed

+7377
-6
lines changed

8 files changed

+7377
-6
lines changed

.github/workflows/deploy.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Deploy to EC2
2+
3+
on:
4+
push:
5+
branches: [master]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v3
14+
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
21+
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/
25+
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 ~/app
30+
docker compose down
31+
docker compose up --build -d
32+
EOF

0 commit comments

Comments
 (0)