Update deploy.yml #10
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.5 . | |
- name: Push Docker image to Docker Hub | |
run: docker push anfal17/react-app:latest.5 | |
- name: Deploy to AWS EC2 | |
uses: appleboy/scp-action@master | |
with: | |
host: 34.230.15.13 | |
username: ubuntu | |
key: ${{ secrets.EC2_SSH_KEY }} | |
script: | | |
docker stop react-app || true | |
docker rm react-app || true | |
docker pull anfal17/react-app:latest.5 | |
docker run -d --name react-app -p 3000:5173 anfal17/react-app:latest.5 |