Merge pull request #246 from boostcampwm-2024/feature-fe-#240 #3
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
name: Create Directory on Remote Server | |
on: | |
push: | |
branches: | |
- develop | |
jobs: | |
env: | |
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 }} | |
BRANCH_NAME: "develop" | |
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 switch -c develop | |
git pull origin develop | |
else | |
echo "$DIR 디렉토리가 존재하지 않습니다. 클론 중..." | |
git clone https://github.com/boostcampwm-2024/web15-OctoDocs.git "$DIR" | |
cd "$DIR" | |
git switch -c develop | |
git pull origin develop | |
fi | |
# Install dependencies | |
echo "의존성 설치" | |
yarn -v | |
yarn install | |
# build | |
yarn build | |
# Check and kill existing process | |
EXISTING_PID=$(lsof -ti :3000) | |
if [ -n "$EXISTING_PID" ]; then | |
echo "3000 프로세스 종료 중...: $EXISTING_PID" | |
kill -9 "$EXISTING_PID" | |
echo "$EXISTING_PID 프로세스 종료" | |
else | |
echo "실행 중인 프로세스가 없습니다." | |
fi | |
EXISTING_PID=$(lsof -ti :1234) | |
if [ -n "$EXISTING_PID" ]; then | |
echo "1234 프로세스 종료 중...: $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/apps/backend | |
- 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/apps/frontend | |
# 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 "nohup node /home/root/app/octodocs/apps/backend/dist/main.js > nohup.out 2> nohup.err < /dev/null &" |