File tree Expand file tree Collapse file tree 1 file changed +16
-18
lines changed Expand file tree Collapse file tree 1 file changed +16
-18
lines changed Original file line number Diff line number Diff line change 1
- name : Deploy Yii2 App to EC2
1
+ name : Deploy to EC2
2
2
3
3
on :
4
4
push :
5
- branches :
6
- - main
5
+ branches : [master]
7
6
8
7
jobs :
9
8
deploy :
10
9
runs-on : ubuntu-latest
11
10
12
11
steps :
13
- - name : Checkout repo
12
+ - name : Checkout code
14
13
uses : actions/checkout@v3
15
14
16
- - name : Setup SSH key
15
+ - name : Set up SSH
17
16
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
20
21
21
- - name : Deploy to EC2
22
+ - name : Copy files to EC2
22
23
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/
26
25
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
34
32
EOF
35
33
You can’t perform that action at this time.
0 commit comments