Skip to content

Commit ac9f2cc

Browse files
author
Ubuntu
committed
update
1 parent ddb0f2f commit ac9f2cc

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

.github/workflows/deploy.yml

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1-
name: Deploy Yii2 App to EC2
1+
name: Deploy to EC2
22

33
on:
44
push:
5-
branches:
6-
- main
5+
branches: [master]
76

87
jobs:
98
deploy:
109
runs-on: ubuntu-latest
1110

1211
steps:
13-
- name: Checkout repo
12+
- name: Checkout code
1413
uses: actions/checkout@v3
1514

16-
- name: Setup SSH key
15+
- name: Set up SSH
1716
run: |
18-
echo "${{ secrets.EC2_SSH_KEY }}" > ec2_key.pem
19-
chmod 600 ec2_key.pem
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
2021
21-
- name: Deploy to EC2
22+
- name: Copy files to EC2
2223
run: |
23-
ssh -o StrictHostKeyChecking=no -i ec2_key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
24-
# Setup repo if first time
25-
cd ~/yii2-app-basic || (git clone https://github.com/harshit075/yii2-app-basic.git && cd yii2-app-basic)
24+
rsync -avz --exclude '.git' --exclude 'vendor' -e "ssh -i ~/.ssh/id_rsa" ./ ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/${{ secrets.EC2_USER }}/app/
2625
27-
git pull origin main
28-
29-
docker stop yii2 || true
30-
docker rm yii2 || true
31-
32-
docker build -t yii2-app .
33-
docker run -d -p 8080:80 --name yii2 yii2-app
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
3432
EOF
3533

0 commit comments

Comments
 (0)