Update cd_frontend.yml #78
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 Frontend | |
| 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/excalidraw-frontend/Dockerfile | |
| build-args: | | |
| DATABASE_URL=${{ secrets.DATABASE_URL }} | |
| NEXT_PUBLIC_BACKEND_URL=${{ secrets.NEXT_PUBLIC_BACKEND_URL }} | |
| NEXT_PUBLIC_WS_URL=${{ secrets.NEXT_PUBLIC_WS_URL }} | |
| push: true | |
| tags: ${{ secrets.DOCKERHUB_USERNAME }}/frontend:${{ 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 image..." | |
| docker pull adarsh9770/frontend:${{ github.sha }} | |
| echo "Stopping old container..." | |
| docker rm -f frontend 2>/dev/null || true | |
| echo "Starting new container..." | |
| docker run -d --name frontend -p 3000:3000 \ | |
| -e DATABASE_URL=${{ secrets.DATABASE_URL }} \ | |
| -e NEXT_PUBLIC_BACKEND_URL=${{ secrets.NEXT_PUBLIC_BACKEND_URL }} \ | |
| -e NEXT_PUBLIC_WS_URL=${{ secrets.NEXT_PUBLIC_WS_URL }} \ | |
| -e EMAIL_USER=${{ secrets.EMAIL_USER }} \ | |
| -e EMAIL_PASSWORD=${{ secrets.EMAIL_PASSWORD }} \ | |
| -e NEXT_PUBLIC_FRONTEND_URL=${{ secrets.NEXT_PUBLIC_FRONTEND_URL }} \ | |
| adarsh9770/frontend:${{ github.sha }} | |
| echo "Cleaning dangling images..." | |
| docker image prune -f | |
| docker ps | |
| EOF |