-
Notifications
You must be signed in to change notification settings - Fork 0
43 lines (33 loc) · 1.11 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
name: Deploy React App
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to Docker Hub
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
- name: Build Docker image
run: docker build -t anfal17/react-app:latest.3 .
- name: Push Docker image to Docker Hub
run: docker push anfal17/react-app:latest.3
- name: SSH into EC2 and Deploy
uses: appleboy/[email protected]
with:
host: 34.230.15.13
username: ec2-user
key: ${{ secrets.EC2_SSH_KEY }}
script: |
# Stop and remove the existing container if it exists
docker stop react-app || true
docker rm react-app || true
# Pull the latest image from Docker Hub
docker pull anfal17/react-app:latest.3
# Run the Docker container
docker run -d --name react-app -p 3000:5173 anfal17/react-app:latest.3