Merge pull request #2 from ajkumarray/feature/FEAT-1/design-setup-and… #1
This file contains hidden or 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: Build and Deploy Nirdeshak React App | |
| on: | |
| push: | |
| branches: | |
| - master | |
| jobs: | |
| deploy-react: | |
| runs-on: ubuntu-latest | |
| env: | |
| IMAGE_REACT: ghcr.io/${{ github.repository_owner }}/nirdeshak | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| run: echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io --u ${{ github.actor }} --password-stdin | |
| - name: Build React Docker Image | |
| run: docker build -t $IMAGE_REACT:latest . | |
| - name: Push Docker image to GHCR | |
| run: docker push $IMAGE_REACT:latest | |
| - name: SSH into EC2 and deploy React app | |
| uses: appleboy/ssh-action@v1.0.0 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: | | |
| docker pull $IMAGE_REACT:latest | |
| docker stop nirdeshak || true && docker rm nirdeshak || true | |
| docker run -d --name nirdeshak -p 3000:80 $IMAGE_REACT:latest | |
| echo "React app deployed successfully" |