Update cd_frontend.yml #73
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 Websocket | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v3 | |
| with: | |
| context: . | |
| file: ./apps/ws-backend/Dockerfile | |
| push: true | |
| tags: ${{ secrets.DOCKERHUB_USERNAME }}/ws-backend:${{ github.sha }} | |
| - name: Clean up Docker resources on VM | |
| run: | | |
| echo "${{ secrets.SSH_PRIVATE_KEY }}" &> ~/ssh_key | |
| mkdir -p /home/runner/.ssh | |
| chmod 700 ~/ssh_key | |
| ssh -o StrictHostKeyChecking=no -i ~/ssh_key ubuntu@64.227.154.35 -t " | |
| # Clean up unused containers, images, and volumes | |
| docker system prune -af --volumes | |
| docker images | |
| docker ps -a | |
| " | |
| - name: Deploy to the VM | |
| run: | | |
| echo "${{ secrets.SSH_PRIVATE_KEY }}" &> ~/ssh_key | |
| mkdir -p /home/runner/.ssh | |
| ls /home/runner/.ssh | |
| chmod 700 /home/runner/ssh_key | |
| ssh -o StrictHostKeyChecking=no -i ~/ssh_key ubuntu@64.227.154.35 -t "docker stop ws-backend || true: | |
| docker rm ws-backend || true: | |
| docker run --name ws-backend -d -p 8080:8080 -e DATABASE_URL=${{ secrets.DATABASE_URL }} -e NEXT_PUBLIC_BACKEND_URL=${{ secrets.NEXT_PUBLIC_BACKEND_URL }} adarsh9770/ws-backend:${{ github.sha }}" |