Deploy Comparative NER to EC2 #11
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 Comparative NER to EC2 | |
| on: | |
| push: | |
| branches: ["main"] | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| cache: "pip" | |
| - name: Install dependencies (for caching) | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Test SSH Connection | |
| run: | | |
| echo "Testing connectivity to ${{ secrets.SSH_HOST }} on port 22..." | |
| nc -zv -w 5 ${{ secrets.SSH_HOST }} 22 | |
| - name: Deploy via rsync | |
| env: | |
| SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "$SSH_PRIVATE_KEY" > ~/deploy_key | |
| chmod 600 ~/deploy_key | |
| rsync -avz --delete -vv \ | |
| -e "ssh -i ~/deploy_key -o StrictHostKeyChecking=no -o ConnectTimeout=10" \ | |
| --exclude='.env' --exclude='entify-env' --exclude='ner' --exclude='.git' --exclude='.github' --exclude='__pycache__' --exclude='*.pyc' \ | |
| ./ ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/var/www/html/entify.orbin.dev/ | |
| rm ~/deploy_key | |
| - name: Post-deployment (Setup and Start Service) | |
| uses: appleboy/ssh-action@v1.2.0 | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USER }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script: | | |
| set -e | |
| cd /var/www/html/entify.orbin.dev | |
| # Stop MySQL before deploying Flask (free up memory) | |
| echo "Stopping MySQL..." | |
| sudo systemctl stop mysql || true | |
| # Cleanup old venv if it exists | |
| if [ -d "ner" ]; then | |
| echo "Deleting legacy ner venv..." | |
| rm -rf ner | |
| fi | |
| # Create new entify-env venv if it doesn't exist | |
| if [ ! -d "entify-env" ]; then | |
| echo "Creating entify-env virtual environment..." | |
| python3 -m venv entify-env | |
| else | |
| echo "entify-env virtual environment already exists." | |
| fi | |
| # Upgrade and install dependencies using entify-env pip | |
| ./entify-env/bin/python3 -m pip install --upgrade pip | |
| ./entify-env/bin/python3 -m pip install -r requirements.txt | |
| echo "Restarting entify service..." | |
| sudo systemctl restart entify |