Skip to content

Commit

Permalink
Update django_CICD.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
2ming00 authored Sep 4, 2024
1 parent 6ac2e4c commit b3de086
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions .github/workflows/django_CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,68 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: '3.10'

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
working-directory: aiServer

- name: Run tests
run: |
python manage.py test
working-directory: aiServer

deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Create secrets.json
uses: jsdaniell/[email protected]
with:
name: "secrets.json"
json: ${{ secrets.SECRETS }}

- name: Deploy to EC2
env:
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ubuntu
EC2_KEY: ${{ secrets.EC2_KEY }}
run: |
echo "$EC2_KEY" > key.pem
echo "${{ secrets.EC2_KEY }}" > key.pem
chmod 400 key.pem
scp -o StrictHostKeyChecking=no -i key.pem -r ./aiServer $EC2_USER@$EC2_HOST:/home/ubuntu/
scp -o StrictHostKeyChecking=no -i key.pem ./secrets.json $EC2_USER@$EC2_HOST:/home/ubuntu/aiServer/
ssh -o StrictHostKeyChecking=no -i key.pem $EC2_USER@$EC2_HOST << EOF
cd /home/ubuntu/aiServer
if [ ! -d "venv" ]; then
python3 -m venv venv
fi
mkdir -p logs
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
python manage.py collectstatic --noinput
python manage.py migrate
if pgrep gunicorn; then
pkill gunicorn
fi
python manage.py collectstatic --noinput
pkill gunicorn || true
nohup gunicorn --bind 0.0.0.0:8000 aiServer.wsgi:application \
--workers 3 \
--timeout 120 \
--access-logfile /home/ubuntu/aiServer/logs/gunicorn-access.log \
--error-logfile /home/ubuntu/aiServer/logs/gunicorn-error.log &
sudo systemctl restart nginx
--access-logfile logs/gunicorn-access.log \
--error-logfile logs/gunicorn-error.log &
sudo service nginx restart
EOF
rm key.pem

0 comments on commit b3de086

Please sign in to comment.