File tree Expand file tree Collapse file tree 1 file changed +19
-19
lines changed Expand file tree Collapse file tree 1 file changed +19
-19
lines changed Original file line number Diff line number Diff line change @@ -2,32 +2,32 @@ name: Deploy to EC2
2
2
3
3
on :
4
4
push :
5
- branches : [master]
5
+ branches : [main] # or 'main' if your branch is main
6
6
7
7
jobs :
8
8
deploy :
9
9
runs-on : ubuntu-latest
10
10
11
11
steps :
12
- - name : Checkout code
13
- uses : actions/checkout@v3
12
+ - name : Checkout code
13
+ uses : actions/checkout@v3
14
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
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
21
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/
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/
25
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 /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
33
33
You can’t perform that action at this time.
0 commit comments