Modify deployment script for chatbot directory and service #7
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 Python Chatbot | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| paths: | |
| - 'Python RAG chatbot/**' | |
| - '.github/workflows/deploy_chatbot.yml' | |
| jobs: | |
| deploy-chatbot: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Copy chatbot files to EC2 | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.CHATBOT_EC2_HOST }} | |
| username: ec2-user | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| source: "Python RAG chatbot/*" | |
| target: "/home/ec2-user/" | |
| strip_components: 0 | |
| - name: Deploy and restart chatbot service | |
| uses: appleboy/ssh-action@v0.1.10 | |
| with: | |
| host: ${{ secrets.CHATBOT_EC2_HOST }} | |
| username: ec2-user | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: | | |
| cd "/home/ec2-user/chatbot" | |
| source .venv/bin/activate | |
| # Install/update dependencies | |
| python3 -m pip install --upgrade pip | |
| python3 -m pip install -r requirements.txt | |
| # Create/update .env file with secrets | |
| cat > .env <<EOF | |
| PINECONE_API_KEY=${{ secrets.CHATBOT_PINECONE_API_KEY }} | |
| PINECONE_CLOUD=${{ secrets.PINECONE_CLOUD }} | |
| PINECONE_REGION=${{ secrets.PINECONE_REGION }} | |
| PINECONE_INDEX=${{ secrets.CHATBOT_PINECONE_INDEX }} | |
| PINECONE_NAMESPACE=${{ secrets.PINECONE_NAMESPACE }} | |
| EMBED_MODEL=${{ secrets.EMBED_MODEL }} | |
| CHAT_MODEL=${{ secrets.CHAT_MODEL }} | |
| OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} | |
| EOF | |
| # Reload and restart service | |
| sudo systemctl daemon-reload | |
| sudo systemctl enable chatbot | |
| sudo systemctl restart chatbot | |
| # Check service status | |
| sudo systemctl status chatbot --no-pager |