Skip to content

Commit be78df4

Browse files
committed
m
1 parent 4fdb384 commit be78df4

1 file changed

Lines changed: 59 additions & 22 deletions

File tree

.github/workflows/deploy-ec2v2.yml

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,65 @@ jobs:
3636
ls -lah
3737
3838

39-
- name: Copy files to server using SCP alternative (rsync)
40-
run: |
41-
mkdir -p ~/.ssh
42-
echo "${{ secrets.EC2_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
43-
chmod 600 ~/.ssh/id_rsa
44-
rsync -avz -e "ssh -o StrictHostKeyChecking=no" ./templates/flask-react/docker-compose.yml ubuntu@${{ secrets.EC2_HOST }}:/home/ubuntu/templates/docker-compose.yml
45-
rsync -avz -e "ssh -o StrictHostKeyChecking=no" ./templates/flask-react/nginx/Dockerfile ubuntu@${{ secrets.EC2_HOST }}:/home/ubuntu/templates/nginx/Dockerfile
46-
rsync -avz -e "ssh -o StrictHostKeyChecking=no" ./templates/flask-react/nginx/default.conf ubuntu@${{ secrets.EC2_HOST }}:/home/ubuntu/templates/nginx/default.conf
47-
rsync -avz -e "ssh -o StrictHostKeyChecking=no" ./templates/flask-react/flask/Dockerfile ubuntu@${{ secrets.EC2_HOST }}:/home/ubuntu/templates/flask/Dockerfile
48-
49-
- name: Deploy to AWS EC2 using SSH
50-
run: |
51-
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ubuntu@${{ secrets.EC2_HOST }} << 'EOF'
52-
cd /home/ubuntu/templates
53-
54-
echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
55-
56-
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/flask-backend:latest
57-
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/nginx-backend:1.0
58-
59-
docker-compose up -d
60-
EOF
39+
# - name: copy files to server using SCP 1
40+
# uses: appleboy/scp-action@master
41+
# with:
42+
# host: ${{ secrets.EC2_HOST }}
43+
# username: ubuntu
44+
# key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
45+
# port: 22
46+
# source: "./templates/flask-react/docker-compose.yml"
47+
# target: "/home/ubuntu/templates/docker-compose.yml"
48+
49+
- name: copy files to server using SCP 2
50+
uses: appleboy/scp-action@master
51+
with:
52+
host: ${{ secrets.EC2_HOST }}
53+
username: ubuntu
54+
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
55+
port: 22
56+
source: "./templates/flask-react/nginx/Dockerfile"
57+
target: "/home/ubuntu/templates/nginx/Dockerfile"
58+
59+
- name: copy files to server using SCP 3
60+
uses: appleboy/scp-action@master
61+
with:
62+
host: ${{ secrets.EC2_HOST }}
63+
username: ubuntu
64+
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
65+
port: 22
66+
source: "./templates/flask-react/nginx/default.conf"
67+
target: "/home/ubuntu/templates/nginx/default.conf"
68+
69+
- name: copy files to server using SCP 4
70+
uses: appleboy/scp-action@master
71+
with:
72+
host: ${{ secrets.EC2_HOST }}
73+
username: ubuntu
74+
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
75+
port: 22
76+
source: "./templates/flask-react/flask/Dockerfile"
77+
target: "/home/ubuntu/templates/flask/Dockerfile"
78+
79+
80+
81+
- name: Deploy to AWS EC2
82+
uses: appleboy/ssh-action@master
83+
with:
84+
host: ${{ secrets.EC2_HOST }}
85+
username: ubuntu
86+
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
87+
script: |
88+
cd /home/ubuntu/templates
89+
90+
echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
91+
92+
93+
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/flask-backend:latest
94+
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/nginx-backend:1.0
95+
96+
97+
docker-compose up -d
6198

6299

63100
# docker stop jeremyhuegel/flask-backend:latest

0 commit comments

Comments
 (0)