-
Notifications
You must be signed in to change notification settings - Fork 0
44 lines (37 loc) · 1.4 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
name: CI/CD for FastAPI
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ~/mirisa_server/requirements.txt
- name: EC2로 SSH 접속하여 git pull
env:
SSH_PRIVATE_KEY: ${{ secrets.EC2_SSH_KEY }}
EC2_USER: 'ubuntu'
EC2_HOST: 'ec2-3-38-23-48.ap-northeast-2.compute.amazonaws.com'
run: |
echo "${SSH_PRIVATE_KEY}" > private_key
chmod 600 private_key
ssh -i private_key -o StrictHostKeyChecking=no $EC2_USER@$EC2_HOST 'cd ~/mirisa_server && git pull origin main'
- name: Restart the FastAPI application
env:
SSH_PRIVATE_KEY: ${{ secrets.EC2_SSH_KEY }}
EC2_USER: 'ubuntu'
EC2_HOST: 'ec2-3-38-23-48.ap-northeast-2.compute.amazonaws.com' # 실제 IP 주소로 수정
run: |
echo "${SSH_PRIVATE_KEY}" > private_key
chmod 600 private_key
ssh -i private_key $EC2_USER@$EC2_HOST 'sudo lsof -t -i :8000 | xargs sudo kill -9 && screen -S server -d -m bash -c "source myenv/bin/activate && cd ~/mirisa_server && python3 main.py"'