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