Skip to content

Merge pull request #7 from rekognize/analytics-updates #24

Merge pull request #7 from rekognize/analytics-updates

Merge pull request #7 from rekognize/analytics-updates #24

Workflow file for this run

name: Deploy to Server
on:
push:
branches:
- dev
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set deployment parameters
id: vars
run: |
if [ "${{ github.ref_name }}" == "dev" ]; then
echo "DEPLOY_DIR=OpenAssistants-dev" >> $GITHUB_ENV
echo "ASGI_SERVER=dev_uvicorn" >> $GITHUB_ENV
elif [ "${{ github.ref_name }}" == "main" ]; then
echo "DEPLOY_DIR=OpenAssistants-main" >> $GITHUB_ENV
echo "ASGI_SERVER=main_uvicorn" >> $GITHUB_ENV
fi
- name: Add SSH Key
run: |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > private_key.pem
chmod 600 private_key.pem
- name: Deploy to Server
env:
DEPLOY_DIR: ${{ env.DEPLOY_DIR }}
ASGI_SERVER: ${{ env.ASGI_SERVER }}
run: |
ssh -i private_key.pem -o StrictHostKeyChecking=no [email protected] <<EOF
# Navigate to the deployment directory
cd /home/ubuntu/$DEPLOY_DIR
# Fetch and reset code
git fetch origin
git reset --hard origin/${{ github.ref_name }}
# Activate virtual environment
if [ -f "venv/bin/activate" ]; then
source venv/bin/activate
else
python3 -m venv venv
source venv/bin/activate
fi
# Install requirements
pip install -r requirements.txt
# Django commands
python manage.py migrate --noinput || { echo "Migrations failed"; exit 1; }
python manage.py collectstatic --noinput || { echo "Collectstatic failed"; exit 1; }
# Restart the server
sudo supervisorctl restart $ASGI_SERVER
EOF