Skip to content

자동배포

박재윤 edited this page Nov 26, 2020 · 1 revision

자동 배포

스크립트

#!/bin/bash

# 현재 경로 가져오기
DIRECTORY=$(dirname $(realpath $0))

# 경로 변경
cd ${DIRECTORY}

git fetch

# 현재 체크섬과 origin 체크섬 비교
CUR_CHECKSUM=$(git rev-parse HEAD)
ORIGIN_CHECKSUM=$(git rev-parse origin/release)

if [ $CUR_CHECKSUM == $ORIGIN_CHECKSUM ];then
        exit;
fi

# 다르면 pull
git pull

npm install

date >> ${DIRECTORY}/deploy.log
echo "pull" >> ${DIRECTORY}/deploy.log
exit

크론탭으로 매분 실행

cronetab -e

크론탭 수정

*      *      *      *      *
분(0-59)  시간(0-23)  일(1-31)  월(1-12)   요일(0-7)


# 매분 test.sh 실행
* * * * * /home/script/test.sh

# 매주 금요일 오전 5시 45분에 test.sh 를 실행
45 5 * * 5 /home/script/test.sh

pm2 watch를 이용해서 바뀐 것 재실행

pm2 start app.js —name "project name" —watch --node-args="--production --port=3000"
Clone this wiki locally