CICD Pipeline #3
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: Deploy FlashLearn to AWS EC2 Instance | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build frontend Docker image | |
| run: docker build -t ${{ secrets.DOCKER_USERNAME }}/flashlearn:frontend-latest ./frontend | |
| - name: Build backend Docker image | |
| run: docker build -t ${{ secrets.DOCKER_USERNAME }}/flashlearn:backend-latest ./backend | |
| - name: Push frontend to Docker Hub | |
| run: docker push ${{ secrets.DOCKER_USERNAME }}/flashlearn:frontend-latest | |
| - name: Push backend to Docker Hub | |
| run: docker push ${{ secrets.DOCKER_USERNAME }}/flashlearn:backend-latest | |
| - name: SSH into EC2 and Deploy New Container | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{secrets.EC2_PUBLIC_IP}} | |
| username: ubuntu | |
| key: ${{secrets.EC2_SSH_PRIVATE_KEY}} | |
| script: | | |
| cd flashlearn | |
| docker-compose down || true | |
| docker-compose pull | |
| docker-compose up -d | |
| - name: Test Frontend Is Live | |
| run: | | |
| curl --fail --silent --show-error https://flashlearn.aimablem.dev || exit 1 | |
| - name: Test Backend Is Live | |
| run: | | |
| curl --fail --silent --show-error https://api.aimablem.dev || exit 1 | |