-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
1 changed file
with
38 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,39 +23,67 @@ jobs: | |
pip install django djangorestframework drf-yasg | ||
working-directory: aiServer | ||
|
||
deploy: | ||
upload: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Upload and Deploy Code to EC2 | ||
- name: Create secrets.json | ||
uses: jsdaniell/[email protected] | ||
with: | ||
name: "secrets.json" | ||
json: ${{ secrets.SECRETS }} | ||
|
||
- name: Upload Code to EC2 | ||
env: | ||
EC2_HOST: ${{ secrets.EC2_HOST }} | ||
EC2_USER: ubuntu | ||
EC2_KEY: ${{ secrets.EC2_KEY }} | ||
SECRET: ${{ secrets.SECRETS }} | ||
run: | | ||
echo "${{ secrets.EC2_KEY }}" > key.pem | ||
chmod 400 key.pem | ||
# secrets.json 파일 생성 | ||
ssh -o StrictHostKeyChecking=no -i key.pem $EC2_USER@$EC2_HOST << 'EOF' | ||
echo '{"SECRET_KEY": "'"${SECRETS}"'"}' > /home/ubuntu/aiServer/secrets.json | ||
# 서버에서 디렉토리 생성 여부 확인 및 생성 | ||
ssh -o StrictHostKeyChecking=no -i key.pem $EC2_USER@$EC2_HOST << EOF | ||
if [ ! -d "/home/ubuntu/aiServer" ]; then | ||
mkdir -p /home/ubuntu/aiServer | ||
fi | ||
EOF | ||
# 코드 업로드 | ||
# 코드 및 secrets.json 업로드 | ||
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/ | ||
# 사용된 키 삭제 | ||
rm key.pem | ||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: upload | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Deploy 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' | ||
ssh -o StrictHostKeyChecking=no -i key.pem $EC2_USER@$EC2_HOST << EOF | ||
cd /home/ubuntu/aiServer || exit 1 | ||
python3 -m venv venv | ||
source venv/bin/activate | ||
python -m pip install --upgrade pip | ||
pip install setuptools corsheaders django djangorestframework drf-yasg gunicorn | ||
pip install setuptools numpy django-cors-headers django djangorestframework drf-yasg gunicorn | ||
nohup gunicorn --bind 0.0.0.0:8000 aiServer.wsgi:application & | ||
sudo service nginx restart | ||
EOF | ||
|