Update deploy.yml - ec2 ssh-keygen #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |