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 7aadb23 commit cbaf5f0
Showing 1 changed file with 85 additions and 91 deletions.
176 changes: 85 additions & 91 deletions .github/workflows/django_CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,104 +6,98 @@ jobs:
build:
runs-on: ubuntu-latest
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 django djangorestframework drf-yasg
working-directory: aiServer
- 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 django djangorestframework drf-yasg
working-directory: aiServer

upload:
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 }}
dir: 'aiServer'

- name: Upload Code to EC2
env:
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ubuntu
EC2_KEY: ${{ secrets.EC2_KEY }}
run: |
echo "${{ secrets.EC2_KEY }}" > key.pem
chmod 400 key.pem
ssh -o StrictHostKeyChecking=no -i key.pem $EC2_USER@$EC2_HOST << EOF
mkdir -p /home/ubuntu/aiServer/logs
mkdir -p /home/ubuntu/aiServer/staticfiles
EOF
scp -o StrictHostKeyChecking=no -i key.pem -r ./aiServer $EC2_USER@$EC2_HOST:/home/ubuntu/
rm key.pem
- name: Checkout code
uses: actions/checkout@v4
- name: Create secrets.json
uses: jsdaniell/[email protected]
with:
name: "secrets.json"
json: ${{ secrets.SECRETS }}
dir: 'aiServer'
- name: Upload Code to EC2
env:
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ubuntu
EC2_KEY: ${{ secrets.EC2_KEY }}
run: |
echo "${{ secrets.EC2_KEY }}" > key.pem
chmod 400 key.pem
ssh -o StrictHostKeyChecking=no -i key.pem $EC2_USER@$EC2_HOST << EOF
mkdir -p /home/ubuntu/aiServer/logs
mkdir -p /home/ubuntu/aiServer/staticfiles
EOF
scp -o StrictHostKeyChecking=no -i key.pem -r ./aiServer $EC2_USER@$EC2_HOST:/home/ubuntu/
rm key.pem
deploy:
runs-on: ubuntu-latest
needs: upload
steps:
- name: Deploy and Verify
env:
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ubuntu
EC2_KEY: ${{ secrets.EC2_KEY }}
run: |
echo "${{ secrets.EC2_KEY }}" > key.pem
chmod 400 key.pem
ssh -o StrictHostKeyChecking=no -i key.pem $EC2_USER@$EC2_HOST << EOF
cd /home/ubuntu/aiServer
# STATIC_ROOT 설정 추가
echo "STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')" >> aiServer/settings.py
pkill -9 gunicorn || true
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
python manage.py migrate
python manage.py collectstatic --noinput
nohup gunicorn --bind 0.0.0.0:8000 aiServer.wsgi:application \
--workers 3 \
--timeout 120 \
--access-logfile logs/gunicorn-access.log \
--error-logfile logs/gunicorn-error.log &
sleep 10
sudo service nginx restart
echo "Checking Gunicorn processes:"
ps aux | grep gunicorn
echo "Checking Gunicorn logs:"
tail -n 20 logs/gunicorn-access.log
tail -n 20 logs/gunicorn-error.log
echo "Testing service response:"
curl -I http://localhost:8000
echo "Checking Nginx status:"
sudo systemctl status nginx
EOF
rm key.pem
- name: Deploy and Verify
env:
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ubuntu
EC2_KEY: ${{ secrets.EC2_KEY }}
run: |
echo "${{ secrets.EC2_KEY }}" > key.pem
chmod 400 key.pem
ssh -o StrictHostKeyChecking=no -i key.pem $EC2_USER@$EC2_HOST << EOF
cd /home/ubuntu/aiServer
echo "STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')" >> aiServer/settings.py
pkill -9 gunicorn || true
sudo apt update
sudo apt install -y python3.10
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
sudo update-alternatives --config python3 <<< "0"
sudo apt-get install -y python3-apt
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
python manage.py migrate
python manage.py collectstatic --noinput
nohup gunicorn --bind 0.0.0.0:8000 aiServer.wsgi:application \
--workers 3 \
--timeout 120 \
--access-logfile logs/gunicorn-access.log \
--error-logfile logs/gunicorn-error.log &
sleep 10
sudo service nginx restart
echo "Checking Gunicorn processes:"
ps aux | grep gunicorn
echo "Checking Gunicorn logs:"
tail -n 20 logs/gunicorn-access.log
tail -n 20 logs/gunicorn-error.log
echo "Testing service response:"
curl -I http://localhost:8000
echo "Checking Nginx status:"
sudo systemctl status nginx
EOF
rm key.pem

0 comments on commit cbaf5f0

Please sign in to comment.