Update cd_web-socket.yml #80
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: Deploy to VM | |
| run: | | |
| echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/ssh_key | |
| chmod 600 ~/ssh_key | |
| ssh -o StrictHostKeyChecking=no -i ~/ssh_key ubuntu@13.234.30.94 << EOF | |
| echo "Pulling latest websocket image..." | |
| docker pull adarsh9770/ws-backend:${{ github.sha }} | |
| echo "Stopping old websocket container..." | |
| docker rm -f ws-backend 2>/dev/null || true | |
| echo "Starting new websocket container..." | |
| docker run -d --name ws-backend -p 8080:8080 \ | |
| -e DATABASE_URL=${{ secrets.DATABASE_URL }} \ | |
| -e NEXT_PUBLIC_BACKEND_URL=${{ secrets.NEXT_PUBLIC_BACKEND_URL }} \ | |
| adarsh9770/ws-backend:${{ github.sha }} | |
| echo "Cleaning unused images..." | |
| docker image prune -f | |
| docker ps | |
| EOF |