-
Notifications
You must be signed in to change notification settings - Fork 4
134 lines (120 loc) · 4.43 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Create Directory on Remote Server
on:
push:
branches:
- develop
jobs:
frontend-CD:
runs-on: ubuntu-latest
steps:
# 코드 체크아웃
- name: Checkout code
uses: actions/checkout@v3
# .env 파일 생성 후 붙여넣기
- name: Create .env file
run: |
echo "${{secrets.DEVELOPMENT_FE_ENV}}" > ./frontend/.env
# Node.js 설치
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "23"
# 패키지 설치 및 React 빌드
- name: Install dependencies and build
run: |
cd frontend
npm install
npm run build
# aws cli를 통해 ncloud object storage 업로드
- name: Configure AWS credentials
env:
NCLOUD_ACCESS_KEY_ID: ${{ secrets.NCLOUD_ACCESS_KEY_ID }}
NCLOUD_SECRET_ACCESS_KEY: ${{ secrets.NCLOUD_SECRET_ACCESS_KEY }}
run: |
aws configure set aws_access_key_id $NCLOUD_ACCESS_KEY_ID
aws configure set aws_secret_access_key $NCLOUD_SECRET_ACCESS_KEY
aws configure set region ap-northeast-2
aws --endpoint-url=https://kr.object.ncloudstorage.com s3 cp ./frontend/dist s3://octodocs/ --recursive --debug
backend-CD:
runs-on: ubuntu-latest
steps:
# 코드 체크아웃
- name: Checkout code
uses: actions/checkout@v3
# .env 파일 생성 후 붙여넣기
- name: Create .env file
run: |
echo "${{secrets.DEVELOPMENT_ENV}}" > ./.env
# sh 실행
- name: Connect to Remote Server and Run Commands
env:
REMOTE_HOST: ${{ secrets.REMOTE_DEV_IP }}
REMOTE_USER: ${{ secrets.REMOTE_USER }}
SSH_KEY: ${{ secrets.REMOTE_PRIVATE_KEY }}
run: |
mkdir ~/.ssh
echo "$SSH_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh -o StrictHostKeyChecking=no $REMOTE_USER@$REMOTE_HOST << 'EOF'
DIR="/home/root/app/octodocs"
# Check if directory exists
if [ -d "$DIR" ]; then
echo "$DIR 디렉토리가 존재합니다. 최신 버전으로 업데이트 중..."
cd "$DIR"
git pull
else
echo "$DIR 디렉토리가 존재하지 않습니다. 클론 중..."
git clone https://github.com/boostcampwm-2024/web15-OctoDocs.git "$DIR"
cd "$DIR"
fi
# Move to backend directory
cd backend
# Install dependencies
echo "의존성 설치"
yarn -v
yarn install
# Check and kill existing process
EXISTING_PID=$(lsof -ti :3000)
if [ -n "$EXISTING_PID" ]; then
echo "프로세스 종료 중...: $EXISTING_PID"
kill -9 "$EXISTING_PID"
echo "$EXISTING_PID 프로세스 종료"
else
echo "실행 중인 프로세스가 없습니다."
fi
EOF
# .env 파일 전송
- name: Copy .env to remote server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.REMOTE_DEV_IP }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.REMOTE_PRIVATE_KEY }}
source: ./.env
target: /home/root/app/octodocs
# yarn start
- name: yarn start
env:
REMOTE_HOST: ${{ secrets.REMOTE_DEV_IP }}
REMOTE_USER: ${{ secrets.REMOTE_USER }}
SSH_KEY: ${{ secrets.REMOTE_PRIVATE_KEY }}
run: |
ssh -o StrictHostKeyChecking=no $REMOTE_USER@$REMOTE_HOST "cd /home/root/app/octodocs; nohup yarn start > nohup.out 2> nohup.err < /dev/null &"
# # 배포용 쉘 스크립트 파일 전송
# - name: Copy deploy.sh to remote server
# uses: appleboy/scp-action@master
# with:
# host: ${{ secrets.REMOTE_DEV_IP }}
# username: ${{ secrets.REMOTE_USER }}
# key: ${{ secrets.REMOTE_PRIVATE_KEY }}
# source: ./deploy.sh
# target: /home/root
# # 쉘 스크립트 실행
# - name: Run command on remote server
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.REMOTE_DEV_IP }}
# username: ${{ secrets.REMOTE_USER }}
# key: ${{ secrets.REMOTE_PRIVATE_KEY }}
# script: |
# sh /home/root/deploy.sh